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