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