Date: Friday, November 3, 2006 @ 14:52:30
  Author: csaba
    Path: /cvsroot/carob/libmysequoia

   Added: test/TestConverter.cpp (1.1) test/TestConverter.hpp (1.1)
Modified: config/mysequoia.conf (1.9 -> 1.10) test/Makefile.am (1.8 ->
          1.9) test/TestMySQLAPI.cpp (1.44 -> 1.45) test/TestMySQLAPI.hpp
          (1.20 -> 1.21)

Added unit tests for encoders and character sets.


------------------------+
 config/mysequoia.conf  |   18 +++++++++++++++
 test/Makefile.am       |    6 +++--
 test/TestConverter.cpp |   54 +++++++++++++++++++++++++++++++++++++++++++++++
 test/TestConverter.hpp |   44 ++++++++++++++++++++++++++++++++++++++
 test/TestMySQLAPI.cpp  |   41 +++++++++++++++++++++++++++++++++++
 test/TestMySQLAPI.hpp  |    6 +++--
 6 files changed, 165 insertions(+), 4 deletions(-)


Index: libmysequoia/config/mysequoia.conf
diff -u libmysequoia/config/mysequoia.conf:1.9 
libmysequoia/config/mysequoia.conf:1.10
--- libmysequoia/config/mysequoia.conf:1.9      Tue Oct 10 11:14:26 2006
+++ libmysequoia/config/mysequoia.conf  Fri Nov  3 14:52:30 2006
@@ -1,5 +1,22 @@
 # the values below are commented out
 # please edit and remove the ';'
+# this is only necessary if from the
+# connect string user, password, host
+# database is missing
+# in this case libmysequoia will use
+# this as default settings
+
+# if you specify more then once the
+# same option, than the last one
+# will overwrite the previous one
+#
+# example:
+# user = realuser
+# password = realpassword
+# user = realuser2
+#
+# the user = realuser2 will overwrite
+# the user = realuser one
 
 [client]
 ;user = realuser
@@ -7,3 +24,4 @@
 ;host = node1 node2
 ;database = DB1
 ;persistent_connection = false
+;default-character-set=latin1
Index: libmysequoia/test/Makefile.am
diff -u libmysequoia/test/Makefile.am:1.8 libmysequoia/test/Makefile.am:1.9
--- libmysequoia/test/Makefile.am:1.8   Mon Mar 27 11:52:38 2006
+++ libmysequoia/test/Makefile.am       Fri Nov  3 14:52:30 2006
@@ -27,7 +27,8 @@
 runTests_SOURCES = runTests.cpp \
                    TestCarobMySQL.cpp \
                    TestMySQLAPI.cpp \
-                   TestIniParser.cpp
+                   TestIniParser.cpp \
+                   TestConverter.cpp
 
 runTests_CXXFLAGS = @CPPUNIT_CFLAGS@ @MYSQL_CFLAGS@ @GCOV_CFLAGS@
 runTests_LDADD = $(top_builddir)/src/libmysequoia.la @CPPUNIT_LDADD@ 
@GCOV_LDADD@ -lpthread
@@ -37,7 +38,8 @@
 EXTRA_DIST = Globals.hpp \
              TestCarobMySQL.hpp \
              TestMySQLAPI.hpp \
-             TestIniParser.hpp
+             TestIniParser.hpp \
+             TestConverter.hpp
 
 clean-local:
        rm -f *.gcno *.gcda
Index: libmysequoia/test/TestConverter.cpp
diff -u /dev/null libmysequoia/test/TestConverter.cpp:1.1
--- /dev/null   Fri Nov  3 14:52:30 2006
+++ libmysequoia/test/TestConverter.cpp Fri Nov  3 14:52:30 2006
@@ -0,0 +1,54 @@
+/*
+ * 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): Csaba Simon
+ * Contributor(s): 
+ */
+
+#include "TestConverter.hpp"
+
+#include <string>
+#include <iostream>
+
+using namespace std;
+ 
+CPPUNIT_TEST_SUITE_REGISTRATION (TestConverter);
+ 
+void TestConverter::setUp(void)
+{
+}
+
+void TestConverter::tearDown(void) 
+{
+}
+
+void TestConverter::latin1(void)
+{
+  string s_in, s_out;
+  wstring ws;
+  
+  for (int i = 0; i < 256; i++)
+    s_in += (char)i;
+
+  Converter conv("latin1");
+  // convert to wchar_t
+  ws = conv.to_wstring(s_in);
+  // convert back to latin1
+  s_out = conv.from_wstring(ws);
+    
+  CPPUNIT_ASSERT_EQUAL (s_in, s_out);
+}
Index: libmysequoia/test/TestConverter.hpp
diff -u /dev/null libmysequoia/test/TestConverter.hpp:1.1
--- /dev/null   Fri Nov  3 14:52:30 2006
+++ libmysequoia/test/TestConverter.hpp Fri Nov  3 14:52:30 2006
@@ -0,0 +1,44 @@
+/*
+ * 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): Csaba Simon
+ * Contributor(s): 
+ */
+
+#ifndef _TESTCONVERTER_HPP
+#define _TESTCONVERTER_HPP
+
+#include "Converter.hpp"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class TestConverter : public CPPUNIT_NS::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestConverter);
+    CPPUNIT_TEST (latin1);
+  CPPUNIT_TEST_SUITE_END ();
+
+public:
+  void setUp (void);
+  void tearDown (void);
+
+protected:
+  void latin1(void);
+};
+
+#endif
Index: libmysequoia/test/TestMySQLAPI.cpp
diff -u libmysequoia/test/TestMySQLAPI.cpp:1.44 
libmysequoia/test/TestMySQLAPI.cpp:1.45
--- libmysequoia/test/TestMySQLAPI.cpp:1.44     Fri Oct 27 16:37:40 2006
+++ libmysequoia/test/TestMySQLAPI.cpp  Fri Nov  3 14:52:30 2006
@@ -884,6 +884,47 @@
   mysql_free_result(res);
 }
 
