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