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