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 STCharTestCase extends
027: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
028:
029: final static String DESCENDANT = "i_char";
030:
031: public char i_char;
032:
033: public STCharTestCase() {
034: }
035:
036: private STCharTestCase(char a_char) {
037: i_char = a_char;
038: }
039:
040: public Object[] createData() {
041: return new Object[] { new STCharTestCase((char) 0),
042: new STCharTestCase((char) 1),
043: new STCharTestCase((char) 99),
044: new STCharTestCase((char) 909) };
045: }
046:
047: public void testEquals() {
048: Query q = newQuery();
049: q.constrain(new STCharTestCase((char) 0));
050:
051: // Primitive default values are ignored, so we need an
052: // additional constraint:
053: q.descend(DESCENDANT).constrain(new Character((char) 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 Character((char) 0)).not();
063: expect(q, new int[] { 1, 2, 3 });
064: }
065:
066: public void testGreater() {
067: Query q = newQuery();
068: q.constrain(new STCharTestCase((char) 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 STCharTestCase((char) 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 testIdentity() {
083: Query q = newQuery();
084: q.constrain(new STCharTestCase((char) 1));
085: ObjectSet set = q.execute();
086: STCharTestCase identityConstraint = (STCharTestCase) set.next();
087: identityConstraint.i_char = 9999;
088: q = newQuery();
089: q.constrain(identityConstraint).identity();
090: identityConstraint.i_char = 1;
091: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
092: _array[1]);
093: }
094:
095: public void testNotIdentity() {
096: Query q = newQuery();
097: q.constrain(new STCharTestCase((char) 1));
098: ObjectSet set = q.execute();
099: STCharTestCase identityConstraint = (STCharTestCase) set.next();
100: identityConstraint.i_char = 9080;
101: q = newQuery();
102: q.constrain(identityConstraint).identity().not();
103: identityConstraint.i_char = 1;
104:
105: expect(q, new int[] { 0, 2, 3 });
106: }
107:
108: public void testConstraints() {
109: Query q = newQuery();
110: q.constrain(new STCharTestCase((char) 1));
111: q.constrain(new STCharTestCase((char) 0));
112: Constraints cs = q.constraints();
113: Constraint[] csa = cs.toArray();
114: if (csa.length != 2) {
115: db4ounit.Assert.fail("Constraints not returned");
116: }
117: }
118:
119: }
|