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.test.legacy.soda.classes.simple;
022:
023: import com.db4o.*;
024: import com.db4o.query.*;
025: import com.db4o.test.legacy.soda.*;
026:
027: public class STChar implements STClass1 {
028:
029: final static String DESCENDANT = "i_char";
030:
031: public static transient SodaTest st;
032:
033: public char i_char;
034:
035: public STChar() {
036: }
037:
038: private STChar(char a_char) {
039: i_char = a_char;
040: }
041:
042: public Object[] store() {
043: return new Object[] { new STChar((char) 0),
044: new STChar((char) 1), new STChar((char) 99),
045: new STChar((char) 909) };
046: }
047:
048: public void testEquals() {
049: Query q = st.query();
050: q.constrain(new STChar((char) 0));
051:
052: // Primitive default values are ignored, so we need an
053: // additional constraint:
054: q.descend(DESCENDANT).constrain(new Character((char) 0));
055: st.expectOne(q, store()[0]);
056: }
057:
058: public void testNotEquals() {
059: Query q = st.query();
060: Object[] r = store();
061: Constraint c = q.constrain(r[0]);
062: q.descend(DESCENDANT).constrain(new Character((char) 0)).not();
063: st.expect(q, new Object[] { r[1], r[2], r[3] });
064: }
065:
066: public void testGreater() {
067: Query q = st.query();
068: Constraint c = q.constrain(new STChar((char) 9));
069: q.descend(DESCENDANT).constraints().greater();
070: Object[] r = store();
071: st.expect(q, new Object[] { r[2], r[3] });
072: }
073:
074: public void testSmaller() {
075: Query q = st.query();
076: Constraint c = q.constrain(new STChar((char) 1));
077: q.descend(DESCENDANT).constraints().smaller();
078: st.expectOne(q, store()[0]);
079: }
080:
081: public void testIdentity() {
082: Query q = st.query();
083: Constraint c = q.constrain(new STChar((char) 1));
084: ObjectSet set = q.execute();
085: STChar identityConstraint = (STChar) set.next();
086: identityConstraint.i_char = 9999;
087: q = st.query();
088: q.constrain(identityConstraint).identity();
089: identityConstraint.i_char = 1;
090: st.expectOne(q, store()[1]);
091: }
092:
093: public void testNotIdentity() {
094: Query q = st.query();
095: Constraint c = q.constrain(new STChar((char) 1));
096: ObjectSet set = q.execute();
097: STChar identityConstraint = (STChar) set.next();
098: identityConstraint.i_char = 9080;
099: q = st.query();
100: q.constrain(identityConstraint).identity().not();
101: identityConstraint.i_char = 1;
102: Object[] r = store();
103: st.expect(q, new Object[] { r[0], r[2], r[3] });
104: }
105:
106: public void testConstraints() {
107: Query q = st.query();
108: q.constrain(new STChar((char) 1));
109: q.constrain(new STChar((char) 0));
110: Constraints cs = q.constraints();
111: Constraint[] csa = cs.toArray();
112: if (csa.length != 2) {
113: st.error("Constraints not returned");
114: }
115: }
116:
117: }
|