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.types;
022:
023: import com.db4o.test.*;
024:
025: public class TEntry {
026:
027: public Object key;
028: public Object value;
029:
030: public TEntry() {
031: }
032:
033: public TEntry(Object key, Object value) {
034: this .key = key;
035: this .value = value;
036: }
037:
038: public TEntry firstElement() {
039: return new TEntry("first", "firstvalue");
040: }
041:
042: public TEntry lastElement() {
043: return new TEntry(new ObjectSimplePublic("lastKey"),
044: new ObjectSimplePublic("lastValue"));
045: }
046:
047: public TEntry noElement() {
048: return new TEntry("NO", "babe");
049: }
050:
051: public TEntry[] test(int ver) {
052: if (ver == 1) {
053: return new TEntry[] {
054: firstElement(),
055: new TEntry(new Integer(111),
056: new ObjectSimplePublic("111")),
057: new TEntry(new Long(9999111), new Double(0.4566)),
058: /*
059:
060: need to extend compare for the following
061:
062: new Entry(
063: new ObjectSimplePublic[]{
064: new ObjectSimplePublic("killer1"), new ObjectSimplePublic("killer2")
065: },
066: new ObjectSimplePublic[]{
067: new ObjectSimplePublic("killer3"), null, new ObjectSimplePublic("killer4")
068: }
069: ),
070: */
071: lastElement() };
072: }
073: return new TEntry[] {
074: new TEntry(new Integer(222), new ObjectSimplePublic(
075: "111")),
076: new TEntry("222", "TrippleTwo"),
077: new TEntry(new ObjectSimplePublic("2222"),
078: new ObjectSimplePublic("222")), };
079: }
080:
081: public void compare(TEntry[] a_cmp, int oneOrTwo, boolean keysOnly) {
082: TEntry[] tests = test(oneOrTwo);
083: TEntry[] cmp = new TEntry[a_cmp.length];
084: System.arraycopy(a_cmp, 0, cmp, 0, a_cmp.length);
085: if (cmp == null) {
086: Regression.addError("Entry:argument is null");
087: return;
088: }
089: if (cmp.length != tests.length) {
090: Regression.addError("Entry:arrays of different length");
091: return;
092: }
093: for (int i = 0; i < tests.length; i++) {
094: boolean found = false;
095: for (int j = 0; j < cmp.length; j++) {
096: if (cmp[j] != null) {
097: if (tests[i].key.equals(cmp[j].key)) {
098: if (!keysOnly) {
099: if (!tests[i].value.equals(cmp[j].value)) {
100: Regression.addError("Entry:inequality");
101: return;
102: }
103: }
104: cmp[j] = null;
105: found = true;
106: break;
107: }
108: }
109: }
110: if (!found) {
111:
112: Regression.addError("element not found");
113: }
114: }
115: }
116: }
|