List:Commits« Previous MessageNext Message »
From:John David Duncan Date:October 19 2009 3:17pm
Subject:bzr push into mysql-5.1-telco-6.3-ndbjtie branch (jdd:3081 to 3082)
View as plain text  
 3082 John David Duncan	2009-10-19
      Copyright notices on all files.
      Test cleanup and a new test for recode().
      More comments about the initialization of a CharsetMapImpl.

    modified:
      storage/ndb/ndbjtie/mysql/include/CharsetMap.h
      storage/ndb/ndbjtie/mysql/src/CharsetMap.cpp
      storage/ndb/ndbjtie/mysql/test/mysql_utils_test.cpp
 3081 John David Duncan	2009-10-18
      Implemented CharsetMap
      Created tests for CharsetMap and recode()
      Changed some .c files to .cpp 
      decimal_str2bin() and decima_bin2str() now have C++ linkage (not C). 

    removed:
      storage/ndb/ndbjtie/mysql/src/mysql_utils.c
    added:
      storage/ndb/ndbjtie/mysql/include/CharsetMap.h
      storage/ndb/ndbjtie/mysql/src/CharsetMap.cpp
      storage/ndb/ndbjtie/mysql/src/CharsetMapImpl.cpp
      storage/ndb/ndbjtie/mysql/src/CharsetMapImpl.h
      storage/ndb/ndbjtie/mysql/src/util_decimal.cpp
    renamed:
      storage/ndb/ndbjtie/mysql/test/mysql_utils_test.c => storage/ndb/ndbjtie/mysql/test/mysql_utils_test.cpp
    modified:
      storage/ndb/ndbjtie/mysql/include/mysql_utils.h
      storage/ndb/ndbjtie/mysql/src/Makefile
      storage/ndb/ndbjtie/mysql/test/mysql_utils_test.cpp
=== modified file 'storage/ndb/ndbjtie/mysql/include/CharsetMap.h'
--- a/storage/ndb/ndbjtie/mysql/include/CharsetMap.h	2009-10-19 04:52:57 +0000
+++ b/storage/ndb/ndbjtie/mysql/include/CharsetMap.h	2009-10-19 15:10:56 +0000
@@ -1,10 +1,20 @@
 /*
- *  CharsetMap.h
- *
- *  Created by John David Duncan on 8/31/09.
- *  Copyright 2009 Sun Microsystems. All rights reserved.
- *
- */
+ Copyright (C) 2009 Sun Microsystems, Inc.
+ All rights reserved. Use is subject to license terms.
+ 
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+ 
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
 
 
 /* CharsetMap handles encoding issues for character data 

=== modified file 'storage/ndb/ndbjtie/mysql/src/CharsetMap.cpp'
--- a/storage/ndb/ndbjtie/mysql/src/CharsetMap.cpp	2009-10-19 04:52:57 +0000
+++ b/storage/ndb/ndbjtie/mysql/src/CharsetMap.cpp	2009-10-19 15:10:56 +0000
@@ -1,9 +1,24 @@
 /*
+ Copyright (C) 2009 Sun Microsystems, Inc.
+ All rights reserved. Use is subject to license terms.
+ 
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+ 
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+/*
  *  CharsetMap.cpp
  *
- *  Created by John David Duncan on 8/31/09.
- *  Copyright 2009 Sun Microsystems. All rights reserved.
- *
  */
 
 #include "CharsetMap.h"
@@ -14,7 +29,9 @@
 
 /* m_map is a static singleton, 
    visible only within the scope of this file,
-   initialized at load time.
+   initialized at load time.  
+   This in turn causes the entire mysql charset library to be initialized, 
+   including reading the XML files under MYSQL_HOME/share/mysql/charsets
 */
 static CharsetMapImpl m_map;
 

=== modified file 'storage/ndb/ndbjtie/mysql/test/mysql_utils_test.cpp'
--- a/storage/ndb/ndbjtie/mysql/test/mysql_utils_test.cpp	2009-10-19 04:52:57 +0000
+++ b/storage/ndb/ndbjtie/mysql/test/mysql_utils_test.cpp	2009-10-19 15:10:56 +0000
@@ -16,7 +16,7 @@
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */
 /*
- * mysql_utils_test.c
+ * mysql_utils_test.cpp
  */
 
 #include <string.h>
@@ -96,9 +96,10 @@ int main()
        but in the UTF-8 representation it is 0xC3 0xBC.
     */
     
