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 STShortWUTestCase extends
029: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements
030: Serializable {
031:
032: final static String DESCENDANT = "i_short";
033:
034: public Object i_short;
035:
036: public STShortWUTestCase() {
037: }
038:
039: private STShortWUTestCase(short a_short) {
040: i_short = new Short(a_short);
041: }
042:
043: public Object[] createData() {
044: return new Object[] { new STShortWUTestCase((short) 0),
045: new STShortWUTestCase((short) 1),
046: new STShortWUTestCase((short) 99),
047: new STShortWUTestCase((short) 909) };
048: }
049:
050: public void testEquals() {
051: Query q = newQuery();
052: q.constrain(new STShortWUTestCase((short) 0));
053:
054: // Primitive default values are ignored, so we need an
055: // additional constraint:
056: q.descend(DESCENDANT).constrain(new Short((short) 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 STShortWUTestCase((short) 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 STShortWUTestCase((short) 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 testContains() {
086: Query q = newQuery();
087: q.constrain(new STShortWUTestCase((short) 9));
088: q.descend(DESCENDANT).constraints().contains();
089:
090: expect(q, new int[] { 2, 3 });
091: }
092:
093: public void testNotContains() {
094: Query q = newQuery();
095: q.constrain(new STShortWUTestCase((short) 0));
096: q.descend(DESCENDANT).constraints().contains().not();
097:
098: expect(q, new int[] { 1, 2 });
099: }
100:
101: public void testLike() {
102: Query q = newQuery();
103: q.constrain(new STShortWUTestCase((short) 90));
104: q.descend(DESCENDANT).constraints().like();
105: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
106: _array[3]);
107: q = newQuery();
108: q.constrain(new STShortWUTestCase((short) 10));
109: q.descend(DESCENDANT).constraints().like();
110: expect(q, new int[] {});
111: }
112:
113: public void testNotLike() {
114: Query q = newQuery();
115: q.constrain(new STShortWUTestCase((short) 1));
116: q.descend(DESCENDANT).constraints().like().not();
117:
118: expect(q, new int[] { 0, 2, 3 });
119: }
120:
121: public void testIdentity() {
122: Query q = newQuery();
123: q.constrain(new STShortWUTestCase((short) 1));
124: ObjectSet set = q.execute();
125: STShortWUTestCase identityConstraint = (STShortWUTestCase) set
126: .next();
127: identityConstraint.i_short = new Short((short) 9999);
128: q = newQuery();
129: q.constrain(identityConstraint).identity();
130: identityConstraint.i_short = new Short((short) 1);
131: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
132: _array[1]);
133: }
134:
135: public void testNotIdentity() {
136: Query q = newQuery();
137: q.constrain(new STShortWUTestCase((short) 1));
138: ObjectSet set = q.execute();
139: STShortWUTestCase identityConstraint = (STShortWUTestCase) set
140: .next();
141: identityConstraint.i_short = new Short((short) 9080);
142: q = newQuery();
143: q.constrain(identityConstraint).identity().not();
144: identityConstraint.i_short = new Short((short) 1);
145:
146: expect(q, new int[] { 0, 2, 3 });
147: }
148:
149: public void testConstraints() {
150: Query q = newQuery();
151: q.constrain(new STShortWUTestCase((short) 1));
152: q.constrain(new STShortWUTestCase((short) 0));
153: Constraints cs = q.constraints();
154: Constraint[] csa = cs.toArray();
155: if (csa.length != 2) {
156: db4ounit.Assert.fail("Constraints not returned");
157: }
158: }
159:
160: public void testEvaluation() {
161: Query q = newQuery();
162: q.constrain(new STShortWUTestCase());
163: q.constrain(new Evaluation() {
164: public void evaluate(Candidate candidate) {
165: STShortWUTestCase sts = (STShortWUTestCase) candidate
166: .getObject();
167: candidate
168: .include((((Short) sts.i_short).shortValue() + 2) > 100);
169: }
170: });
171:
172: expect(q, new int[] { 2, 3 });
173: }
174:
175: }
|