001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.common.soda.wrapper.untyped;
022:
023: import java.io.*;
024:
025: import com.db4o.*;
026: import com.db4o.query.*;
027:
028: public class STCharWUTestCase extends
029: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements
030: Serializable {
031:
032: final static String DESCENDANT = "i_char";
033:
034: public Object i_char;
035:
036: public STCharWUTestCase() {
037: }
038:
039: private STCharWUTestCase(char a_char) {
040: i_char = new Character(a_char);
041: }
042:
043: public Object[] createData() {
044: return new Object[] { new STCharWUTestCase((char) 0),
045: new STCharWUTestCase((char) 1),
046: new STCharWUTestCase((char) 99),
047: new STCharWUTestCase((char) 909) };
048: }
049:
050: public void testEquals() {
051: Query q = newQuery();
052: q.constrain(new STCharWUTestCase((char) 0));
053:
054: // Primitive default values are ignored, so we need an
055: // additional constraint:
056: q.descend(DESCENDANT).constrain(new Character((char) 0));
057: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
058: _array[0]);
059: }
060:
061: public void testNotEquals() {
062: Query q = newQuery();
063:
064: q.constrain(_array[0]);
065: q.descend(DESCENDANT).constraints().not();
066: expect(q, new int[] { 1, 2, 3 });
067: }
068:
069: public void testGreater() {
070: Query q = newQuery();
071: q.constrain(new STCharWUTestCase((char) 9));
072: q.descend(DESCENDANT).constraints().greater();
073:
074: expect(q, new int[] { 2, 3 });
075: }
076:
077: public void testSmaller() {
078: Query q = newQuery();
079: q.constrain(new STCharWUTestCase((char) 1));
080: q.descend(DESCENDANT).constraints().smaller();
081: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
082: _array[0]);
083: }
084:
085: public void testIdentity() {
086: Query q = newQuery();
087: q.constrain(new STCharWUTestCase((char) 1));
088: ObjectSet set = q.execute();
089: STCharWUTestCase identityConstraint = (STCharWUTestCase) set
090: .next();
091: identityConstraint.i_char = new Character((char) 9999);
092: q = newQuery();
093: q.constrain(identityConstraint).identity();
094: identityConstraint.i_char = new Character((char) 1);
095: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
096: _array[1]);
097: }
098:
099: public void testNotIdentity() {
100: Query q = newQuery();
101: q.constrain(new STCharWUTestCase((char) 1));
102: ObjectSet set = q.execute();
103: STCharWUTestCase identityConstraint = (STCharWUTestCase) set
104: .next();
105: identityConstraint.i_char = new Character((char) 9080);
106: q = newQuery();
107: q.constrain(identityConstraint).identity().not();
108: identityConstraint.i_char = new Character((char) 1);
109:
110: expect(q, new int[] { 0, 2, 3 });
111: }
112:
113: public void testConstraints() {
114: Query q = newQuery();
115: q.constrain(new STCharWUTestCase((char) 1));
116: q.constrain(new STCharWUTestCase((char) 0));
117: Constraints cs = q.constraints();
118: Constraint[] csa = cs.toArray();
119: if (csa.length != 2) {
120: db4ounit.Assert.fail("Constraints not returned");
121: }
122: }
123:
124: public void testEvaluation() {
125: Query q = newQuery();
126: q.constrain(new STCharWUTestCase());
127: q.constrain(new Evaluation() {
128: public void evaluate(Candidate candidate) {
129: STCharWUTestCase sts = (STCharWUTestCase) candidate
130: .getObject();
131: candidate
132: .include((((Character) sts.i_char).charValue() + 2) > 100);
133: }
134: });
135:
136: expect(q, new int[] { 2, 3 });
137: }
138:
139: }
|