Date: Thursday, December 15, 2005 @ 12:29:56
  Author: gilles
    Path: /cvsroot/carob/carob/test

   Added: TestDriverResultSet.cpp (1.1) TestDriverResultSet.hpp (1.1)
Modified: CarobTestLauncher.cpp (1.9 -> 1.10)

Added tests on DriverResultSet class.
For now, tests getInt[32] and getString functions


-------------------------+
 CarobTestLauncher.cpp   |    2 
 TestDriverResultSet.cpp |  153 ++++++++++++++++++++++++++++++++++++++++++++++
 TestDriverResultSet.hpp |   50 +++++++++++++++
 3 files changed, 205 insertions(+)


Index: carob/test/CarobTestLauncher.cpp
diff -u carob/test/CarobTestLauncher.cpp:1.9 
carob/test/CarobTestLauncher.cpp:1.10
--- carob/test/CarobTestLauncher.cpp:1.9        Tue Dec  6 17:52:59 2005
+++ carob/test/CarobTestLauncher.cpp    Thu Dec 15 12:29:56 2005
@@ -32,6 +32,7 @@
 
 #include "TestBeginCommitRollback.hpp"
 #include "TestConnect.hpp"
+#include "TestDriverResultSet.hpp"
 #include "TestExecReadRequest.hpp"
 #include "TestExecWriteRequest.hpp"
 #include "TestStatement.hpp"
@@ -52,6 +53,7 @@
   runner.addTest(TestExecReadRequest::suite());
   runner.addTest(TestBeginCommitRollback::suite());
   runner.addTest(TestStatement::suite());
+  runner.addTest(TestDriverResultSet::suite());
 
   // add our own protector
   CarobProtector* cprot = new CarobProtector();
