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