001: /*
002: This source file is part of Smyle, a database library.
003: For up-to-date information, see http://www.drjava.de/smyle
004: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: For full license text, see doc/license/lgpl.txt in this distribution
021: */
022:
023: package drjava.smyle.tests;
024:
025: import java.io.*;
026: import java.util.*;
027: import junit.framework.*;
028: import drjava.smyle.*;
029: import drjava.smyle.meta.*;
030: import drjava.smyle.testtypes.*;
031: import drjava.util.*;
032: import org.artsProject.util.*;
033:
034: public class GeneratedCodeTest extends TestCase {
035: public GeneratedCodeTest(String name) {
036: super (name);
037: }
038:
039: DataTypes dt = new DataTypes(true, 1, 2, "test", new JustName(
040: "john")).bytesAdd((byte) 17).longsAdd(3).stringsAdd("test")
041: .structsAdd(new JustName("anne"));
042:
043: ByteVector bytes;
044: IntVector longs;
045: ArrayList<String> strings;
046: ArrayList<JustName> structs;
047:
048: public void setUp() {
049: bytes = new ByteVector();
050: longs = new IntVector();
051: strings = new ArrayList<String>();
052: structs = new ArrayList<JustName>();
053: bytes.add((byte) 17);
054: longs.add(3);
055: strings.add("test");
056: structs.add(new JustName("anne"));
057: }
058:
059: public void testFFields() {
060: assertEquals(ComparableBoolean.TRUE, DataTypes.f_b.of(dt));
061: assertEquals(new Integer(1), DataTypes.f_l.of(dt));
062: assertEquals(new Long(2), DataTypes.f_ll.of(dt));
063: assertEquals("test", DataTypes.f_s.of(dt));
064: assertEquals(new JustName("john"), DataTypes.f_strct.of(dt));
065: assertEquals(bytes, DataTypes.f_bytes.of(dt));
066: assertEquals(longs, DataTypes.f_longs.of(dt));
067: assertEquals(strings, DataTypes.f_strings.of(dt));
068: assertEquals(structs, DataTypes.f_structs.of(dt));
069: }
070:
071: public void testNestedFFields() {
072: NestedDataTypes nested = new NestedDataTypes(dt);
073: assertEquals(ComparableBoolean.TRUE, NestedDataTypes.f_nested_b
074: .of(nested));
075: assertEquals(new Integer(1), NestedDataTypes.f_nested_l
076: .of(nested));
077: assertEquals(new Long(2), NestedDataTypes.f_nested_ll
078: .of(nested));
079: assertEquals("test", NestedDataTypes.f_nested_s.of(nested));
080: assertEquals(new JustName("john"),
081: NestedDataTypes.f_nested_strct.of(nested));
082: assertEquals(bytes, NestedDataTypes.f_nested_bytes.of(nested));
083: assertEquals(longs, NestedDataTypes.f_nested_longs.of(nested));
084: assertEquals(strings, NestedDataTypes.f_nested_strings
085: .of(nested));
086: assertEquals(structs, NestedDataTypes.f_nested_structs
087: .of(nested));
088: }
089:
090: public void testCopyConstructors() {
091: assertEquals(dt, new DataTypes(dt));
092: }
093:
094: /** also tests autoincrement */
095: public void testStore() {
096: Store store1 = Smyle.createEmptyStore("temp/store");
097: Snapshot snapshot = store1.mutableSnapshot();
098: snapshot.getTable("autoincs", AutoInc.getTypeInfo()).add(
099: new AutoInc("green", 0));
100: snapshot.commit();
101: store1.close();
102:
103: MyStore store = MyStore.open("temp/store");
104: Table<AutoInc> table = store.autoincs(store.snapshot());
105: assertEquals(1, table.get(0).id);
106: store.close();
107:
108: store = MyStore.create("temp/store");
109: assertEquals(0, store.autoincs(store.snapshot()).size());
110: store.close();
111:
112: MyStore.open(new File("temp/store")).close();
113: MyStore.create(new File("temp/store")).close();
114:
115: store = MyStore.openReadOnly("temp/store");
116: assertEquals(0, store.autoincs(store.snapshot()).size());
117: try {
118: store.mutableSnapshot();
119: fail("No exception");
120: } catch (ReadOnlyException e) {
121: // ok
122: }
123: store.close();
124: }
125:
126: public void testRecursiveDataTypes() {
127: assertNotNull(Recursive.getTypeInfo().fieldTypes[0]);
128: Recursive r = new Recursive(), r2 = new Recursive();
129: r.recAdd(r2);
130: assertEquals(r, Recursive.fromHex(r.toHex()));
131: }
132: }
|