-    const char my_word_latin1[6] = { 0xFC , 'l' , 'k' , 'e' , 'r' , 0 } ; 
-    const char my_word_utf8[7] = { 0xC3 , 0xBC , 'l' , 'k' , 'e' , 'r' , 0 }; 
-    const char my_word_truncated[5] = { 0xC3 , 0xBC , 'l' , 'k' , 0 };   
+    const char my_word_latin1[6]    = { 0xFC , 'l' , 'k' , 'e' , 'r', 0}; 
+    const char my_word_utf8[7]      = { 0xC3 , 0xBC , 'l' , 'k' , 'e' , 'r', 0}; 
+    const char my_word_truncated[5] = { 0xC3 , 0xBC , 'l' , 'k', 0};
+    const char my_bad_utf8[5]       = { 'l' , 0xBC , 'a' , 'd' , 0};
     char result_buff_1[32];
     char result_buff_2[32];
     char result_buff_too_small[4];
@@ -112,45 +113,54 @@ int main()
     printf("Latin1: \"%s\"                       UTF8:  \"%s\" \n", 
            my_word_latin1, my_word_utf8);
     
-    /* recode from UTF-8 to Latin 1 */
+    /* RECODE TEST 1: recode from UTF-8 to Latin 1 */
     lengths[0] = 7;
     lengths[1] = 32;
     int rr1 = csmap.recode(lengths, utf8_num, latin1_num, 
                            my_word_utf8, result_buff_1);
-    printf("Recode UTF-8 to Latin-1: %d %ld %ld \"%s\" => \"%s\" \n", rr1, 
-           lengths[0], lengths[1], my_word_utf8, result_buff_1);
+    printf("Recode Test 1 - UTF-8 to Latin-1: %d %ld %ld \"%s\" => \"%s\" \n", 
+           rr1, lengths[0], lengths[1], my_word_utf8, result_buff_1);
     assert(rr1 == RECODE_OK);
     assert(lengths[0] == 7);
     assert(lengths[1] == 6);
     assert(!strcmp(result_buff_1, my_word_latin1));
     
-    /* recode from Latin1 to to UTF-8 */
+    /* RECODE TEST 2: recode from Latin1 to to UTF-8 */
     lengths[0] = 6;
     lengths[1] = 32;
     int rr2 = CharsetMap::recode(lengths, latin1_num, utf8_num,
                                  my_word_latin1, result_buff_2);
-    printf("Recode Latin-1 to UTF-8: %d %ld %ld \"%s\" => \"%s\" \n", rr2, 
-           lengths[0], lengths[1], my_word_latin1, result_buff_2);
+    printf("Recode Test 2 - Latin-1 to UTF-8: %d %ld %ld \"%s\" => \"%s\" \n", 
+           rr2, lengths[0], lengths[1], my_word_latin1, result_buff_2);
     assert(rr2 == RECODE_OK);
     assert(lengths[0] == 6);
     assert(lengths[1] == 7);
     assert(!(strcmp(result_buff_2, my_word_utf8)));
     
-    /* recode with a too-small result buffer */
+    /* RECODE TEST 3: recode with a too-small result buffer */
     lengths[0] = 6;
     lengths[1] = 4;
     int rr3 = CharsetMap::recode(lengths, latin1_num, utf8_num,
                                  my_word_latin1, result_buff_too_small);
-    printf("Recode with too-small buffer: %d %ld %ld \"%s\" => \"%s\" \n", rr3, 
-           lengths[0], lengths[1], my_word_latin1, result_buff_too_small);
+    printf("Recode Test 3 - too-small buffer: %d %ld %ld \"%s\" => \"%s\" \n", 
+           rr3, lengths[0], lengths[1], my_word_latin1, result_buff_too_small);
     assert(rr3 == RECODE_BUFF_TOO_SMALL);
     assert(lengths[0] == 3);
     assert(lengths[1] == 4);
+    /* Note that the buffer size was 4, but the comparison string including 
+       terminator is length 5 */
     assert(!(strcmp(result_buff_too_small, my_word_truncated)));
     
-    /* recode with an invalid character set */
+    /* RECODE TEST 4: recode with an invalid character set */
     int rr4 = csmap.recode(lengths, 0, 999, my_word_latin1, result_buff_2);
-    printf("Recode with invalid charset: %d \n", rr4);
+    printf("Recode Test 4 - invalid charset: %d \n", rr4);
     assert(rr4 == RECODE_BAD_CHARSET);
-    
+
+    /* RECODE TEST 5: source string is ill-formed UTF-8 */
+    lengths[0] = 5;
+    lengths[1] = 32;
+    int rr5 = csmap.recode(lengths, utf8_num, latin1_num, 
+                           my_bad_utf8, result_buff_2);
+    printf("Recode Test 5 - ill-formed source string: %d \n", rr5);
+    assert(rr5 == RECODE_BAD_SRC);
 }


Attachment: [text/bzr-bundle] bzr/jdd@sun.com-20091019151056-2i4f2wxwwlv3ogok.bundle
Thread
bzr push into mysql-5.1-telco-6.3-ndbjtie branch (jdd:3081 to 3082)John David Duncan19 Oct