KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > types > arrays > NestedArraysTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.db4ounit.common.types.arrays;
22
23 import db4ounit.*;
24 import db4ounit.extensions.*;
25
26
27 public class NestedArraysTestCase extends AbstractDb4oTestCase {
28
29     private static final int DEPTH = 5;
30     private static final int ELEMENTS = 3;
31
32     public static class Data {
33         public Object JavaDoc _obj;
34         public Object JavaDoc[] _arr;
35
36         public Data(Object JavaDoc obj, Object JavaDoc[] arr) {
37             this._obj = obj;
38             _arr = arr;
39         }
40     }
41     
42     protected void store(){
43         Object JavaDoc[] obj = new Object JavaDoc[ELEMENTS];
44         fill(obj, DEPTH);
45         Object JavaDoc[] arr = new Object JavaDoc[ELEMENTS];
46         fill(arr, DEPTH);
47         db().set(new Data(obj,arr));
48     }
49     
50     private void fill(Object JavaDoc[] arr, int depth){
51         if(depth <= 0){
52             arr[0] = "somestring";
53             arr[1] = new Integer JavaDoc(10);
54             return;
55         }
56         
57         depth --;
58         
59         for (int i = 0; i < ELEMENTS; i++) {
60             arr[i] = new Object JavaDoc[ELEMENTS];
61             fill((Object JavaDoc[])arr[i], depth );
62         }
63     }
64     
65     public void testOne(){
66         Data data=(Data)retrieveOnlyInstance(Data.class);
67         db().activate(data, Integer.MAX_VALUE);
68         check((Object JavaDoc[])data._obj, DEPTH);
69         check(data._arr, DEPTH);
70     }
71     
72     private void check(Object JavaDoc[] arr, int depth){
73         if(depth <= 0){
74             Assert.areEqual("somestring",arr[0]);
75             Assert.areEqual(new Integer JavaDoc(10),arr[1]);
76             return;
77         }
78         
79         depth --;
80         
81         for (int i = 0; i < ELEMENTS; i++) {
82             check((Object JavaDoc[])arr[i], depth );
83         }
84         
85     }
86     
87 }
88
Popular Tags