Date: Friday, March 10, 2006 @ 22:21:41
Author: gilles
Path: /cvsroot/carob/carob/test/30-ResultSet
Modified: TestBigDecimal.cpp (1.5 -> 1.6) TestBigDecimal.hpp (1.2 -> 1.3)
Added testGetAsUInt64()
Added max+1 and min-1 tests for GetAsInt64 => min-1 commented because of a bug
in bigdecimal
--------------------+
TestBigDecimal.cpp | 157 +++++++++++++++++++++++++++++++++++++++++++++++----
TestBigDecimal.hpp | 5 +
2 files changed, 150 insertions(+), 12 deletions(-)
Index: carob/test/30-ResultSet/TestBigDecimal.cpp
diff -u carob/test/30-ResultSet/TestBigDecimal.cpp:1.5
carob/test/30-ResultSet/TestBigDecimal.cpp:1.6
--- carob/test/30-ResultSet/TestBigDecimal.cpp:1.5 Thu Mar 9 10:54:24 2006
+++ carob/test/30-ResultSet/TestBigDecimal.cpp Fri Mar 10 22:21:41 2006
@@ -87,6 +87,19 @@
L"UPDATE product SET cost =
-123456789012345678901234567890.123456789012345678901234567890 WHERE id=" +
toWString(id++));
statementPtr->executeUpdate(
L"UPDATE product SET cost =
123456789012345678901234567890.123456789012345678901234567890 WHERE id=" +
toWString(id++));
+
+ //MAX ULLONG
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = " +
toWString(numeric_limits<uint64_t>::max()) + L" WHERE id=" + toWString(id++));
+ // MAX ULLONG + 1 (numeric_limits<uint64_t>::max()+1)
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = 18446744073709551616 WHERE id=" +
toWString(id++));
+ //MAX LLONG +1
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = 9223372036854775808 WHERE id= " +
toWString(id++));
+ //MIN LLONG -1
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = -9223372036854775809 WHERE id= " +
toWString(id++));
}
void TestBigDecimal::testGetAsString()
@@ -148,6 +161,8 @@
CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"123456789012345678901234567890" +
fromString(localeconv()->decimal_point) + L"123456789012345678901234567890");
}
+//TODO: display as strings (when logging) in order to see where the test
crashes
+//TODO: improve log msgs
void TestBigDecimal::testGetAsInt()
{
@@ -205,37 +220,37 @@
statementPtr = connectionPtr->createStatement();
DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM
product");
drsPtr->next();
- logInfo(fctName, L"0 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, L"0 - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 0);
drsPtr->next();
- logInfo(fctName, L"-0.5 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, L"-0.5 - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 0);
drsPtr->next();
- logInfo(fctName, L"0.5 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 0);
+ logInfo(fctName, L"0.5 - getAsInt64=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 0);
drsPtr->next();
- logInfo(fctName, L"-1 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, L"-1 - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == -1);
drsPtr->next();
- logInfo(fctName, L"1 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, L"1 - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 1);
drsPtr->next();
- logInfo(fctName, L"-12.34 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, L"-12.34 - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == -12);
drsPtr->next();
- logInfo(fctName, L"12.34 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, L"12.34 - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 12);
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsInt64=" +
drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int>::min());
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsInt64=" +
drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int>::max());
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<long long>::min()) + L" -
getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, toWString(numeric_limits<long long>::min()) + L" -
getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<long long>::min());
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" -
getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" -
getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<long long>::max());
drsPtr->next();
logInfo(fctName, L"0<number<1 - getAsInt64="+drsPtr->getAsString(3));
@@ -251,7 +266,122 @@
{
logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
}
+ drsPtr->next();
+ //min double
+ drsPtr->next();
+ //max double
+ drsPtr->next();
+ //-1234etc
+ drsPtr->next();
+ //+1234etc
+ drsPtr->next();
+ //Max ULL
+ drsPtr->next();
+ //Max ULL+1
+ drsPtr->next();
+ try
+ {
+ logInfo(fctName, L"Trying getAsInt64 on max long long
+1="+drsPtr->getAsString(3));
+ drsPtr->getAsInt64(3);
+ CPPUNIT_ASSERT(false);
+ }
+ catch (ConversionException ce)
+ {
+ logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
+ }
+ drsPtr->next();
+//TODO:-max_long -1 should throw an exception !!!
+/* try
+ {
+ logInfo(fctName, L"Trying getAsInt64 on ming long long
-1="+drsPtr->getAsString(3));
+ drsPtr->getAsInt64(3);
+ CPPUNIT_ASSERT(false);
+ }
+ catch (ConversionException ce)
+ {
+ logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
+ }
+*/
+ connectionPtr->deleteStatement(statementPtr);
+}
+void TestBigDecimal::testGetAsUInt64()
+{
+ wstring fctName(L"TestBigDecimal::testGetAsUInt64");
+ Statement* statementPtr = NULL;
+ statementPtr = connectionPtr->createStatement();
+ DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM
product");
+ drsPtr->next();
+ logInfo(fctName, L"0 - getAsUInt64=" + toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) == 0);
+ drsPtr->next();
+ drsPtr->next();
+ logInfo(fctName, L"0.5 - getAsUInt64=" + toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) == 0);
+ drsPtr->next();
+ try
+ {
+ logInfo(fctName, L"Trying getAsUInt64 on a negative number");
+ drsPtr->getAsUInt64(3);
+ CPPUNIT_ASSERT(false);
+ }
+ catch (ConversionException ce)
+ {
+ logInfo(fctName, L"-1 - getAsUInt64 threw an exception - this is ok");
+ }
+ drsPtr->next();
+ logInfo(fctName, L"1 - getAsUInt64=" + toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) == 1);
+ drsPtr->next();
+ drsPtr->next();
+ logInfo(fctName, L"12.34 - getAsUInt64=" +
toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) == 12);
+ drsPtr->next();
+ drsPtr->next();
+ logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsUInt64="
+ toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) ==
static_cast<uint64_t>(numeric_limits<int>::max()));
+ drsPtr->next();
+ drsPtr->next();
+ logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" -
getAsUInt64=" + toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) ==
static_cast<uint64_t>(numeric_limits<long long>::max()));
+ drsPtr->next();
+ //min float
+ logInfo(fctName, L"0<number<1 - getAsUInt64=" +
toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) == 0);
+ drsPtr->next();
+ //max float
+ try
+ {
+ logInfo(fctName, L"Trying getAsUInt64 on a too big number");
+ drsPtr->getAsUInt64(3);
+ CPPUNIT_ASSERT(false);
+ }
+ catch (ConversionException ce)
+ {
+ logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
+ }
+ drsPtr->next();
+ //min double
+ drsPtr->next();
+ //max double
+ drsPtr->next();
+ //-1234etc
+ drsPtr->next();
+ //+1234etc
+ drsPtr->next();
+ logInfo(fctName, L"Max unsigned long long - getAsUInt64=" +
drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) == numeric_limits<uint64_t>::max());
+ drsPtr->next();
+ try
+ {
+ logInfo(fctName, L"Trying getAsUInt64 on Max unsigned long long +1");
+ drsPtr->getAsUInt64(3);
+ CPPUNIT_ASSERT(false);
+ }
+ catch (ConversionException ce)
+ {
+ logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
+ }
connectionPtr->deleteStatement(statementPtr);
}
@@ -354,6 +484,9 @@
"TestBigDecimal::testGetAsInt64",
&TestBigDecimal::testGetAsInt64));
suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
+ "TestBigDecimal::testGetAsUInt64",
+ &TestBigDecimal::testGetAsUInt64));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
"TestBigDecimal::testGetAsFloat",
&TestBigDecimal::testGetAsFloat));
suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
Index: carob/test/30-ResultSet/TestBigDecimal.hpp
diff -u carob/test/30-ResultSet/TestBigDecimal.hpp:1.2
carob/test/30-ResultSet/TestBigDecimal.hpp:1.3
--- carob/test/30-ResultSet/TestBigDecimal.hpp:1.2 Thu Mar 9 10:47:36 2006
+++ carob/test/30-ResultSet/TestBigDecimal.hpp Fri Mar 10 22:21:41 2006
@@ -57,6 +57,11 @@
*/
void testGetAsInt64();
/**
+ * Read big decimal values using getAsUInt64() and checks that the unsigned
+ * long long read is the expected one
+ */
+ void testGetAsUInt64();
+ /**
* Read big decimal values using getAsFloat() and checks that the double read
* is the expected one
*/
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits