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 StringHandlerUpdateTestCase extends
026: HandlerUpdateTestCaseBase {
027:
028: private static final String[] data = new String[] { "one",
029: "aAzZ|!§$%&/()=?ßöäüÄÖÜYZ;:-_+*~#^°'@", "", null,
030:
031: };
032:
033: public static void main(String[] args) {
034: new TestRunner(StringHandlerUpdateTestCase.class).run();
035: }
036:
037: protected String typeName() {
038: return "string";
039: }
040:
041: public static class Item {
042:
043: public String _typed;
044:
045: public Object _untyped;
046:
047: }
048:
049: public static class ItemArrays {
050:
051: public String[] _typedArray;
052:
053: public Object[] _untypedArray;
054:
055: public Object _arrayInObject;
056:
057: }
058:
059: protected Object[] createValues() {
060: Item[] values = new Item[data.length + 1];
061: for (int i = 0; i < data.length; i++) {
062: Item item = new Item();
063: values[i] = item;
064: item._typed = data[i];
065: item._untyped = data[i];
066: }
067: values[values.length - 1] = new Item();
068: return values;
069: }
070:
071: protected Object createArrays() {
072: ItemArrays item = new ItemArrays();
073: createTypedArray(item);
074: createUntypedArray(item);
075: createArrayInObject(item);
076: return item;
077: }
078:
079: private void createUntypedArray(ItemArrays item) {
080: item._untypedArray = new String[data.length + 1];
081: for (int i = 0; i < data.length; i++) {
082: item._untypedArray[i] = data[i];
083: }
084: }
085:
086: private void createTypedArray(ItemArrays item) {
087: item._typedArray = new String[data.length];
088: System.arraycopy(data, 0, item._typedArray, 0, data.length);
089: }
090:
091: private void createArrayInObject(ItemArrays item) {
092: String[] arr = new String[data.length];
093: System.arraycopy(data, 0, arr, 0, data.length);
094: item._arrayInObject = arr;
095: }
096:
097: protected void assertValues(Object[] values) {
098: for (int i = 0; i < data.length; i++) {
099: Item item = (Item) values[i];
100: assertAreEqual(data[i], item._typed);
101: assertAreEqual(data[i], (String) item._untyped);
102: }
103: Item nullItem = (Item) values[values.length - 1];
104: Assert.isNull(nullItem._typed);
105: Assert.isNull(nullItem._untyped);
106: }
107:
108: protected void assertArrays(Object obj) {
109: ItemArrays item = (ItemArrays) obj;
110: assertTypedArray(item);
111: assertUntypedArray(item);
112: assertArrayInObject(item);
113: }
114:
115: private void assertTypedArray(ItemArrays item) {
116: assertData(item._typedArray);
117: }
118:
119: protected void assertUntypedArray(ItemArrays item) {
120: for (int i = 0; i < data.length; i++) {
121: assertAreEqual(data[i], (String) item._untypedArray[i]);
122: }
123: Assert
124: .isNull(item._untypedArray[item._untypedArray.length - 1]);
125: }
126:
127: private void assertArrayInObject(ItemArrays item) {
128: assertData((String[]) item._arrayInObject);
129: }
130:
131: private void assertData(String[] values) {
132: for (int i = 0; i < data.length; i++) {
133: assertAreEqual(data[i], values[i]);
134: }
135: }
136:
137: private void assertAreEqual(String expected, String actual) {
138: Assert.areEqual(expected, actual);
139: }
140:
141: }
|