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.collections;
022:
023: import java.util.*;
024:
025: import com.db4o.query.*;
026: import com.db4o.test.legacy.soda.*;
027: import com.db4o.test.legacy.soda.collections.*;
028:
029: public class STHashSetU implements STClass {
030:
031: public static transient SodaTest st;
032:
033: Object col;
034:
035: public STHashSetU() {
036: }
037:
038: public STHashSetU(Object[] arr) {
039: col = new HashSet();
040: for (int i = 0; i < arr.length; i++) {
041: ((HashSet) col).add(arr[i]);
042: }
043: }
044:
045: public Object[] store() {
046: return new Object[] {
047: new STHashSetU(),
048: new STHashSetU(new Object[0]),
049: new STHashSetU(new Object[] { new Integer(0),
050: new Integer(0) }),
051: new STHashSetU(new Object[] { new Integer(1),
052: new Integer(17),
053: new Integer(Integer.MAX_VALUE - 1) }),
054: new STHashSetU(new Object[] { new Integer(3),
055: new Integer(17), new Integer(25),
056: new Integer(Integer.MAX_VALUE - 2) }),
057: new STHashSetU(new Object[] { "foo",
058: new STElement("bar", "barbar") }),
059: new STHashSetU(new Object[] { "foo2",
060: new STElement("bar", "barbar2") }) };
061: }
062:
063: public void testDefaultContainsInteger() {
064: Query q = st.query();
065: Object[] r = store();
066: q.constrain(new STHashSetU(new Object[] { new Integer(17) }));
067: st.expect(q, new Object[] { r[3], r[4] });
068: }
069:
070: public void testDefaultContainsString() {
071: Query q = st.query();
072: Object[] r = store();
073: q.constrain(new STHashSetU(new Object[] { "foo" }));
074: st.expect(q, new Object[] { r[5] });
075: }
076:
077: public void testDefaultContainsTwo() {
078: Query q = st.query();
079: Object[] r = store();
080: q.constrain(new STHashSetU(new Object[] { new Integer(17),
081: new Integer(25) }));
082: st.expect(q, new Object[] { r[4] });
083: }
084:
085: public void testDescendOne() {
086: Query q = st.query();
087: Object[] r = store();
088: q.constrain(STHashSetU.class);
089: q.descend("col").constrain(new Integer(17));
090: st.expect(q, new Object[] { r[3], r[4] });
091: }
092:
093: public void testDescendTwo() {
094: Query q = st.query();
095: Object[] r = store();
096: q.constrain(STHashSetU.class);
097: Query qElements = q.descend("col");
098: qElements.constrain(new Integer(17));
099: qElements.constrain(new Integer(25));
100: st.expect(q, new Object[] { r[4] });
101: }
102:
103: public void testDescendSmaller() {
104: Query q = st.query();
105: Object[] r = store();
106: q.constrain(STHashSetU.class);
107: Query qElements = q.descend("col");
108: qElements.constrain(new Integer(3)).smaller();
109: st.expect(q, new Object[] { r[2], r[3] });
110: }
111:
112: public void testDefaultContainsObject() {
113: Query q = st.query();
114: Object[] r = store();
115: q.constrain(new STHashSetU(new Object[] { new STElement("bar",
116: null) }));
117: st.expect(q, new Object[] { r[5], r[6] });
118: }
119:
120: public void testDescendToObject() {
121: Query q = st.query();
122: Object[] r = store();
123: q.constrain(new STHashSetU());
124: q.descend("col").descend("foo1").constrain("bar");
125: st.expect(q, new Object[] { r[5], r[6] });
126: }
127:
128: }
|