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 STByteWUTestCase extends
029: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements
030: Serializable {
031:
032: final static String DESCENDANT = "i_byte";
033:
034: public Object i_byte;
035:
036: public STByteWUTestCase() {
037: }
038:
039: private STByteWUTestCase(byte a_byte) {
040: i_byte = new Byte(a_byte);
041: }
042:
043: public Object[] createData() {
044: return new Object[] { new STByteWUTestCase((byte) 0),
045: new STByteWUTestCase((byte) 1),
046: new STByteWUTestCase((byte) 99),
047: new STByteWUTestCase((byte) 113), };
048: }
049:
050: public void testEquals() {
051: Query q = newQuery();
052: q.constrain(new STByteWUTestCase((byte) 0));
053: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
054: _array[0]);
055: }
056:
057: public void testNotEquals() {
058: Query q = newQuery();
059:
060: q.constrain(_array[0]);
061: q.descend(DESCENDANT).constraints().not();
062: expect(q, new int[] { 1, 2, 3 });
063: }
064:
065: public void testGreater() {
066: Query q = newQuery();
067: q.constrain(new STByteWUTestCase((byte) 9));
068: q.descend(DESCENDANT).constraints().greater();
069:
070: expect(q, new int[] { 2, 3 });
071: }
072:
073: public void testSmaller() {
074: Query q = newQuery();
075: q.constrain(new STByteWUTestCase((byte) 1));
076: q.descend(DESCENDANT).constraints().smaller();
077: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
078: _array[0]);
079: }
080:
081: public void testContains() {
082: Query q = newQuery();
083: q.constrain(new STByteWUTestCase((byte) 9));
084: q.descend(DESCENDANT).constraints().contains();
085:
086: expect(q, new int[] { 2 });
087: }
088:
089: public void testNotContains() {
090: Query q = newQuery();
091: q.constrain(new STByteWUTestCase((byte) 0));
092: q.descend(DESCENDANT).constraints().contains().not();
093:
094: expect(q, new int[] { 1, 2, 3 });
095: }
096:
097: public void testLike() {
098: Query q = newQuery();
099: q.constrain(new STByteWUTestCase((byte) 11));
100: q.descend(DESCENDANT).constraints().like();
101: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
102: new STByteWUTestCase((byte) 113));
103: q = newQuery();
104: q.constrain(new STByteWUTestCase((byte) 10));
105: q.descend(DESCENDANT).constraints().like();
106: expect(q, new int[] {});
107: }
108:
109: public void testNotLike() {
110: Query q = newQuery();
111: q.constrain(new STByteWUTestCase((byte) 1));
112: q.descend(DESCENDANT).constraints().like().not();
113:
114: expect(q, new int[] { 0, 2 });
115: }
116:
117: public void testIdentity() {
118: Query q = newQuery();
119: q.constrain(new STByteWUTestCase((byte) 1));
120: ObjectSet set = q.execute();
121: STByteWUTestCase identityConstraint = (STByteWUTestCase) set
122: .next();
123: identityConstraint.i_byte = new Byte((byte) 102);
124: q = newQuery();
125: q.constrain(identityConstraint).identity();
126: identityConstraint.i_byte = new Byte((byte) 1);
127: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
128: _array[1]);
129: }
130:
131: public void testNotIdentity() {
132: Query q = newQuery();
133: q.constrain(new STByteWUTestCase((byte) 1));
134: ObjectSet set = q.execute();
135: STByteWUTestCase identityConstraint = (STByteWUTestCase) set
136: .next();
137: identityConstraint.i_byte = new Byte((byte) 102);
138: q = newQuery();
139: q.constrain(identityConstraint).identity().not();
140: identityConstraint.i_byte = new Byte((byte) 1);
141:
142: expect(q, new int[] { 0, 2, 3 });
143: }
144:
145: public void testConstraints() {
146: Query q = newQuery();
147: q.constrain(new STByteWUTestCase((byte) 1));
148: q.constrain(new STByteWUTestCase((byte) 0));
149: Constraints cs = q.constraints();
150: Constraint[] csa = cs.toArray();
151: if (csa.length != 2) {
152: db4ounit.Assert.fail("Constraints not returned");
153: }
154: }
155:
156: public void testNull() {
157:
158: }
159:
160: public void testEvaluation() {
161: Query q = newQuery();
162: q.constrain(new STByteWUTestCase());
163: q.constrain(new Evaluation() {
164: public void evaluate(Candidate candidate) {
165: STByteWUTestCase sts = (STByteWUTestCase) candidate
166: .getObject();
167: candidate
168: .include((((Byte) sts.i_byte).byteValue() + 2) > 100);
169: }
170: });
171:
172: expect(q, new int[] { 2, 3 });
173: }
174:
175: }
|