Date: Thursday, January 11, 2007 @ 22:53:22
  Author: marc
    Path: /cvsroot/carob/carob/test/30-ResultSet

Modified: TestSimpleUnicode.cpp (1.10 -> 1.11) TestSimpleUnicode.hpp (1.2
          -> 1.3)

Complete rewrite, added many tests.


-----------------------+
 TestSimpleUnicode.cpp |  112 +++++++++++++++++++++++++++++++++++++-----------
 TestSimpleUnicode.hpp |    8 +++
 2 files changed, 95 insertions(+), 25 deletions(-)


Index: carob/test/30-ResultSet/TestSimpleUnicode.cpp
diff -u carob/test/30-ResultSet/TestSimpleUnicode.cpp:1.10 
carob/test/30-ResultSet/TestSimpleUnicode.cpp:1.11
--- carob/test/30-ResultSet/TestSimpleUnicode.cpp:1.10  Wed Dec 20 19:38:41 2006
+++ carob/test/30-ResultSet/TestSimpleUnicode.cpp       Thu Jan 11 22:53:22 2007
@@ -37,25 +37,11 @@
 
 using std::wstring;
 
-// warning: some DBMS (e.g., PostgreSQL) support only C-style, Null Terminated 
Strings.
-// This test WILL FAIL with them. (SQLstate 08P01 for PostgreSQL)
-
-namespace {
-
-    // PBK
-    // phi beta kappa + zero + last character (kappa) again
 
-    // wchar_t wide_pbk_[] = { 0x03c6, 0x03b2, 0x03ba };
-    // wstring wide_pbk(wide_pbk_, 3);
-    // this is is even more evil (see SEQUOIA-133)
-    wchar_t wide_pbk_[] = { 0x03c6, 0x03b2, 0x03ba, 0, 0x03ba };
-    wstring wide_pbk(wide_pbk_, 5);
 
-}
-
-void TestSimpleUnicode::testBasic()
+void writeRead(Connection *connectionPtr, const std::wstring& fctName,
+               const std::wstring& testString)
 {
-    const wstring fctName(L"TestSimpleUnicode::testBasic");
 
     if (isInfoEnabled())
     {
@@ -67,7 +53,7 @@
     Statement *stmt = connectionPtr->createStatement();
     
     wstring insertcmd(L"INSERT INTO " TABLE_NAME " values ('");
-    insertcmd += wide_pbk;
+    insertcmd += testString;
     insertcmd += L"')";
 
     int updatecount = stmt->executeUpdate(insertcmd);
@@ -76,23 +62,101 @@
     DriverResultSet* drsPtr = stmt->executeQuery(L"SELECT * FROM " TABLE_NAME);
     CPPUNIT_ASSERT(drsPtr->next());
 
-    wstring returned_pbk = drsPtr->getString(1);
-    CPPUNIT_ASSERT(0 == wide_pbk.compare(returned_pbk));
+    wstring returnedString = drsPtr->getString(1);
+    CPPUNIT_ASSERT(0 == testString.compare(returnedString));
 
     CPPUNIT_ASSERT(!drsPtr->next());
 
 }
 
+void TestSimpleUnicode::testPBK()
+{
+    const wstring fctName(L"TestSimpleUnicode::testPBK");
+    // PBK
+    // phi beta kappa + zero + last character (kappa)
+
+    wchar_t test_[] = { 0x03c6, 0x03b2, 0x03ba };
+    wstring test(test_, 3);
+
+    writeRead(connectionPtr, fctName, test);
+}
+
+
+// warning: some DBMS (e.g., PostgreSQL) support only C-style, Null Terminated 
Strings.
+// This test WILL FAIL with them. (SQLstate 08P01 for PostgreSQL)
+
+void TestSimpleUnicode::testPBKNull()
+{
+    const wstring fctName(L"TestSimpleUnicode::testPBKNull");
+    // PBK
+    // phi beta kappa + zero + last character (kappa) again
+    // this is is even more evil because of the zero (see SEQUOIA-133)
+    wchar_t test_[] = { 0x03c6, 0x03b2, 0x03ba, 0, 0x03ba };
+    wstring test(test_, 5);
+
+    writeRead(connectionPtr, fctName, test);
+}
+
+
+void TestSimpleUnicode::testLatin1CodeSubset()
+{
+    const wstring fctName(L"TestSimpleUnicode::testLatin1CodeSubset");
+
+    wchar_t test_[] = { 307, 340, 240, 241 };
+    wstring test(test_, 4);
+
+    writeRead(connectionPtr, fctName, test);
+
+}
+
+// CAROB-101
+void TestSimpleUnicode::testInvalidUnicode()
+{
+    const wstring fctName(L"TestSimpleUnicode::testInvalidUnicode");
+
+    
+    wchar_t invalid_ [] = { 0x110000 };
+    wstring invalid_unicode(invalid_, 1);
+
+    try {
+        writeRead(connectionPtr, fctName, invalid_unicode);
+        CPPUNIT_FAIL("should not be successful to write/read invalid unicode");
+    } catch (const CarobException& ce) {
+        // TODO: check that this is an expected exception like
+        //  java.nio.charset.UnmappableCharacterException
+        // or alike.
+        // If we get something totally unrelated instead (like
+        // for instance "all controllers down") => rethrow
+        if (ce.getSQLState() != L"Unmappablecharacter")
+            throw;
+    }
+}
+
 // List of tests in this class
 CppUnit::Test* TestSimpleUnicode::suite()
 {
     CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( 
"TestSimpleUnicode" );
-// TODO: check why mysql throws errors
-#ifndef CAROB_TEST_USE_MYSQL
+
+    suiteOfTests->addTest(new CppUnit::TestCaller<TestSimpleUnicode>(
+                              "TestSimpleUnicode::testPBK",
+                              &TestSimpleUnicode::testPBK));
+
+// ? : TODO: check why mysql throws errors
+// MH: Probably because it refuses inline nulls?
+// #ifndef CAROB_TEST_USE_MYSQL
     suiteOfTests->addTest(new CppUnit::TestCaller<TestSimpleUnicode>(
-                              "TestSimpleUnicode::testBasic",
-                              &TestSimpleUnicode::testBasic));
-#endif
+                              "TestSimpleUnicode::testPBKNull",
+                              &TestSimpleUnicode::testPBKNull));
+// #endif
+
+    suiteOfTests->addTest(new CppUnit::TestCaller<TestSimpleUnicode>(
+                              "TestSimpleUnicode::testLatin1CodeSubset",
+                              &TestSimpleUnicode::testLatin1CodeSubset));
+
+    suiteOfTests->addTest(new CppUnit::TestCaller<TestSimpleUnicode>(
+                              "TestSimpleUnicode::testInvalidUnicode",
+                              &TestSimpleUnicode::testInvalidUnicode));
+
     return suiteOfTests;
 }
 
Index: carob/test/30-ResultSet/TestSimpleUnicode.hpp
diff -u carob/test/30-ResultSet/TestSimpleUnicode.hpp:1.2 
carob/test/30-ResultSet/TestSimpleUnicode.hpp:1.3
--- carob/test/30-ResultSet/TestSimpleUnicode.hpp:1.2   Thu Jul 27 17:10:53 2006
+++ carob/test/30-ResultSet/TestSimpleUnicode.hpp       Thu Jan 11 22:53:22 2007
@@ -38,7 +38,13 @@
    * Writes exotic (greek) unicode characters in a table and checks that when
    * read back, the data is identical
    */
-  void testBasic();
+  void testPBK();
+
+  void testPBKNull();
+
+  void testLatin1CodeSubset();
+
+  void testInvalidUnicode();
 
 };
 

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

Reply via email to