Date: Wednesday, March 22, 2006 @ 19:24:41
  Author: gilles
    Path: /cvsroot/carob/carob/test/40-Parameter-PreparedStatement

Modified: TestParameterStatement.cpp (1.9 -> 1.10)
          TestParameterStatement.hpp (1.4 -> 1.5)

Added testBigDecimal that writes and re-read special big decimal values to the 
DB
This also tests big decimal contructors


----------------------------+
 TestParameterStatement.cpp |   68 ++++++++++++++++++++++++++++++++++++++-----
 TestParameterStatement.hpp |    2 +
 2 files changed, 63 insertions(+), 7 deletions(-)


Index: carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp
diff -u 
carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp:1.9 
carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp:1.10
--- carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp:1.9    
Fri Mar  3 16:54:13 2006
+++ carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp        
Wed Mar 22 19:24:41 2006
@@ -19,19 +19,24 @@
  * Contributor(s): Marc Herbert
  */
 
-#include <iostream>
-
-#include "Common.hpp"
-#include "Connection.hpp"
-#include "CarobException.hpp"
-#include "DriverResultSet.hpp"
 #include "TestParameterStatement.hpp"
-#include "RequestWithResultSetParameters.hpp"
+
 #include "ResultSetMetaData.hpp"
+#include "RequestWithResultSetParameters.hpp"
+#include "BigDecimal.hpp"
 #include "ParameterStatement.hpp"
+#include "DriverResultSet.hpp"
+
+#include "Connection.hpp"
+#include "CarobException.hpp"
+#include "Common.hpp"
+
+#include <iostream>
+#include <limits>
 
 using std::wstring;
 using std::endl;
+using std::numeric_limits;
 
 using namespace CarobNS;
 
@@ -265,6 +270,52 @@
   CPPUNIT_ASSERT(teststring == drs->getString(1)); // FIXME: replace by 
getBoolean()
 }
 
+void TestParameterStatement::testBigDecimal()
+{
+  const std::wstring TABLE_TYPE(L"(bd DECIMAL(128))");
+  const std::wstring TABLE_NAME(L"bigdecimaltest");
+
+  wstring fctName(L"TestParameterStatement::testBigDecimal");
+  
+  createOrReplaceTable(connectionPtr, TABLE_NAME, TABLE_TYPE);
+
+  ParameterStatement* pstmt = connectionPtr->
+    createParameterStatement(wstring(L"INSERT into ") + TABLE_NAME + L" values 
(?)");
+
+  BigDecimal testVals[50];
+  int nbTestVals = 0;
+  testVals[nbTestVals++] = BigDecimal(L"-123,456");
+  testVals[nbTestVals++] = BigDecimal(L"123,456");
+  testVals[nbTestVals++] = BigDecimal(-123456789);
+  testVals[nbTestVals++] = BigDecimal(123456789);
+  testVals[nbTestVals++] = BigDecimal(-123456789L);
+  testVals[nbTestVals++] = BigDecimal(123456789L);
+  testVals[nbTestVals++] = BigDecimal(-123456789LL);
+  testVals[nbTestVals++] = BigDecimal(123456789LL);
+  testVals[nbTestVals++] = BigDecimal(numeric_limits<int>::min());
+  testVals[nbTestVals++] = BigDecimal(numeric_limits<int>::max());
+  testVals[nbTestVals++] = BigDecimal(numeric_limits<long>::min());
+  testVals[nbTestVals++] = BigDecimal(numeric_limits<long>::max());
+  testVals[nbTestVals++] = BigDecimal(numeric_limits<long long>::min());
+  testVals[nbTestVals++] = BigDecimal(numeric_limits<long long>::max());
+
+  for (int i=0; i<nbTestVals; i++)
+  {
+    logDebug(fctName, L"setting value " + static_cast<wstring>(testVals[i]));
+    pstmt->setBigDecimal(1, testVals[i]);
+    int uc = pstmt->executeUpdate();
+    CPPUNIT_ASSERT(uc == 1);
+  }
+  Statement* stmt = connectionPtr-> createStatement();
+
+  DriverResultSet * drs = stmt->executeQuery(std::wstring(L"SELECT * from ") + 
TABLE_NAME);
+  for (int i=0; i<nbTestVals; i++)
+  {
+    CPPUNIT_ASSERT(drs->next());
+    logDebug(fctName, L"testing with value " + 
static_cast<wstring>(testVals[i]));
+    CPPUNIT_ASSERT(drs->getBigDecimal(1) == testVals[i]);
+  }
+}
 
 CppUnit::Test* TestParameterStatement::suite()
 {
@@ -293,6 +344,9 @@
   suiteOfTests->addTest(new CppUnit::TestCaller<TestParameterStatement>(
                                  "TestParameterStatement::testStrings",
                                  &TestParameterStatement::testStrings));
+  suiteOfTests->addTest(new CppUnit::TestCaller<TestParameterStatement>(
+                                 "TestParameterStatement::testBigDecimal",
+                                 &TestParameterStatement::testBigDecimal));
 
   return suiteOfTests;
 }
Index: carob/test/40-Parameter-PreparedStatement/TestParameterStatement.hpp
diff -u 
carob/test/40-Parameter-PreparedStatement/TestParameterStatement.hpp:1.4 
carob/test/40-Parameter-PreparedStatement/TestParameterStatement.hpp:1.5
--- carob/test/40-Parameter-PreparedStatement/TestParameterStatement.hpp:1.4    
Mon Feb 27 17:13:36 2006
+++ carob/test/40-Parameter-PreparedStatement/TestParameterStatement.hpp        
Wed Mar 22 19:24:41 2006
@@ -75,6 +75,8 @@
   void testBoolean();
 
   void testStrings();
+
+  void testBigDecimal();
 };
 
 #endif /*TESTPARAMETERSTATEMENT_H_*/

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to