Search in sources :

Example 1 with TestValue

use of org.h2.test.unit.TestValue in project h2database by h2database.

the class TestDataPage method testValues.

private void testValues() {
    testValue(ValueNull.INSTANCE);
    testValue(ValueBoolean.FALSE);
    testValue(ValueBoolean.TRUE);
    for (int i = 0; i < 256; i++) {
        testValue(ValueByte.get((byte) i));
    }
    for (int i = 0; i < 256 * 256; i += 10) {
        testValue(ValueShort.get((short) i));
    }
    for (int i = 0; i < 256 * 256; i += 10) {
        testValue(ValueInt.get(i));
        testValue(ValueInt.get(-i));
        testValue(ValueLong.get(i));
        testValue(ValueLong.get(-i));
    }
    testValue(ValueInt.get(Integer.MAX_VALUE));
    testValue(ValueInt.get(Integer.MIN_VALUE));
    for (long i = 0; i < Integer.MAX_VALUE; i += 10 + i / 4) {
        testValue(ValueInt.get((int) i));
        testValue(ValueInt.get((int) -i));
    }
    testValue(ValueLong.get(Long.MAX_VALUE));
    testValue(ValueLong.get(Long.MIN_VALUE));
    for (long i = 0; i >= 0; i += 10 + i / 4) {
        testValue(ValueLong.get(i));
        testValue(ValueLong.get(-i));
    }
    testValue(ValueDecimal.get(BigDecimal.ZERO));
    testValue(ValueDecimal.get(BigDecimal.ONE));
    testValue(ValueDecimal.get(BigDecimal.TEN));
    testValue(ValueDecimal.get(BigDecimal.ONE.negate()));
    testValue(ValueDecimal.get(BigDecimal.TEN.negate()));
    for (long i = 0; i >= 0; i += 10 + i / 4) {
        testValue(ValueDecimal.get(new BigDecimal(i)));
        testValue(ValueDecimal.get(new BigDecimal(-i)));
        for (int j = 0; j < 200; j += 50) {
            testValue(ValueDecimal.get(new BigDecimal(i).setScale(j)));
            testValue(ValueDecimal.get(new BigDecimal(i * i).setScale(j)));
        }
        testValue(ValueDecimal.get(new BigDecimal(i * i)));
    }
    testValue(ValueDate.get(new Date(System.currentTimeMillis())));
    testValue(ValueDate.get(new Date(0)));
    testValue(ValueTime.get(new Time(System.currentTimeMillis())));
    testValue(ValueTime.get(new Time(0)));
    testValue(ValueTimestamp.fromMillis(System.currentTimeMillis()));
    testValue(ValueTimestamp.fromMillis(0));
    testValue(ValueTimestampTimeZone.parse("2000-01-01 10:00:00"));
    testValue(ValueJavaObject.getNoCopy(null, new byte[0], this));
    testValue(ValueJavaObject.getNoCopy(null, new byte[100], this));
    for (int i = 0; i < 300; i++) {
        testValue(ValueBytes.getNoCopy(new byte[i]));
    }
    for (int i = 0; i < 65000; i += 10 + i) {
        testValue(ValueBytes.getNoCopy(new byte[i]));
    }
    testValue(ValueUuid.getNewRandom());
    for (int i = 0; i < 100; i++) {
        testValue(ValueString.get(new String(new char[i])));
    }
    for (int i = 0; i < 65000; i += 10 + i) {
        testValue(ValueString.get(new String(new char[i])));
        testValue(ValueStringFixed.get(new String(new char[i])));
        testValue(ValueStringIgnoreCase.get(new String(new char[i])));
    }
    testValue(ValueFloat.get(0f));
    testValue(ValueFloat.get(1f));
    testValue(ValueFloat.get(-1f));
    testValue(ValueDouble.get(0));
    testValue(ValueDouble.get(1));
    testValue(ValueDouble.get(-1));
    for (int i = 0; i < 65000; i += 10 + i) {
        for (double j = 0.1; j < 65000; j += 10 + j) {
            testValue(ValueFloat.get((float) (i / j)));
            testValue(ValueDouble.get(i / j));
            testValue(ValueFloat.get((float) -(i / j)));
            testValue(ValueDouble.get(-(i / j)));
        }
    }
    testValue(ValueArray.get(new Value[0]));
    testValue(ValueArray.get(new Value[] { ValueBoolean.TRUE, ValueInt.get(10) }));
    SimpleResultSet rs = new SimpleResultSet();
    rs.setAutoClose(false);
    rs.addColumn("ID", Types.INTEGER, 0, 0);
    rs.addColumn("NAME", Types.VARCHAR, 255, 0);
    rs.addRow(1, "Hello");
    rs.addRow(2, "World");
    rs.addRow(3, "Peace");
    testValue(ValueResultSet.get(rs));
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) Value(org.h2.value.Value) Time(java.sql.Time) ValueTime(org.h2.value.ValueTime) ValueString(org.h2.value.ValueString) BigDecimal(java.math.BigDecimal) ValueDate(org.h2.value.ValueDate) Date(java.sql.Date)

Example 2 with TestValue

use of org.h2.test.unit.TestValue in project h2database by h2database.

the class TestDataPage method testValue.

private void testValue(Value v) {
    Data data = Data.create(null, 1024);
    data.checkCapacity((int) v.getPrecision());
    data.writeValue(v);
    data.writeInt(123);
    data.reset();
    Value v2 = data.readValue();
    assertEquals(v.getType(), v2.getType());
    assertEquals(0, v.compareTo(v2, compareMode));
    assertEquals(123, data.readInt());
}
Also used : Value(org.h2.value.Value) Data(org.h2.store.Data)

Example 3 with TestValue

use of org.h2.test.unit.TestValue in project h2database by h2database.

the class TestAll method testUnit.

private void testUnit() {
    // mv store
    addTest(new TestCacheConcurrentLIRS());
    addTest(new TestCacheLIRS());
    addTest(new TestCacheLongKeyLIRS());
    addTest(new TestConcurrentLinkedList());
    addTest(new TestDataUtils());
    addTest(new TestFreeSpace());
    addTest(new TestKillProcessWhileWriting());
    addTest(new TestMVRTree());
    addTest(new TestMVStore());
    addTest(new TestMVStoreBenchmark());
    addTest(new TestMVStoreStopCompact());
    addTest(new TestMVStoreTool());
    addTest(new TestMVTableEngine());
    addTest(new TestObjectDataType());
    addTest(new TestRandomMapOps());
    addTest(new TestSpinLock());
    addTest(new TestStreamStore());
    addTest(new TestTransactionStore());
    // unit
    addTest(new TestAnsCompression());
    addTest(new TestAutoReconnect());
    addTest(new TestBinaryArithmeticStream());
    addTest(new TestBitStream());
    addTest(new TestBnf());
    addTest(new TestCache());
    addTest(new TestCharsetCollator());
    addTest(new TestClearReferences());
    addTest(new TestCollation());
    addTest(new TestCompress());
    addTest(new TestConnectionInfo());
    addTest(new TestDataPage());
    addTest(new TestDateIso8601());
    addTest(new TestExit());
    addTest(new TestFile());
    addTest(new TestFileLock());
    addTest(new TestFtp());
    addTest(new TestIntArray());
    addTest(new TestIntIntHashMap());
    addTest(new TestIntPerfectHash());
    addTest(new TestJmx());
    addTest(new TestMathUtils());
    addTest(new TestMode());
    addTest(new TestModifyOnWrite());
    addTest(new TestOldVersion());
    addTest(new TestObjectDeserialization());
    addTest(new TestMultiThreadedKernel());
    addTest(new TestOverflow());
    addTest(new TestPageStore());
    addTest(new TestPageStoreCoverage());
    addTest(new TestPerfectHash());
    addTest(new TestPgServer());
    addTest(new TestReader());
    addTest(new TestRecovery());
    addTest(new TestScriptReader());
    addTest(new RecoverLobTest());
    addTest(createTest("org.h2.test.unit.TestServlet"));
    addTest(new TestSecurity());
    addTest(new TestShell());
    addTest(new TestSort());
    addTest(new TestStreams());
    addTest(new TestStringUtils());
    addTest(new TestTimeStampWithTimeZone());
    addTest(new TestTraceSystem());
    addTest(new TestUpgrade());
    addTest(new TestUsingIndex());
    addTest(new TestUtils());
    addTest(new TestValue());
    addTest(new TestValueHashMap());
    addTest(new TestWeb());
    runAddedTests();
    // serial
    addTest(new TestDate());
    addTest(new TestDateTimeUtils());
    addTest(new TestCluster());
    addTest(new TestConcurrent());
    addTest(new TestFileLockSerialized());
    addTest(new TestFileLockProcess());
    addTest(new TestFileSystem());
    addTest(new TestNetUtils());
    addTest(new TestPattern());
    addTest(new TestTools());
    addTest(new TestSampleApps());
    addTest(new TestStringCache());
    addTest(new TestValueMemory());
    runAddedTests(1);
}
Also used : TestPageStoreCoverage(org.h2.test.unit.TestPageStoreCoverage) TestDateIso8601(org.h2.test.unit.TestDateIso8601) RecoverLobTest(org.h2.test.recover.RecoverLobTest) TestMVTableEngine(org.h2.test.store.TestMVTableEngine) TestPgServer(org.h2.test.unit.TestPgServer) TestValueMemory(org.h2.test.unit.TestValueMemory) TestKillProcessWhileWriting(org.h2.test.store.TestKillProcessWhileWriting) TestExit(org.h2.test.unit.TestExit) TestMode(org.h2.test.unit.TestMode) TestPageStore(org.h2.test.unit.TestPageStore) TestSort(org.h2.test.unit.TestSort) TestUtils(org.h2.test.unit.TestUtils) TestOldVersion(org.h2.test.unit.TestOldVersion) TestObjectDeserialization(org.h2.test.unit.TestObjectDeserialization) TestCompress(org.h2.test.unit.TestCompress) TestCluster(org.h2.test.db.TestCluster) TestCharsetCollator(org.h2.test.unit.TestCharsetCollator) TestFileLockSerialized(org.h2.test.unit.TestFileLockSerialized) TestMVStoreBenchmark(org.h2.test.store.TestMVStoreBenchmark) TestFileLock(org.h2.test.unit.TestFileLock) TestIntArray(org.h2.test.unit.TestIntArray) TestCacheLongKeyLIRS(org.h2.test.store.TestCacheLongKeyLIRS) TestOverflow(org.h2.test.unit.TestOverflow) TestModifyOnWrite(org.h2.test.unit.TestModifyOnWrite) TestPattern(org.h2.test.unit.TestPattern) TestValueHashMap(org.h2.test.unit.TestValueHashMap) TestReader(org.h2.test.unit.TestReader) TestNetUtils(org.h2.test.unit.TestNetUtils) TestObjectDataType(org.h2.test.store.TestObjectDataType) TestDataPage(org.h2.test.unit.TestDataPage) TestWeb(org.h2.test.server.TestWeb) TestTraceSystem(org.h2.test.unit.TestTraceSystem) TestClearReferences(org.h2.test.unit.TestClearReferences) TestUpgrade(org.h2.test.db.TestUpgrade) TestStreamStore(org.h2.test.store.TestStreamStore) TestTransactionStore(org.h2.test.store.TestTransactionStore) TestConnectionInfo(org.h2.test.unit.TestConnectionInfo) TestTools(org.h2.test.unit.TestTools) TestStreams(org.h2.test.unit.TestStreams) TestFile(org.h2.test.unit.TestFile) TestSampleApps(org.h2.test.unit.TestSampleApps) TestCacheConcurrentLIRS(org.h2.test.store.TestCacheConcurrentLIRS) TestConcurrent(org.h2.test.store.TestConcurrent) TestFtp(org.h2.test.unit.TestFtp) TestStringUtils(org.h2.test.unit.TestStringUtils) TestSpinLock(org.h2.test.store.TestSpinLock) TestDataUtils(org.h2.test.store.TestDataUtils) TestUsingIndex(org.h2.test.db.TestUsingIndex) TestRandomMapOps(org.h2.test.store.TestRandomMapOps) TestValue(org.h2.test.unit.TestValue) TestIntPerfectHash(org.h2.test.unit.TestIntPerfectHash) TestMVStore(org.h2.test.store.TestMVStore) TestMathUtils(org.h2.test.unit.TestMathUtils) TestRecovery(org.h2.test.unit.TestRecovery) TestTimeStampWithTimeZone(org.h2.test.unit.TestTimeStampWithTimeZone) TestFileLockProcess(org.h2.test.unit.TestFileLockProcess) TestMultiThreadedKernel(org.h2.test.db.TestMultiThreadedKernel) TestFreeSpace(org.h2.test.store.TestFreeSpace) TestDateTimeUtils(org.h2.test.unit.TestDateTimeUtils) TestMVRTree(org.h2.test.store.TestMVRTree) TestSecurity(org.h2.test.unit.TestSecurity) TestMVStoreTool(org.h2.test.store.TestMVStoreTool) TestIntIntHashMap(org.h2.test.unit.TestIntIntHashMap) TestBnf(org.h2.test.unit.TestBnf) TestCacheLIRS(org.h2.test.store.TestCacheLIRS) TestAutoReconnect(org.h2.test.unit.TestAutoReconnect) TestBinaryArithmeticStream(org.h2.test.unit.TestBinaryArithmeticStream) TestCollation(org.h2.test.unit.TestCollation) TestJmx(org.h2.test.unit.TestJmx) TestPerfectHash(org.h2.test.unit.TestPerfectHash) TestAnsCompression(org.h2.test.unit.TestAnsCompression) TestShell(org.h2.test.unit.TestShell) TestStringCache(org.h2.test.unit.TestStringCache) TestConcurrentLinkedList(org.h2.test.store.TestConcurrentLinkedList) TestCache(org.h2.test.unit.TestCache) TestDate(org.h2.test.unit.TestDate) TestMVStoreStopCompact(org.h2.test.store.TestMVStoreStopCompact) TestBitStream(org.h2.test.unit.TestBitStream) TestScriptReader(org.h2.test.unit.TestScriptReader) TestFileSystem(org.h2.test.unit.TestFileSystem)

