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 STByte implements STClass1 {
028:
029: final static String DESCENDANT = "i_byte";
030:
031: public static transient SodaTest st;
032:
033: public byte i_byte;
034:
035: public STByte() {
036: }
037:
038: private STByte(byte a_byte) {
039: i_byte = a_byte;
040: }
041:
042: public Object[] store() {
043: return new Object[] { new STByte((byte) 0),
044: new STByte((byte) 1), new STByte((byte) 99),
045: new STByte((byte) 113) };
046: }
047:
048: public void testEquals() {
049: Query q = st.query();
050: q.constrain(new STByte((byte) 0));
051:
052: // Primitive default values are ignored, so we need an
053: // additional constraint:
054: q.descend(DESCENDANT).constrain(new Byte((byte) 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 Byte((byte) 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 STByte((byte) 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 STByte((byte) 1));
077: q.descend(DESCENDANT).constraints().smaller();
078: st.expectOne(q, store()[0]);
079: }
080:
081: public void testContains() {
082: Query q = st.query();
083: Constraint c = q.constrain(new STByte((byte) 9));
084: q.descend(DESCENDANT).constraints().contains();
085: Object[] r = store();
086: st.expect(q, new Object[] { r[2] });
087: }
088:
089: public void testNotContains() {
090: Query q = st.query();
091: Constraint c = q.constrain(new STByte((byte) 0));
092: q.descend(DESCENDANT).constrain(new Byte((byte) 0)).contains()
093: .not();
094: Object[] r = store();
095: st.expect(q, new Object[] { r[1], r[2], r[3] });
096: }
097:
098: public void testLike() {
099: Query q = st.query();
100: Constraint c = q.constrain(new STByte((byte) 11));
101: q.descend(DESCENDANT).constraints().like();
102: st.expectOne(q, new STByte((byte) 113));
103: q = st.query();
104: c = q.constrain(new STByte((byte) 10));
105: q.descend(DESCENDANT).constraints().like();
106: st.expectNone(q);
107: }
108:
109: public void testNotLike() {
110: Query q = st.query();
111: Constraint c = q.constrain(new STByte((byte) 1));
112: q.descend(DESCENDANT).constraints().like().not();
113: Object[] r = store();
114: st.expect(q, new Object[] { r[0], r[2] });
115: }
116:
117: public void testIdentity() {
118: Query q = st.query();
119: Constraint c = q.constrain(new STByte((byte) 1));
120: ObjectSet set = q.execute();
121: STByte identityConstraint = (STByte) set.next();
122: identityConstraint.i_byte = 102;
123: q = st.query();
124: q.constrain(identityConstraint).identity();
125: identityConstraint.i_byte = 1;
126: st.expectOne(q, store()[1]);
127: }
128:
129: public void testNotIdentity() {
130: Query q = st.query();
131: Constraint c = q.constrain(new STByte((byte) 1));
132: ObjectSet set = q.execute();
133: STByte identityConstraint = (STByte) set.next();
134: identityConstraint.i_byte = 102;
135: q = st.query();
136: q.constrain(identityConstraint).identity().not();
137: identityConstraint.i_byte = 1;
138: Object[] r = store();
139: st.expect(q, new Object[] { r[0], r[2], r[3] });
140: }
141:
142: public void testConstraints() {
143: Query q = st.query();
144: q.constrain(new STByte((byte) 1));
145: q.constrain(new STByte((byte) 0));
146: Constraints cs = q.constraints();
147: Constraint[] csa = cs.toArray();
148: if (csa.length != 2) {
149: st.error("Constraints not returned");
150: }
151: }
152:
153: }
|