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