+/*
+ * The following test case will fail if the
+ * "characterEncoding=utf8" is missing from
+ * the vdb file url option
+ */
+void TestMySQLAPI::bug_lms_8_test(void)
+{
+  const int BUFFER_IN_LEN = 0x100;
+  char buffer_in[BUFFER_IN_LEN];
+  char buffer_out[BUFFER_IN_LEN * 2];
+  char query[BUFFER_IN_LEN * 2 + 30];
+  unsigned long len;
+  MYSQL_RES *res = 0;
+  MYSQL_ROW row = 0;
+
+  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 0, 0) 
!= 0);  
+
+  mysql_query(mysql, "drop table t1");
+  CPPUNIT_ASSERT(mysql_query(mysql, "create table t1 (a int, c varchar(1024)) 
default charset=utf8") == 0);
+
+  for (int i = 0; i < BUFFER_IN_LEN; i++)
+    buffer_in[i] = i;
+
+  CPPUNIT_ASSERT(mysql_set_character_set(mysql, "latin1") == 0);
+  CPPUNIT_ASSERT((len = mysql_real_escape_string(mysql, buffer_out, buffer_in, 
BUFFER_IN_LEN)) != (unsigned long) ~0);
+
+  memmove(query, "insert into t1 values (1, '", 27);
+  memmove(query+27, buffer_out, len);
+  memmove(query+27+len, "')", 2);
+  query[27+len+2] = '\0';
+  CPPUNIT_ASSERT(mysql_real_query(mysql, query, 27+len+2) == 0);
+  CPPUNIT_ASSERT(mysql_query(mysql, "select a, c from t1") == 0);
+
+  CPPUNIT_ASSERT((res = mysql_store_result(mysql)) != 0);
+  CPPUNIT_ASSERT((row = mysql_fetch_row(res)) != 0);
+  CPPUNIT_ASSERT(memcmp(row[0], "1", 2) == 0);
+  CPPUNIT_ASSERT(memcmp(row[1], buffer_in, BUFFER_IN_LEN) == 0);
+
+  mysql_free_result(res);  
+}
+
 void TestMySQLAPI::bug_lms_9_test(void)
 {
   const char *setcharset = "gbk";
Index: libmysequoia/test/TestMySQLAPI.hpp
diff -u libmysequoia/test/TestMySQLAPI.hpp:1.20 
libmysequoia/test/TestMySQLAPI.hpp:1.21
--- libmysequoia/test/TestMySQLAPI.hpp:1.20     Fri Oct 27 16:37:40 2006
+++ libmysequoia/test/TestMySQLAPI.hpp  Fri Nov  3 14:52:30 2006
@@ -33,9 +33,9 @@
     CPPUNIT_TEST (mysql_init_test);
     CPPUNIT_TEST (mysql_real_connect_test);
     CPPUNIT_TEST (mysql_real_connect_negative_test);
-    #ifdef USE_OLD_FUNCTIONS
+#ifdef USE_OLD_FUNCTIONS
     CPPUNIT_TEST (mysql_connect_test);
-    #endif
+#endif
     CPPUNIT_TEST (mysql_select_db_test);
     CPPUNIT_TEST (mysql_select_db_negative_test);
     CPPUNIT_TEST (mysql_change_user_test);
@@ -60,6 +60,7 @@
     CPPUNIT_TEST (mysql_stmt_long_data_fetch_field_test);
     CPPUNIT_TEST (mysql_blob_test);
     CPPUNIT_TEST (bug_lms_6_test);
+    CPPUNIT_TEST (bug_lms_8_test);
     CPPUNIT_TEST (bug_lms_9_test);
     CPPUNIT_TEST (bug_lms_10_test);
     CPPUNIT_TEST (mysql_warning_count_test);
@@ -104,6 +105,7 @@
   void mysql_stmt_long_data_fetch_field_test(void);
   void mysql_blob_test(void);
   void bug_lms_6_test(void);
+  void bug_lms_8_test(void);
   void bug_lms_9_test(void);
   void bug_lms_10_test(void);
   void mysql_warning_count_test(void);

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

Reply via email to