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.deepOR;
022:
023: import java.util.*;
024:
025: import com.db4o.query.*;
026:
027: public class STOrContainsTestCase extends
028: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
029:
030: String name;
031: ArrayList al1;
032: ArrayList al2;
033:
034: public STOrContainsTestCase() {
035: }
036:
037: public STOrContainsTestCase(String name, Object[] l1, Object[] l2) {
038: this .name = name;
039: al1 = new ArrayList();
040: if (l1 != null) {
041: for (int i = 0; i < l1.length; i++) {
042: al1.add(l1[i]);
043: }
044: }
045: al2 = new ArrayList();
046: if (l2 != null) {
047: for (int i = 0; i < l2.length; i++) {
048: al2.add(l2[i]);
049: }
050: }
051:
052: }
053:
054: public Object[] createData() {
055: return new Object[] {
056: new STOrContainsTestCase("one", new Object[] {
057: new Named("Marcus"), new Named("8"),
058: new Named("Woohaa") }, new Object[] {
059: new Named("one"), new Named("two"),
060: new Named("three") }),
061: new STOrContainsTestCase("two", new Object[] {
062: new Named("one"), new Named("two"),
063: new Named("three") }, new Object[] {
064: new Named("Marcus"), new Named("8"),
065: new Named("Woohaa") }),
066: new STOrContainsTestCase("three", new Object[] {
067: new Named("is"), new Named("this"),
068: new Named("true") }, new Object[] {
069: new Named("no"), new Named("ho"),
070: new Named("wo") }) };
071: }
072:
073: public void testNoneFound() {
074: Query q = newQuery();
075: q.constrain(STOrContainsTestCase.class);
076: Query name1 = q.descend("al1").descend("name");
077: Query name2 = q.descend("al2").descend("name");
078: name1.constrain("hugolo").or(name2.constrain("hugoli"));
079:
080: expect(q, new int[] {});
081: }
082:
083: public void testOneFound() {
084: Query q = newQuery();
085: q.constrain(STOrContainsTestCase.class);
086: Query name1 = q.descend("al1").descend("name");
087: Query name2 = q.descend("al2").descend("name");
088: name1.constrain("Woohaa").or(name2.constrain("Woohaa"));
089:
090: expect(q, new int[] { 0, 1 });
091: }
092:
093: public void testBothFound() {
094: Query q = newQuery();
095: q.constrain(STOrContainsTestCase.class);
096: Query name1 = q.descend("al1").descend("name");
097: Query name2 = q.descend("al2").descend("name");
098: name1.constrain("Marcus").or(name2.constrain("three"));
099:
100: expect(q, new int[] { 0 });
101: }
102:
103: public void testMoreOr1() {
104: Query q = newQuery();
105: q.constrain(STOrContainsTestCase.class);
106: Query name1 = q.descend("al1").descend("name");
107: Query name2 = q.descend("al2").descend("name");
108: name1.constrain("Marcus").or(name2.constrain("three")).or(
109: q.descend("name").constrain("three"));
110:
111: expect(q, new int[] { 0, 2 });
112: }
113:
114: public void testMoreOr2() {
115: Query q = newQuery();
116: q.constrain(STOrContainsTestCase.class);
117: Query name1 = q.descend("al1").descend("name");
118: Query name2 = q.descend("al2").descend("name");
119: name1.constrain("Marcus").or(name2.constrain("wo")).or(
120: q.descend("name").constrain("three"));
121:
122: expect(q, new int[] { 0, 2 });
123: }
124:
125: public static class Named {
126: String name;
127:
128: public Named() {
129: }
130:
131: public Named(String name) {
132: this.name = name;
133: }
134: }
135:
136: }
|