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