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.joins.untyped;
022:
023: import com.db4o.query.*;
024:
025: public class STOrUTestCase extends
026: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
027:
028: public static void main(String[] arguments) {
029: new STOrUTestCase().runAll();
030: }
031:
032: public Object orInt;
033: public Object orString;
034:
035: public STOrUTestCase() {
036: }
037:
038: private STOrUTestCase(int a_int, String a_string) {
039: orInt = new Integer(a_int);
040: orString = a_string;
041: }
042:
043: private STOrUTestCase(Object a_int, String a_string) {
044: orInt = a_int;
045: orString = a_string;
046: }
047:
048: public String toString() {
049: return "STOr: int:" + orInt + " str:" + orString;
050: }
051:
052: public Object[] createData() {
053: return new Object[] { new STOrUTestCase(0, "hi"),
054: new STOrUTestCase(5, null),
055: new STOrUTestCase(1000, "joho"),
056: new STOrUTestCase(30000, "osoo"),
057: new STOrUTestCase(Integer.MAX_VALUE - 1, null), };
058: }
059:
060: public void testSmallerGreater() {
061: Query q = newQuery();
062: q.constrain(new STOrUTestCase());
063: Query sub = q.descend("orInt");
064: sub.constrain(new Integer(30000)).greater().or(
065: sub.constrain(new Integer(5)).smaller());
066:
067: expect(q, new int[] { 0, 4 });
068: }
069:
070: public void testGreaterGreater() {
071: Query q = newQuery();
072: q.constrain(new STOrUTestCase());
073: Query sub = q.descend("orInt");
074: sub.constrain(new Integer(30000)).greater().or(
075: sub.constrain(new Integer(5)).greater());
076:
077: expect(q, new int[] { 2, 3, 4 });
078: }
079:
080: public void testGreaterEquals() {
081: Query q = newQuery();
082: q.constrain(new STOrUTestCase());
083: Query sub = q.descend("orInt");
084: sub.constrain(new Integer(1000)).greater().or(
085: sub.constrain(new Integer(0)));
086:
087: expect(q, new int[] { 0, 3, 4 });
088: }
089:
090: public void testEqualsNull() {
091: Query q = newQuery();
092: q.constrain(new STOrUTestCase(1000, null));
093: q.descend("orInt").constraints().or(
094: q.descend("orString").constrain(null));
095:
096: expect(q, new int[] { 1, 2, 4 });
097: }
098:
099: public void testAndOrAnd() {
100: Query q = newQuery();
101: q.constrain(new STOrUTestCase(null, null));
102: (q.descend("orInt").constrain(new Integer(5)).and(q.descend(
103: "orString").constrain(null))).or(q.descend("orInt")
104: .constrain(new Integer(1000)).and(
105: q.descend("orString").constrain("joho")));
106:
107: expect(q, new int[] { 1, 2 });
108: }
109:
110: public void testOrAndOr() {
111: Query q = newQuery();
112: q.constrain(new STOrUTestCase(null, null));
113: (q.descend("orInt").constrain(new Integer(5)).or(q.descend(
114: "orString").constrain(null))).and(q.descend("orInt")
115: .constrain(new Integer(Integer.MAX_VALUE - 1)).or(
116: q.descend("orString").constrain("joho")));
117: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
118: _array[4]);
119: }
120:
121: public void testOrOrAnd() {
122: Query q = newQuery();
123: q.constrain(new STOrUTestCase());
124: (q.descend("orInt").constrain(
125: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
126: "orString").constrain("joho"))).or(q.descend("orInt")
127: .constrain(new Integer(5)).and(
128: q.descend("orString").constrain(null)));
129:
130: expect(q, new int[] { 1, 2, 4 });
131: }
132:
133: public void testMultiOrAnd() {
134: Query q = newQuery();
135: q.constrain(new STOrUTestCase());
136: ((q.descend("orInt").constrain(
137: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
138: "orString").constrain("joho"))).or(q.descend("orInt")
139: .constrain(new Integer(5)).and(
140: q.descend("orString").constrain("joho"))))
141: .or((q.descend("orInt").constrain(
142: new Integer(Integer.MAX_VALUE - 1)).or(q
143: .descend("orString").constrain(null))).and(q
144: .descend("orInt").constrain(new Integer(5)).or(
145: q.descend("orString").constrain(null))));
146:
147: expect(q, new int[] { 1, 2, 4 });
148: }
149:
150: public void testNotSmallerGreater() {
151: Query q = newQuery();
152: q.constrain(new STOrUTestCase());
153: Query sub = q.descend("orInt");
154: (sub.constrain(new Integer(30000)).greater().or(sub.constrain(
155: new Integer(5)).smaller())).not();
156:
157: expect(q, new int[] { 1, 2, 3 });
158: }
159:
160: public void testNotGreaterGreater() {
161: Query q = newQuery();
162: q.constrain(new STOrUTestCase());
163: Query sub = q.descend("orInt");
164: (sub.constrain(new Integer(30000)).greater().or(sub.constrain(
165: new Integer(5)).greater())).not();
166:
167: expect(q, new int[] { 0, 1 });
168: }
169:
170: public void testNotGreaterEquals() {
171: Query q = newQuery();
172: q.constrain(new STOrUTestCase());
173: Query sub = q.descend("orInt");
174: (sub.constrain(new Integer(1000)).greater().or(sub
175: .constrain(new Integer(0)))).not();
176:
177: expect(q, new int[] { 1, 2 });
178: }
179:
180: public void testNotEqualsNull() {
181: Query q = newQuery();
182: q.constrain(new STOrUTestCase(1000, null));
183: (q.descend("orInt").constraints().or(q.descend("orString")
184: .constrain(null))).not();
185:
186: expect(q, new int[] { 0, 3 });
187: }
188:
189: public void testNotAndOrAnd() {
190: Query q = newQuery();
191: q.constrain(new STOrUTestCase());
192: (q.descend("orInt").constrain(new Integer(5)).and(q.descend(
193: "orString").constrain(null))).or(
194: q.descend("orInt").constrain(new Integer(1000)).and(
195: q.descend("orString").constrain("joho"))).not();
196:
197: expect(q, new int[] { 0, 3, 4 });
198: }
199:
200: public void testNotOrAndOr() {
201: Query q = newQuery();
202: q.constrain(new STOrUTestCase());
203: (q.descend("orInt").constrain(new Integer(5)).or(q.descend(
204: "orString").constrain(null))).and(
205: q.descend("orInt").constrain(
206: new Integer(Integer.MAX_VALUE - 1)).or(
207: q.descend("orString").constrain("joho"))).not();
208:
209: expect(q, new int[] { 0, 1, 2, 3 });
210: }
211:
212: public void testNotOrOrAnd() {
213: Query q = newQuery();
214: q.constrain(new STOrUTestCase());
215: (q.descend("orInt").constrain(
216: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
217: "orString").constrain("joho"))).or(
218: q.descend("orInt").constrain(new Integer(5)).and(
219: q.descend("orString").constrain(null))).not();
220:
221: expect(q, new int[] { 0, 3 });
222: }
223:
224: public void testNotMultiOrAnd() {
225: Query q = newQuery();
226: q.constrain(new STOrUTestCase());
227: ((q.descend("orInt").constrain(
228: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
229: "orString").constrain("joho"))).or(q.descend("orInt")
230: .constrain(new Integer(5)).and(
231: q.descend("orString").constrain("joho"))))
232: .or(
233: (q.descend("orInt").constrain(
234: new Integer(Integer.MAX_VALUE - 1))
235: .or(q.descend("orString").constrain(
236: null))).and(q.descend("orInt")
237: .constrain(new Integer(5)).or(
238: q.descend("orString")
239: .constrain(null))))
240: .not();
241:
242: expect(q, new int[] { 0, 3 });
243: }
244:
245: public void testOrNotAndOr() {
246: Query q = newQuery();
247: q.constrain(new STOrUTestCase());
248: (q.descend("orInt").constrain(
249: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
250: "orString").constrain("joho"))).not().and(
251: q.descend("orInt").constrain(new Integer(5)).or(
252: q.descend("orString").constrain(null)));
253:
254: expect(q, new int[] { 1 });
255: }
256:
257: public void testAndNotAndAnd() {
258: Query q = newQuery();
259: q.constrain(new STOrUTestCase());
260: (q.descend("orInt").constrain(
261: new Integer(Integer.MAX_VALUE - 1)).and(q.descend(
262: "orString").constrain(null))).not().and(
263: q.descend("orInt").constrain(new Integer(5)).or(
264: q.descend("orString").constrain("osoo")));
265:
266: expect(q, new int[] { 1, 3 });
267: }
268:
269: }
|