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