Index: carob/test/TestDriverResultSet.cpp
diff -u /dev/null carob/test/TestDriverResultSet.cpp:1.1
--- /dev/null   Thu Dec 15 12:29:56 2005
+++ carob/test/TestDriverResultSet.cpp  Thu Dec 15 12:29:56 2005
@@ -0,0 +1,153 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005 Emic Networks
+ * 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 <iostream>
+
+#include "Common.hpp"
+#include "Connection.hpp"
+#include "CarobException.hpp"
+#include "DriverResultSet.hpp"
+#include "TestDriverResultSet.hpp"
+#include "RequestWithResultSetParameters.hpp"
+#include "ResultSetMetaData.hpp"
+#include "Statement.hpp"
+
+using std::wstring;
+using std::wcerr;
+using std::endl;
+
+using namespace CarobNS;
+
+void TestDriverResultSet::testNullValueRetrieval()
+{
+  wstring fctName(L"TestStatement::testNullValueRetrieval");
+  Statement* statementPtr = NULL;
+  //1. Update table: set a value to null
+  statementPtr = connectionPtr->createStatement();
+  if (isDebugEnabled())
+  {
+    logDebug(fctName, L"Creating a NULL value");
+  }
+  statementPtr->executeUpdate(L"UPDATE address SET firstname=NULL WHERE id=0");
+
+  //2. try to read the value with getString
+  DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM address 
WHERE id=0");
+  drsPtr->next();
+  try
+  {
+    drsPtr->getString(2); //should fail
+    // We should receive an exception instead of coming here
+    CPPUNIT_ASSERT(false);
+  }
+  catch (NullValueException nve)
+  {
+    if (isErrorEnabled())
+    {
+      logError(fctName, L"Read failed (this is ok). Exception: "
+          + nve.description());
+    }
+  }
+  //3. lets do it again with getInt
+  try
+  {
+    drsPtr->getInt(2); //should fail
+    // We should receive an exception instead of coming here
+    CPPUNIT_ASSERT(false);
+  }
+  catch (NullValueException nve)
+  {
+    if (isErrorEnabled())
+    {
+      logError(fctName, L"Read failed (this is ok). Exception: "
+          + nve.description());
+    }
+  }
+  delete statementPtr;
+}
+
+void TestDriverResultSet::testGetIntOnString()
+{
+  wstring fctName(L"TestStatement::testGetIntOnString");
+  Statement* statementPtr = NULL;
+  //1. Set a string to an int an read it
+  statementPtr = connectionPtr->createStatement();
+  if (isDebugEnabled())
+  {
+    logDebug(fctName, L"Writing an int in a string");
+  }
+  statementPtr->executeUpdate(L"UPDATE address SET firstname='1234' WHERE 
id=0");
+  //read
+  DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM address 
WHERE id=0");
+  drsPtr->next();
+  wcerr<<L"Int val as string (should be 1234)="<<drsPtr->getInt32(2)<<endl;
+  CPPUNIT_ASSERT(drsPtr->getInt32(2) == 1234);
+
+  //2. Negative numbers
+  statementPtr = connectionPtr->createStatement();
+  if (isDebugEnabled())
+  {
+    logDebug(fctName, L"Writing a negative int in a string");
+  }
+  statementPtr->executeUpdate(L"UPDATE address SET firstname='-1' WHERE id=1");
+  //Read it
+  drsPtr = statementPtr->executeQuery(L"SELECT * FROM address WHERE id=1");
+  drsPtr->next();
+  wcerr<<L"Int val as string (should be -1)="<<drsPtr->getInt32(2)<<endl;
+  CPPUNIT_ASSERT(drsPtr->getInt32(2) == -1);
+
+  //3. Not a number
+  statementPtr = connectionPtr->createStatement();
+  if (isDebugEnabled())
+  {
+    logDebug(fctName, L"Writing a non-number in a string");
+  }
+  statementPtr->executeUpdate(L"UPDATE address SET firstname='hello' WHERE 
id=1");
+  //Read it
+  drsPtr = statementPtr->executeQuery(L"SELECT * FROM address WHERE id=1");
+  drsPtr->next();
+  try
+  {
+    drsPtr->getInt32(2);
+    CPPUNIT_ASSERT(false);
+  }
+  catch (DriverException de)
+  {
+    if (isErrorEnabled())
+    {
+      logError(fctName, L"Read failed (this is ok). Exception: "
+          + de.description());
+    }
+  }
+  delete statementPtr;
+}
+
+CppUnit::Test* TestDriverResultSet::suite()
+{
+  CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( 
"TestDriverResultSet" );
+  suiteOfTests->addTest(new CppUnit::TestCaller<TestDriverResultSet>(
+                                 "testNullValueRetrieval", 
+                                 
&TestDriverResultSet::testNullValueRetrieval));
+  suiteOfTests->addTest(new CppUnit::TestCaller<TestDriverResultSet>(
+                                 "testGetIntOnString", 
+                                 &TestDriverResultSet::testGetIntOnString));
+  return suiteOfTests;
+}
+
Index: carob/test/TestDriverResultSet.hpp
diff -u /dev/null carob/test/TestDriverResultSet.hpp:1.1
--- /dev/null   Thu Dec 15 12:29:56 2005
+++ carob/test/TestDriverResultSet.hpp  Thu Dec 15 12:29:56 2005
@@ -0,0 +1,50 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005 Emic Networks
+ * 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 TESTDRIVERRESULTSET_H_
+#define TESTDRIVERRESULTSET_H_
+
+#include "TestOnValidConnection.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 TestDriverResultSet : public TestOnValidConnection
+{
+public:
+  /** Suite of tests to be run */
+  static CppUnit::Test* suite();
+
+  /**
+   * Sets a null value in a table and tries to read it. Checks that a
+   * NullValueException is thrown
+   */
+  void testNullValueRetrieval();
+  /**
+   * Sets a string entry to various numbers as strings and tries to read it
+   * using getInt function
+   */
+  void testGetIntOnString();
+};
+
+#endif /*TESTDRIVERRESULTSET_H_*/

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

Reply via email to