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