Example 4 with TestValue

use of org.h2.test.unit.TestValue in project h2database by h2database.

the class TestFunctions method testValue.

private void testValue() throws SQLException {
    Connection conn = getConnection("functions");
    Statement stat = conn.createStatement();
    ResultSet rs;
    stat.execute("create alias TO_CHAR_2 for \"" + getClass().getName() + ".toChar\"");
    rs = stat.executeQuery("call TO_CHAR_2(TIMESTAMP '2001-02-03 04:05:06', 'format')");
    rs.next();
    assertEquals("2001-02-03 04:05:06", rs.getString(1));
    stat.execute("drop alias TO_CHAR_2");
    conn.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) CallableStatement(java.sql.CallableStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SimpleResultSet(org.h2.tools.SimpleResultSet)

Aggregations

SimpleResultSet (org.h2.tools.SimpleResultSet)2 Value (org.h2.value.Value)2 BigDecimal (java.math.BigDecimal)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 Date (java.sql.Date)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Time (java.sql.Time)1 Data (org.h2.store.Data)1 TestCluster (org.h2.test.db.TestCluster)1 TestMultiThreadedKernel (org.h2.test.db.TestMultiThreadedKernel)1 TestUpgrade (org.h2.test.db.TestUpgrade)1 TestUsingIndex (org.h2.test.db.TestUsingIndex)1 RecoverLobTest (org.h2.test.recover.RecoverLobTest)1 TestWeb (org.h2.test.server.TestWeb)1 TestCacheConcurrentLIRS (org.h2.test.store.TestCacheConcurrentLIRS)1 TestCacheLIRS (org.h2.test.store.TestCacheLIRS)1 TestCacheLongKeyLIRS (org.h2.test.store.TestCacheLongKeyLIRS)1