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