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.handlers;
022:
023: import db4ounit.*;
024:
025: public class ObjectArrayUpdateTestCase extends
026: HandlerUpdateTestCaseBase {
027:
028: private static ParentItem[] childData = new ParentItem[] {
029: new ChildItem("one"), new ChildItem("two"), null, };
030:
031: private static ParentItem[] mixedData = new ParentItem[] {
032: new ParentItem("one"), new ChildItem("two"),
033: new ChildItem("three"), null, };
034:
035: public static class ItemArrays {
036:
037: public ChildItem[] _typedChildren;
038:
039: public ParentItem[] _typedChildrenInParentArray;
040:
041: public Object[] _untypedChildren;
042:
043: public Object[] _untypedChildrenInParentArray;
044:
045: public Object _untypedChildrenInObject;
046:
047: public Object _untypedChildrenInParentArrayInObject;
048:
049: public ParentItem[] _typedMixed;
050:
051: public Object[] _untypedMixed;
052:
053: public Object _untypedMixedInObject;
054:
055: }
056:
057: public static class ParentItem {
058:
059: public String _name;
060:
061: public ParentItem(String name) {
062: _name = name;
063: }
064:
065: public boolean equals(Object obj) {
066: if (!(obj instanceof ParentItem)) {
067: return false;
068: }
069: if (obj instanceof ChildItem) {
070: return false;
071: }
072: return hasSameNameAs((ParentItem) obj);
073: }
074:
075: protected boolean hasSameNameAs(ParentItem other) {
076: if (_name == null) {
077: return other._name == null;
078: }
079: return _name.equals(other._name);
080: }
081:
082: }
083:
084: public static class ChildItem extends ParentItem {
085:
086: public ChildItem(String name) {
087: super (name);
088: }
089:
090: public boolean equals(Object obj) {
091: if (!(obj instanceof ChildItem)) {
092: return false;
093: }
094: return hasSameNameAs((ParentItem) obj);
095: }
096:
097: }
098:
099: protected Object createArrays() {
100: ItemArrays item = new ItemArrays();
101: item._typedChildren = castToChildItemArray(childData);
102: item._typedChildrenInParentArray = childData;
103: item._untypedChildren = castToChildItemArray(childData);
104: item._untypedChildrenInParentArray = childData;
105: item._untypedChildrenInObject = castToChildItemArray(childData);
106: item._untypedChildrenInParentArrayInObject = childData;
107: item._typedMixed = mixedData;
108: item._untypedMixed = mixedData;
109: item._untypedMixedInObject = mixedData;
110: return item;
111: }
112:
113: protected void assertArrays(Object obj) {
114: ItemArrays item = (ItemArrays) obj;
115: ArrayAssert.areEqual(castToChildItemArray(childData),
116: item._typedChildren);
117: ArrayAssert.areEqual(childData,
118: item._typedChildrenInParentArray);
119: ArrayAssert.areEqual(castToChildItemArray(childData),
120: item._untypedChildren);
121: ArrayAssert.areEqual(childData,
122: item._untypedChildrenInParentArray);
123: ArrayAssert.areEqual(castToChildItemArray(childData),
124: (Object[]) item._untypedChildrenInObject);
125: ArrayAssert.areEqual(childData,
126: (Object[]) item._untypedChildrenInParentArrayInObject);
127: ArrayAssert.areEqual(mixedData, item._typedMixed);
128: ArrayAssert.areEqual(mixedData, item._untypedMixed);
129: ArrayAssert.areEqual(mixedData,
130: (Object[]) item._untypedMixedInObject);
131: }
132:
133: private ChildItem[] castToChildItemArray(ParentItem[] array) {
134: ChildItem[] res = new ChildItem[array.length];
135: for (int i = 0; i < res.length; i++) {
136: res[i] = (ChildItem) array[i];
137: }
138: return res;
139: }
140:
141: protected Object[] createValues() {
142: // not used
143: return null;
144: }
145:
146: protected void assertValues(Object[] values) {
147: // not used
148: }
149:
150: protected String typeName() {
151: return "object-array";
152: }
153:
154: }
|