01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.db4ounit.common.handlers;
22:
23: public class UntypedHandlerTestCase extends TypeHandlerTestCaseBase {
24:
25: public static void main(String[] args) {
26: new UntypedHandlerTestCase().runSolo();
27: }
28:
29: public static class Item {
30:
31: public Object _member;
32:
33: public Item(Object member) {
34: _member = member;
35: }
36:
37: public boolean equals(Object obj) {
38: if (obj == this ) {
39: return true;
40: }
41: if (!(obj instanceof Item)) {
42: return false;
43: }
44: Item other = (Item) obj;
45: if (this ._member.getClass().isArray()) {
46: return arraysEquals((Object[]) this ._member,
47: (Object[]) other._member);
48: }
49: return this ._member.equals(other._member);
50:
51: }
52:
53: private boolean arraysEquals(Object[] arr1, Object[] arr2) {
54: if (arr1.length != arr2.length) {
55: return false;
56: }
57: for (int i = 0; i < arr1.length; i++) {
58: if (!arr1[i].equals(arr2[i])) {
59: return false;
60: }
61: }
62: return true;
63: }
64:
65: public int hashCode() {
66: int hash = 7;
67: hash = 31 * hash
68: + (null == _member ? 0 : _member.hashCode());
69: return hash;
70: }
71:
72: public String toString() {
73: return "[" + _member + "]";
74: }
75: }
76:
77: public void testStoreIntItem() throws Exception {
78: doTestStoreObject(new Item(new Integer(3355)));
79: }
80:
81: public void testStoreStringItem() throws Exception {
82: doTestStoreObject(new Item("one"));
83: }
84:
85: public void testStoreArrayItem() throws Exception {
86: doTestStoreObject(new Item(
87: new String[] { "one", "two", "three" }));
88: }
89:
90: }
|