summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2006-09-08 18:48:32 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2006-09-08 18:48:32 +0000
commitabd574dd1afe6bf7bb33f5e05c9ecfec624401bd (patch)
tree1759bb5ba8abb5960d8f86974188718772042b38 /test
parentd89f63cae748a3e4f51185e392607ecd63c71a15 (diff)
downloadjackcess-abd574dd1afe6bf7bb33f5e05c9ecfec624401bd.tar.gz
jackcess-abd574dd1afe6bf7bb33f5e05c9ecfec624401bd.zip
clean up lots of cruft around datatypes; add more sanity checking on table creation; fix free space calculations
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@105 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java91
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/TableTest.java3
2 files changed, 90 insertions, 4 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
index 18d3b47..ccefd0f 100644
--- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
@@ -9,6 +9,7 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -35,6 +36,63 @@ public class DatabaseTest extends TestCase {
return Database.create(tmp);
}
+ public void testInvalidTableDefs() throws Exception {
+ Database db = create();
+
+ try {
+ db.createTable("test", Collections.<Column>emptyList());
+ fail("created table with no columns?");
+ } catch(IllegalArgumentException e) {
+ // success
+ }
+
+ List<Column> columns = new ArrayList<Column>();
+ Column col = new Column();
+ col.setName("A");
+ col.setType(DataType.TEXT);
+ columns.add(col);
+ col = new Column();
+ col.setName("a");
+ col.setType(DataType.MEMO);
+ columns.add(col);
+
+ try {
+ db.createTable("test", columns);
+ fail("created table with duplicate column names?");
+ } catch(IllegalArgumentException e) {
+ // success
+ }
+
+ columns = new ArrayList<Column>();
+ col = new Column();
+ col.setName("A");
+ col.setType(DataType.TEXT);
+ col.setLength((short)(352 * 2));
+ columns.add(col);
+
+ try {
+ db.createTable("test", columns);
+ fail("created table with invalid column length?");
+ } catch(IllegalArgumentException e) {
+ // success
+ }
+
+ columns = new ArrayList<Column>();
+ col = new Column();
+ col.setName("A");
+ col.setType(DataType.TEXT);
+ columns.add(col);
+ db.createTable("test", columns);
+
+ try {
+ db.createTable("Test", columns);
+ fail("create duplicate tables?");
+ } catch(IllegalArgumentException e) {
+ // success
+ }
+
+ }
+
public void testReadDeletedRows() throws Exception {
Table table = Database.open(new File("test/data/delTest.mdb")).getTable("Table");
int rows = 0;
@@ -153,10 +211,33 @@ public class DatabaseTest extends TestCase {
}
public void testDeleteCurrentRow() throws Exception {
+
+ // make sure correct row is deleted
Database db = create();
createTestTable(db);
- Object[] row = createTestRow();
+ Object[] row1 = createTestRow("Tim1");
+ Object[] row2 = createTestRow("Tim2");
+ Object[] row3 = createTestRow("Tim3");
Table table = db.getTable("Test");
+ table.addRows(Arrays.asList(row1, row2, row3));
+
+ table.reset();
+ table.getNextRow();
+ table.getNextRow();
+ table.deleteCurrentRow();
+
+ table.reset();
+
+ Map<String, Object> outRow = table.getNextRow();
+ assertEquals("Tim1", outRow.get("A"));
+ outRow = table.getNextRow();
+ assertEquals("Tim3", outRow.get("A"));
+
+ // test multi row delete/add
+ db = create();
+ createTestTable(db);
+ Object[] row = createTestRow();
+ table = db.getTable("Test");
for (int i = 0; i < 10; i++) {
row[3] = i;
table.addRow(row);
@@ -445,10 +526,14 @@ public class DatabaseTest extends TestCase {
assertEquals(89, columns.size());
}
- private Object[] createTestRow() {
- return new Object[] {"Tim", "R", "McCune", 1234, (byte) 0xad, 555.66d,
+ private Object[] createTestRow(String col1Val) {
+ return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d,
777.88f, (short) 999, new Date()};
}
+
+ private Object[] createTestRow() {
+ return createTestRow("Tim");
+ }
private void createTestTable(Database db) throws Exception {
List<Column> columns = new ArrayList<Column>();
diff --git a/test/src/java/com/healthmarketscience/jackcess/TableTest.java b/test/src/java/com/healthmarketscience/jackcess/TableTest.java
index ecb02e8..29178f9 100644
--- a/test/src/java/com/healthmarketscience/jackcess/TableTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/TableTest.java
@@ -18,6 +18,7 @@ public class TableTest extends TestCase {
}
public void testCreateRow() throws Exception {
+ JetFormat format = JetFormat.VERSION_4;
Table table = new Table();
List<Column> columns = new ArrayList<Column>();
Column col = new Column();
@@ -33,7 +34,7 @@ public class TableTest extends TestCase {
row[0] = new Short((short) 9);
row[1] = "Tim";
row[2] = "McCune";
- ByteBuffer buffer = table.createRow(row);
+ ByteBuffer buffer = table.createRow(row, format.MAX_ROW_SIZE);
assertEquals((short) colCount, buffer.getShort());
assertEquals((short) 9, buffer.getShort());
assertEquals((byte) 'T', buffer.get());