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