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 STOwnCollectionTTestCase extends
028: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
029:
030: MyCollection col;
031:
032: public STOwnCollectionTTestCase() {
033:
034: }
035:
036: public STOwnCollectionTTestCase(Object[] arr) {
037: col = new MyCollection();
038: for (int i = 0; i < arr.length; i++) {
039: col.add(arr[i]);
040: }
041: }
042:
043: public Object[] createData() {
044: return new Object[] {
045: new STOwnCollectionTTestCase(),
046: new STOwnCollectionTTestCase(new Object[0]),
047: new STOwnCollectionTTestCase(new Object[] {
048: new Integer(0), new Integer(0) }),
049: new STOwnCollectionTTestCase(new Object[] {
050: new Integer(1), new Integer(17),
051: new Integer(Integer.MAX_VALUE - 1) }),
052: new STOwnCollectionTTestCase(new Object[] {
053: new Integer(3), new Integer(17),
054: new Integer(25),
055: new Integer(Integer.MAX_VALUE - 2) }),
056: new STOwnCollectionTTestCase(new Object[] { "foo",
057: new STElement("bar", "barbar") }),
058: new STOwnCollectionTTestCase(new Object[] { "foo2",
059: new STElement("bar", "barbar2") }) };
060: }
061:
062: public void testDefaultContainsInteger() {
063: Query q = newQuery();
064:
065: q.constrain(new STOwnCollectionTTestCase(
066: new Object[] { new Integer(17) }));
067: expect(q, new int[] { 3, 4 });
068: }
069:
070: public void testDefaultContainsString() {
071: Query q = newQuery();
072:
073: q
074: .constrain(new STOwnCollectionTTestCase(
075: new Object[] { "foo" }));
076: expect(q, new int[] { 5 });
077: }
078:
079: public void testDefaultContainsTwo() {
080: Query q = newQuery();
081:
082: q.constrain(new STOwnCollectionTTestCase(new Object[] {
083: new Integer(17), new Integer(25) }));
084: expect(q, new int[] { 4 });
085: }
086:
087: public void testDescendOne() {
088: Query q = newQuery();
089:
090: q.constrain(STOwnCollectionTTestCase.class);
091: q.descend("col").constrain(new Integer(17));
092: expect(q, new int[] { 3, 4 });
093: }
094:
095: public void testDescendTwo() {
096: Query q = newQuery();
097:
098: q.constrain(STOwnCollectionTTestCase.class);
099: Query qElements = q.descend("col");
100: qElements.constrain(new Integer(17));
101: qElements.constrain(new Integer(25));
102: expect(q, new int[] { 4 });
103: }
104:
105: public void testDescendSmaller() {
106: Query q = newQuery();
107:
108: q.constrain(STOwnCollectionTTestCase.class);
109: Query qElements = q.descend("col");
110: qElements.constrain(new Integer(3)).smaller();
111: expect(q, new int[] { 2, 3 });
112: }
113:
114: public void testDefaultContainsObject() {
115: Query q = newQuery();
116:
117: q.constrain(new STOwnCollectionTTestCase(
118: new Object[] { new STElement("bar", null) }));
119: expect(q, new int[] { 5, 6 });
120: }
121:
122: public void testDescendToObject() {
123: Query q = newQuery();
124:
125: q.constrain(new STOwnCollectionTTestCase());
126: q.descend("col").descend("foo1").constrain("bar");
127: expect(q, new int[] { 5, 6 });
128: }
129:
130: public static class MyCollection implements Collection {
131:
132: ArrayList myList;
133:
134: public MyCollection() {
135: myList = new ArrayList();
136: }
137:
138: public int size() {
139: return myList.size();
140: }
141:
142: public boolean isEmpty() {
143: return myList.isEmpty();
144: }
145:
146: public boolean contains(Object o) {
147: return myList.contains(o);
148: }
149:
150: public Iterator iterator() {
151: return myList.iterator();
152: }
153:
154: public Object[] toArray() {
155: return myList.toArray();
156: }
157:
158: public Object[] toArray(Object[] a) {
159: return myList.toArray(a);
160: }
161:
162: public boolean add(Object o) {
163: return myList.add(o);
164: }
165:
166: public boolean remove(Object o) {
167: return myList.remove(o);
168: }
169:
170: public boolean containsAll(Collection c) {
171: return myList.containsAll(c);
172: }
173:
174: public boolean addAll(Collection c) {
175: return myList.addAll(c);
176: }
177:
178: public boolean removeAll(Collection c) {
179: return myList.removeAll(c);
180: }
181:
182: public boolean retainAll(Collection c) {
183: return myList.retainAll(c);
184: }
185:
186: public void clear() {
187: myList.clear();
188: }
189:
190: public boolean equals(Object o) {
191: return myList.equals(o);
192: }
193:
194: public int hashCode() {
195: return myList.hashCode();
196: }
197: }
198: }
|