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 java.util.*;
024:
025: import com.db4o.internal.handlers.*;
026: import com.db4o.internal.marshall.*;
027:
028: import db4ounit.*;
029:
030: public class DateHandlerUpdateTestCase extends
031: HandlerUpdateTestCaseBase {
032:
033: public static class Item {
034:
035: public Date _date;
036:
037: public Object _untyped;
038: }
039:
040: public static class ItemArrays {
041:
042: public Date[] _dateArray;
043:
044: public Object[] _untypedObjectArray;
045:
046: public Object _arrayInObject;
047:
048: }
049:
050: private static final Date[] data = {
051: new Date(DatePlatform.MIN_DATE),
052: new Date(DatePlatform.MIN_DATE + 1),
053: new Date(1191972104500L),
054: new Date(DatePlatform.MAX_DATE - 1),
055: new Date(DatePlatform.MAX_DATE), };
056:
057: public static void main(String[] args) {
058: new TestRunner(DateHandlerUpdateTestCase.class).run();
059: }
060:
061: protected void assertArrays(Object obj) {
062: ItemArrays itemArrays = (ItemArrays) obj;
063: Date[] dateArray = (Date[]) itemArrays._arrayInObject;
064: for (int i = 0; i < data.length; i++) {
065: assertAreEqual(data[i], itemArrays._dateArray[i]);
066: assertAreEqual(data[i],
067: (Date) itemArrays._untypedObjectArray[i]);
068: assertAreEqual(data[i], dateArray[i]);
069: }
070:
071: // Assert.isNull(itemArrays._dateArray[data.length]);
072:
073: Assert.isNull(itemArrays._untypedObjectArray[data.length]);
074:
075: // FIXME: We are not signalling null for Dates in typed arrays in
076: // the current handler format:
077: Assert.areEqual(emptyValue(), dateArray[data.length]);
078: }
079:
080: protected void assertValues(Object[] values) {
081: for (int i = 0; i < data.length; i++) {
082: Item item = (Item) values[i];
083: assertAreEqual(data[i], item._date);
084: assertAreEqual(data[i], (Date) item._untyped);
085: }
086:
087: Item emptyItem = (Item) values[values.length - 1];
088: Assert.areEqual(emptyValue(), emptyItem._date);
089: Assert.isNull(emptyItem._untyped);
090: }
091:
092: private Object emptyValue() {
093: return new DateHandler(null).primitiveNull();
094: }
095:
096: private void assertAreEqual(Date expected, Date actual) {
097: if (expected.equals(new Date(DatePlatform.MAX_DATE))
098: && _handlerVersion == 0) {
099: // Bug in the oldest format: It treats a Long.MAX_VALUE date as null.
100: expected = MarshallingConstants0.NULL_DATE;
101: }
102: Assert.areEqual(expected, actual);
103: }
104:
105: protected Object createArrays() {
106: ItemArrays itemArrays = new ItemArrays();
107: itemArrays._dateArray = new Date[data.length + 1];
108: System
109: .arraycopy(data, 0, itemArrays._dateArray, 0,
110: data.length);
111:
112: itemArrays._untypedObjectArray = new Object[data.length + 1];
113: System.arraycopy(data, 0, itemArrays._untypedObjectArray, 0,
114: data.length);
115:
116: Date[] dateArray = new Date[data.length + 1];
117: System.arraycopy(data, 0, dateArray, 0, data.length);
118: itemArrays._arrayInObject = dateArray;
119: return itemArrays;
120: }
121:
122: protected Object[] createValues() {
123: Item[] values = new Item[data.length + 1];
124: for (int i = 0; i < data.length; i++) {
125: Item item = new Item();
126: item._date = data[i];
127: item._untyped = data[i];
128: values[i] = item;
129: }
130: values[values.length - 1] = new Item();
131: return values;
132: }
133:
134: protected String typeName() {
135: return "date";
136: }
137:
138: }
|