KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > wrapper > untyped > STCharWUTestCase


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.soda.wrapper.untyped;
22 import java.io.*;
23
24 import com.db4o.*;
25 import com.db4o.query.*;
26
27
28 public class STCharWUTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements Serializable{
29     
30     final static String JavaDoc DESCENDANT = "i_char";
31     
32     public Object JavaDoc i_char;
33     
34     public STCharWUTestCase(){
35     }
36     
37     private STCharWUTestCase(char a_char){
38         i_char = new Character JavaDoc(a_char);
39     }
40     
41     public Object JavaDoc[] createData() {
42         return new Object JavaDoc[]{
43             new STCharWUTestCase((char)0),
44             new STCharWUTestCase((char)1),
45             new STCharWUTestCase((char)99),
46             new STCharWUTestCase((char)909)
47         };
48     }
49     
50     public void testEquals(){
51         Query q = newQuery();
52         q.constrain(new STCharWUTestCase((char)0));
53         
54         // Primitive default values are ignored, so we need an
55
// additional constraint:
56
q.descend(DESCENDANT).constrain(new Character JavaDoc((char)0));
57         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]);
58     }
59     
60     public void testNotEquals(){
61         Query q = newQuery();
62         
63         q.constrain(_array[0]);
64         q.descend(DESCENDANT).constraints().not();
65         expect(q, new int[] {1, 2, 3});
66     }
67     
68     public void testGreater(){
69         Query q = newQuery();
70         q.constrain(new STCharWUTestCase((char)9));
71         q.descend(DESCENDANT).constraints().greater();
72         
73         expect(q, new int[] {2, 3});
74     }
75     
76     public void testSmaller(){
77         Query q = newQuery();
78         q.constrain(new STCharWUTestCase((char)1));
79         q.descend(DESCENDANT).constraints().smaller();
80         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]);
81     }
82     
83     public void testIdentity(){
84         Query q = newQuery();
85         q.constrain(new STCharWUTestCase((char)1));
86         ObjectSet set = q.execute();
87         STCharWUTestCase identityConstraint = (STCharWUTestCase)set.next();
88         identityConstraint.i_char = new Character JavaDoc((char)9999);
89         q = newQuery();
90         q.constrain(identityConstraint).identity();
91         identityConstraint.i_char = new Character JavaDoc((char)1);
92         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,_array[1]);
93     }
94     
95     public void testNotIdentity(){
96         Query q = newQuery();
97         q.constrain(new STCharWUTestCase((char)1));
98         ObjectSet set = q.execute();
99         STCharWUTestCase identityConstraint = (STCharWUTestCase)set.next();
100         identityConstraint.i_char = new Character JavaDoc((char)9080);
101         q = newQuery();
102         q.constrain(identityConstraint).identity().not();
103         identityConstraint.i_char = new Character JavaDoc((char)1);
104         
105         expect(q, new int[] {0, 2, 3});
106     }
107     
108     public void testConstraints(){
109         Query q = newQuery();
110         q.constrain(new STCharWUTestCase((char)1));
111         q.constrain(new STCharWUTestCase((char)0));
112         Constraints cs = q.constraints();
113         Constraint[] csa = cs.toArray();
114         if(csa.length != 2){
115             db4ounit.Assert.fail("Constraints not returned");
116         }
117     }
118     
119     public void testEvaluation(){
120         Query q = newQuery();
121         q.constrain(new STCharWUTestCase());
122         q.constrain(new Evaluation() {
123             public void evaluate(Candidate candidate) {
124                 STCharWUTestCase sts = (STCharWUTestCase)candidate.getObject();
125                 candidate.include((((Character JavaDoc)sts.i_char).charValue() + 2) > 100);
126             }
127         });
128         
129         expect(q, new int[] {2, 3});
130     }
131     
132 }
133
134
Popular Tags