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.common.soda.arrays.untyped;
022:
023: import com.db4o.query.*;
024:
025: public class STArrMixedNTestCase extends
026: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
027:
028: public Object[][][] arr;
029:
030: public STArrMixedNTestCase() {
031: }
032:
033: public STArrMixedNTestCase(Object[][][] arr) {
034: this .arr = arr;
035: }
036:
037: public Object[] createData() {
038: STArrMixedNTestCase[] arrMixed = new STArrMixedNTestCase[5];
039:
040: arrMixed[0] = new STArrMixedNTestCase();
041:
042: Object[][][] content = new Object[1][1][2];
043: arrMixed[1] = new STArrMixedNTestCase(content);
044:
045: content = new Object[2][2][3];
046: arrMixed[2] = new STArrMixedNTestCase(content);
047:
048: content = new Object[2][2][3];
049: content[0][0][1] = "foo";
050: content[0][1][0] = "bar";
051: content[0][1][2] = "fly";
052: content[1][0][0] = new Boolean(false);
053: arrMixed[3] = new STArrMixedNTestCase(content);
054:
055: content = new Object[2][2][3];
056: content[0][0][0] = "bar";
057: content[0][1][0] = "wohay";
058: content[0][1][1] = "johy";
059: content[1][0][0] = new Integer(12);
060: arrMixed[4] = new STArrMixedNTestCase(content);
061:
062: Object[] ret = new Object[arrMixed.length];
063: System.arraycopy(arrMixed, 0, ret, 0, arrMixed.length);
064: return ret;
065: }
066:
067: public void testDefaultContainsString() {
068: Query q = newQuery();
069:
070: Object[][][] content = new Object[1][1][1];
071: content[0][0][0] = "bar";
072: q.constrain(new STArrMixedNTestCase(content));
073: expect(q, new int[] { 3, 4 });
074: }
075:
076: public void testDefaultContainsInteger() {
077: Query q = newQuery();
078:
079: Object[][][] content = new Object[1][1][1];
080: content[0][0][0] = new Integer(12);
081: q.constrain(new STArrMixedNTestCase(content));
082: expect(q, new int[] { 4 });
083: }
084:
085: public void testDefaultContainsBoolean() {
086: Query q = newQuery();
087:
088: Object[][][] content = new Object[1][1][1];
089: content[0][0][0] = new Boolean(false);
090: q.constrain(new STArrMixedNTestCase(content));
091: expect(q, new int[] { 3 });
092: }
093:
094: public void testDefaultContainsTwo() {
095: Query q = newQuery();
096:
097: Object[][][] content = new Object[2][1][1];
098: content[0][0][0] = "bar";
099: content[1][0][0] = new Integer(12);
100: q.constrain(new STArrMixedNTestCase(content));
101: expect(q, new int[] { 4 });
102: }
103:
104: public void testDescendOne() {
105: Query q = newQuery();
106:
107: q.constrain(STArrMixedNTestCase.class);
108: q.descend("arr").constrain("bar");
109: expect(q, new int[] { 3, 4 });
110: }
111:
112: public void testDescendTwo() {
113: Query q = newQuery();
114:
115: q.constrain(STArrMixedNTestCase.class);
116: Query qElements = q.descend("arr");
117: qElements.constrain("foo");
118: qElements.constrain("bar");
119: expect(q, new int[] { 3 });
120: }
121:
122: public void testDescendOneNot() {
123: Query q = newQuery();
124:
125: q.constrain(STArrMixedNTestCase.class);
126: q.descend("arr").constrain("bar").not();
127: expect(q, new int[] { 0, 1, 2 });
128: }
129:
130: public void testDescendTwoNot() {
131: Query q = newQuery();
132:
133: q.constrain(STArrMixedNTestCase.class);
134: Query qElements = q.descend("arr");
135: qElements.constrain("foo").not();
136: qElements.constrain("bar").not();
137: expect(q, new int[] { 0, 1, 2 });
138: }
139:
140: }
|