diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2006-09-23 18:45:11 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2006-09-23 18:45:11 +0000 |
commit | 23423a0a369af9187e74615f09299c39fd337e60 (patch) | |
tree | f47a43153de355342269a4482012b56522cf14a1 /test/src | |
parent | 78c26cb7fe9a4e20b7e6dfca3e375a3c0c927134 (diff) | |
download | jackcess-23423a0a369af9187e74615f09299c39fd337e60.tar.gz jackcess-23423a0a369af9187e74615f09299c39fd337e60.zip |
fix ordering of byte code comparator
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@120 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/IndexTest.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java new file mode 100644 index 0000000..0adeb10 --- /dev/null +++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java @@ -0,0 +1,96 @@ +// Copyright (c) 2006 Health Market Science, Inc. + +package com.healthmarketscience.jackcess; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +import junit.framework.TestCase; + +import static com.healthmarketscience.jackcess.DatabaseTest.*; + +/** + * @author James Ahlborn + */ +public class IndexTest extends TestCase { + + /** + * Creates a new <code>IndexTest</code> instance. + * + */ + public IndexTest(String name) { + super(name); + } + + public void testByteOrder() throws Exception { + byte b1 = (byte)0x00; + byte b2 = (byte)0x01; + byte b3 = (byte)0x7F; + byte b4 = (byte)0x80; + byte b5 = (byte)0xFF; + + assertTrue(ByteUtil.toUnsignedInt(b1) < ByteUtil.toUnsignedInt(b2)); + assertTrue(ByteUtil.toUnsignedInt(b2) < ByteUtil.toUnsignedInt(b3)); + assertTrue(ByteUtil.toUnsignedInt(b3) < ByteUtil.toUnsignedInt(b4)); + assertTrue(ByteUtil.toUnsignedInt(b4) < ByteUtil.toUnsignedInt(b5)); + } + + public void testByteCodeComparator() { + // FIXME, writeme + byte[] b0 = null; + byte[] b1 = new byte[]{(byte)0x00}; + byte[] b2 = new byte[]{(byte)0x00, (byte)0x00}; + byte[] b3 = new byte[]{(byte)0x00, (byte)0x01}; + byte[] b4 = new byte[]{(byte)0x01}; + byte[] b5 = new byte[]{(byte)0x80}; + byte[] b6 = new byte[]{(byte)0xFF}; + byte[] b7 = new byte[]{(byte)0xFF, (byte)0x00}; + byte[] b8 = new byte[]{(byte)0xFF, (byte)0x01}; + + List<byte[]> expectedList = Arrays.<byte[]>asList(b0, b1, b2, b3, b4, + b5, b6, b7, b8); + SortedSet<byte[]> sortedSet = new TreeSet<byte[]>( + Index.BYTE_CODE_COMPARATOR); + sortedSet.addAll(expectedList); + assertEquals(expectedList, new ArrayList<byte[]>(sortedSet)); + + } + + public void testPrimaryKey() throws Exception { + Table table = open().getTable("Table1"); + Map<String, Boolean> foundPKs = new HashMap<String, Boolean>(); + for(Index index : table.getIndexes()) { + foundPKs.put(index.getColumns().iterator().next().getName(), + index.isPrimaryKey()); + } + Map<String, Boolean> expectedPKs = new HashMap<String, Boolean>(); + expectedPKs.put("A", Boolean.TRUE); + expectedPKs.put("B", Boolean.FALSE); + assertEquals(expectedPKs, foundPKs); + } + + public void testIndexSlots() throws Exception + { + Database mdb = Database.open(new File("test/data/indexTest.mdb")); + + Table table = mdb.getTable("Table1"); + assertEquals(4, table.getIndexes().size()); + assertEquals(4, table.getIndexSlotCount()); + + table = mdb.getTable("Table2"); + assertEquals(2, table.getIndexes().size()); + assertEquals(3, table.getIndexSlotCount()); + + table = mdb.getTable("Table3"); + assertEquals(2, table.getIndexes().size()); + assertEquals(3, table.getIndexSlotCount()); + } + + +} |