Date: Friday, March 3, 2006 @ 18:21:26
Author: gilles
Path: /cvsroot/carob/carob/test
Added: 30-ResultSet/TestBigDecimal.cpp (1.1)
30-ResultSet/TestBigDecimal.hpp (1.1)
Modified: CarobTestLauncher.cpp (1.28 -> 1.29)
Added tests on BigDecimal to string conversion
Prepared (commented) tests for to int and to long conversions
---------------------------------+
30-ResultSet/TestBigDecimal.cpp | 194 ++++++++++++++++++++++++++++++++++++++
30-ResultSet/TestBigDecimal.hpp | 61 +++++++++++
CarobTestLauncher.cpp | 2
3 files changed, 257 insertions(+)
Index: carob/test/30-ResultSet/TestBigDecimal.cpp
diff -u /dev/null carob/test/30-ResultSet/TestBigDecimal.cpp:1.1
--- /dev/null Fri Mar 3 18:21:26 2006
+++ carob/test/30-ResultSet/TestBigDecimal.cpp Fri Mar 3 18:21:26 2006
@@ -0,0 +1,194 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Gilles Rayrat
+ * Contributor(s):
+ */
+
+#include "TestBigDecimal.hpp"
+
+#include "Statement.hpp"
+#include "DriverResultSet.hpp"
+
+#include "CarobException.hpp"
+#include "Common.hpp"
+
+#include <values.h>
+#include <string>
+#include <iostream>
+
+using std::wstring;
+using std::endl;
+
+using namespace CarobNS;
+
+void TestBigDecimal::setUp()
+{
+ //1st create connection & stuff
+ ConnectionSetup::setUp();
+
+ // write some bigdecimals in a products table
+ Statement* statementPtr = NULL;
+ statementPtr = connectionPtr->createStatement();
+ int id = 0;
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = 0 WHERE id=" + toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = 1 WHERE id=" + toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = -1 WHERE id=" + toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = " + toWString(MININT) + L" WHERE id=" +
toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = " + toWString(MAXINT) + L" WHERE id=" +
toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = " + toWString(MINLONG) + L" WHERE id=" +
toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = " + toWString(MAXLONG) + L" WHERE id= " +
toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = 12345678901234567890.12345678901234567890
WHERE id=" + toWString(id++));
+ statementPtr->executeUpdate(
+ L"UPDATE product SET cost = -12345678901234567890.12345678901234567890
WHERE id=" + toWString(id++));
+}
+
+void TestBigDecimal::testGetAsString()
+{
+ wstring fctName(L"TestBigDecimal::testGetAsString");
+ Statement* statementPtr = NULL;
+ statementPtr = connectionPtr->createStatement();
+ DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM
product");
+ drsPtr->next();
+ logInfo(fctName, L"0 - getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"0");
+ drsPtr->next();
+ logInfo(fctName, L"1 - getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"1");
+ drsPtr->next();
+ logInfo(fctName, L"-1 - getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"-1");
+ drsPtr->next();
+ logInfo(fctName, toWString(MININT) + L" - getAsString=" +
drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MININT));
+ drsPtr->next();
+ logInfo(fctName, toWString(MAXINT) + L" - getAsString=" +
drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MAXINT));
+ drsPtr->next();
+ logInfo(fctName, toWString(MINLONG) + L" - getAsString=" +
drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MINLONG));
+ drsPtr->next();
+ logInfo(fctName, toWString(MAXLONG) + L" - getAsString=" +
drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(MAXLONG));
+ drsPtr->next();
+ logInfo(fctName, L"12345678901234567890.12345678901234567890 - getAsString="
+ drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) ==
L"12345678901234567890.12345678901234567890");
+ drsPtr->next();
+ logInfo(fctName, L"-12345678901234567890.12345678901234567890 -
getAsString=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3) ==
L"-12345678901234567890.12345678901234567890");
+
+ connectionPtr->deleteStatement(statementPtr);
+}
+
+void TestBigDecimal::testGetAsInt()
+{
+ wstring fctName(L"TestBigDecimal::testGetAsInt");
+ Statement* statementPtr = NULL;
+ statementPtr = connectionPtr->createStatement();
+ DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM
product");
+ drsPtr->next();
+ logInfo(fctName, L"0 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 0);
+ drsPtr->next();
+ logInfo(fctName, L"1 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 1);
+ drsPtr->next();
+ logInfo(fctName, L"-1 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == -1);
+ drsPtr->next();
+ logInfo(fctName, toWString(MININT) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MININT);
+ drsPtr->next();
+ logInfo(fctName, toWString(MAXINT) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MAXINT);
+ drsPtr->next();
+ logInfo(fctName, toWString(MINLONG) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
+//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MINLONG);
+ drsPtr->next();
+ logInfo(fctName, toWString(MAXLONG) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
+//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == MAXLONG);
+ drsPtr->next();
+ logInfo(fctName, L"12345678901234567890.12345678901234567890 - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
+//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == -6101065172474983726);
+ drsPtr->next();
+ logInfo(fctName, L"-12345678901234567890.12345678901234567890 - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
+//TODO CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 6101065172474983726);
+
+ connectionPtr->deleteStatement(statementPtr);
+}
+
+void TestBigDecimal::testGetAsInt64()
+{
+ wstring fctName(L"TestBigDecimal::testGetAsInt64");
+ Statement* statementPtr = NULL;
+ statementPtr = connectionPtr->createStatement();
+ DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM
product");
+ drsPtr->next();
+ logInfo(fctName, L"0 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 0);
+ drsPtr->next();
+ logInfo(fctName, L"1 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 1);
+ drsPtr->next();
+ logInfo(fctName, L"-1 - getAsInt64=" + toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == -1);
+ drsPtr->next();
+ logInfo(fctName, toWString(MININT) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MININT);
+ drsPtr->next();
+ logInfo(fctName, toWString(MAXINT) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MAXINT);
+ drsPtr->next();
+ logInfo(fctName, toWString(MINLONG) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MINLONG);
+ drsPtr->next();
+ logInfo(fctName, toWString(MAXLONG) + L" - getAsInt64=" +
toWString(drsPtr->getAsInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == MAXLONG);
+ drsPtr->next();
+ logInfo(fctName, L"12345678901234567890.12345678901234567890 - getAsInt64="
+ toWString(drsPtr->getAsInt64(3)));
+// CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == -6101065172474983726);
+ drsPtr->next();
+ logInfo(fctName, L"-12345678901234567890.12345678901234567890 - getAsInt64="
+ toWString(drsPtr->getAsInt64(3)));
+// CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 6101065172474983726);
+
+ connectionPtr->deleteStatement(statementPtr);
+}
+
+CppUnit::Test* TestBigDecimal::suite()
+{
+ CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "TestBigDecimal"
);
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
+ "TestBigDecimal::testGetAsString",
+ &TestBigDecimal::testGetAsString));
+/* suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
+ "TestBigDecimal::testgetAsInt",
+ &TestBigDecimal::testGetAsInt));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestBigDecimal>(
+ "TestBigDecimal::testgetAsInt64",
+ &TestBigDecimal::testGetAsInt64));
+*/
+ return suiteOfTests;
+}
+
Index: carob/test/30-ResultSet/TestBigDecimal.hpp
diff -u /dev/null carob/test/30-ResultSet/TestBigDecimal.hpp:1.1
--- /dev/null Fri Mar 3 18:21:26 2006
+++ carob/test/30-ResultSet/TestBigDecimal.hpp Fri Mar 3 18:21:26 2006
@@ -0,0 +1,61 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Gilles Rayrat
+ * Contributor(s):
+ */
+
+#ifndef TESTBIGDECIMAL_H_
+#define TESTBIGDECIMAL_H_
+
+#include "../ConnectionSetup.hpp"
+
+/**
+ * Test class for Statement class.
+ * This is basically a copy of exec read and exec write commands testing
+ * A controller *MUST* run locally for test success !!!
+ */
+class TestBigDecimal : public ConnectionSetup
+{
+public:
+ /** Suite of tests to be run */
+ static CppUnit::Test* suite();
+
+ /**
+ * After calling ConnectionSetup::setUp(), writes a bunch of big decimal
+ * values in a table that will be read by all tests
+ */
+ virtual void setUp();
+
+ /**
+ * Read big decimal values using getAsString(), then checks the read and
+ * written values are consistent
+ */
+ void testGetAsString();
+ /**
+ * Read big decimal values using getAsInt() and checks that the integer read
+ * is the expected one
+ */
+ void testGetAsInt();
+ /**
+ * Read big decimal values using getAsInt64() and checks that the long read
+ * is the expected one
+ */
+ void testGetAsInt64();
+};
+
+#endif /*TESTBIGDECIMAL_H_*/
Index: carob/test/CarobTestLauncher.cpp
diff -u carob/test/CarobTestLauncher.cpp:1.28
carob/test/CarobTestLauncher.cpp:1.29
--- carob/test/CarobTestLauncher.cpp:1.28 Fri Mar 3 16:48:23 2006
+++ carob/test/CarobTestLauncher.cpp Fri Mar 3 18:21:26 2006
@@ -47,6 +47,7 @@
#include "30-ResultSet/TestSimpleUnicode.hpp"
#include "30-ResultSet/TestExecReadRequest.hpp"
#include "30-ResultSet/TestDriverResultSet.hpp"
+#include "30-ResultSet/TestBigDecimal.hpp"
#include "35-ResultList/TestExec.hpp"
#include "40-Parameter-PreparedStatement/TestParameterStatement.hpp"
#include "40-Parameter-PreparedStatement/TestPreparedStatement.hpp"
@@ -75,6 +76,7 @@
runner.addTest(TestExecReadRequest::suite());
runner.addTest(TestExec::suite());
runner.addTest(TestBeginCommitRollback::suite());
+ runner.addTest(TestBigDecimal::suite());
runner.addTest(TestDriverResultSet::suite());
runner.addTest(TestStringCodecs::suite());
runner.addTest(TestSimpleUnicode::suite());
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits