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