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