Integrate abartlet's t_push_ucs2 test into test framework:
authorMartin Pool <mbp@samba.org>
Tue, 8 Apr 2003 08:05:01 +0000 (08:05 +0000)
committerMartin Pool <mbp@samba.org>
Tue, 8 Apr 2003 08:05:01 +0000 (08:05 +0000)
 - Build t_push_ucs2 as part of check-programs, the prerequisite for
   "make check".

 - t_push_ucs2.c: Load configuration from /dev/null so that we get a
   unix_charset of UTF-8 and can do meaningful UCS2 tests.  Better
   comment.

 - Add a test to strings.py which tries conversion UTF8->UCS2->UTF8
   and checks the results.  Do this for English, Latin-1, and Katakana
   strings.

 - Add Python module with symbolic names for a handful of UNICODE
   characters.
(This used to be commit 275e095c92ac74815ab9e388a0e83cdb7ddd85f3)

source3/Makefile.in
source3/stf/strings.py
source3/stf/unicodenames.py [new file with mode: 0644]
source3/torture/t_push_ucs2.c

index fc18fc2ff2def88a9bdfeb149f963d324c65d45e..b9504f5b15862145132a2341ef696fdd9e33812c 100644 (file)
@@ -1347,4 +1347,4 @@ check: check-programs
        python stf/standardcheck.py
 
 # These are called by the test suite
-check-programs: bin/t_strcmp
+check-programs: bin/t_strcmp bin/t_push_ucs2
index 8fc12d4e3965da2b106793cd0a4f309251a222a4..4e070c04448ba4d9bb492e9ebf07a7141dcb88bc 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/python     
 
 # Comfychair test cases for Samba string functions.
 
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 # USA
 
+# XXX: All this code assumes that the Unix character set is UTF-8,
+# which is the most common setting.  I guess it would be better to
+# force it to that value while running the tests.  I'm not sure of the
+# best way to do that yet.
+# 
+# Note that this is NOT the case in C code until the loadparm table is
+# intialized -- the default seems to be ASCII, which rather lets Samba
+# off the hook. :-) The best way seems to be to put this in the test
+# harnesses:
+#
+#       lp_load("/dev/null", True, False, False);
+#
+# -- mbp
+
 import sys, re, comfychair
+from unicodenames import *
 
 def signum(a):
     if a < 0:
@@ -28,6 +43,23 @@ def signum(a):
         return +1
     else:
         return 0
+
+
+class PushUCS2_Tests(comfychair.TestCase):
+    """Conversion to/from UCS2"""
+    def runtest(self):
+        OE = LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
+        oe = LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
+        cases = ['hello',
+                 'hello world',
+                 'g' + OE + OE + 'gomobile', 
+                 'g' + OE + oe + 'gomobile', 
+                 u'foo\u0100',
+                 KATAKANA_LETTER_A * 20,
+                 ]
+        for u8str in cases:
+            out, err = self.runcmd("t_push_ucs2 \"%s\"" % u8str.encode('utf-8'))
+            self.assert_equal(out, "0\n")
     
 
 class StrCaseCmp_Ascii_Tests(comfychair.TestCase):
@@ -61,9 +93,13 @@ class StrCaseCmp_Ascii_Tests(comfychair.TestCase):
             self.run_strcmp(a, b, expect)
         
 # Define the tests exported by this module
-tests = [StrCaseCmp_Ascii_Tests]
+tests = [StrCaseCmp_Ascii_Tests,
+         PushUCS2_Tests]
 
 # Handle execution of this file as a main program
 if __name__ == '__main__':
     comfychair.main(tests)
 
+# Local variables:
+# coding: utf-8
+# End:
diff --git a/source3/stf/unicodenames.py b/source3/stf/unicodenames.py
new file mode 100644 (file)
index 0000000..d4100cb
--- /dev/null
@@ -0,0 +1,33 @@
+#! /usr/bin/python
+
+# Copyright (C) 2003 by Martin Pool <mbp@samba.org>
+# 
+# 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; either version 2 of the
+# License, or (at your option) any later version.
+# 
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+
+
+"""
+Defines symbolic names for a few UNICODE characters, to make test
+source code more readable on machines that don't have all the
+necessary fonts.
+
+You can do "import *" on this file safely.
+"""
+
+LATIN_CAPITAL_LETTER_N_WITH_TILDE         = u'\u004e'
+LATIN_CAPITAL_LETTER_O_WITH_DIARESIS      = u'\u00d6'
+LATIN_SMALL_LETTER_O_WITH_DIARESIS        = u'\u00f6'
+
+KATAKANA_LETTER_A                         = u'\u30a2'
index ca04394acce90b69ecfb2f9082677329a226f6b6..86ae1b9b6ca516812dec66515a903ea33932defb 100644 (file)
@@ -30,10 +30,14 @@ static int check_push_ucs2(const char *orig)
 int main(int argc, char *argv[])
 {
        int i, ret = 0;
-       
+
+       /* Needed to initialize character set */
+       lp_load("/dev/null", True, False, False);
+
        if (argc != 2) {
                fprintf(stderr, "usage: %s STRING1\n"
-                       "Converts a string, prints the results of strcmp\n",
+                       "Checks that a string translated UNIX->UCS2->UNIX is unchanged\n"
+                       "Should be always 0\n",
                        argv[0]);
                return 2;
        }