From e239ead4b52efcbaf1b0d2b54700d3c38128d90a Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 19 Mar 2003 03:42:27 +0000 Subject: A new STF test case! This one checks strcasecmp correctness for various strings. (This used to be commit ef5bdb1700f6033f342d6bb32a8d0ee240dd34b8) --- source3/stf/strings.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 source3/stf/strings.py (limited to 'source3/stf/strings.py') diff --git a/source3/stf/strings.py b/source3/stf/strings.py new file mode 100755 index 0000000000..fb26c2f9e5 --- /dev/null +++ b/source3/stf/strings.py @@ -0,0 +1,57 @@ +#! /usr/bin/python + +# Comfychair test cases for Samba string functions. + +# Copyright (C) 2003 by Martin Pool +# +# 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 + +import sys, re, comfychair + +def signum(a): + if a < 0: + return -1 + elif a > 0: + return +1 + else: + return 0 + + +class StrCaseCmp_Ascii_Tests(comfychair.TestCase): + """String comparisons in simple ASCII""" + def run_strcmp(self, a, b, expect): + out = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a, b)) + if signum(int(out)) != expect: + self.fail("comparison failed:\n" + " a=%s\n" + " b=%s\n" + " expected=%s\n" + " result=%s\n" % (`a`, `b`, `expect`, `out`)) + + def runtest(self): + cases = [('hello', 'hello', 0), + ('hello', 'goodbye', +1), + ('goodbye', 'hello', -1), + ('hell', 'hello', -1)] + for a, b, expect in cases: + self.run_strcmp(a, b, expect) + + +tests = [StrCaseCmp_Ascii_Tests] + +if __name__ == '__main__': + comfychair.main(tests) + -- cgit From 41fdeceb82d7607fc6f3e9b31640d5e264f8ed9a Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 19 Mar 2003 08:32:42 +0000 Subject: Add additional StrCaseCmp test cases. Doc. (This used to be commit ac6027884b04943fac3d469ff6542d62293f46cc) --- source3/stf/strings.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source3/stf/strings.py') diff --git a/source3/stf/strings.py b/source3/stf/strings.py index fb26c2f9e5..a67e137058 100755 --- a/source3/stf/strings.py +++ b/source3/stf/strings.py @@ -42,16 +42,28 @@ class StrCaseCmp_Ascii_Tests(comfychair.TestCase): " result=%s\n" % (`a`, `b`, `expect`, `out`)) def runtest(self): + # A, B, strcasecmp(A, B) cases = [('hello', 'hello', 0), ('hello', 'goodbye', +1), ('goodbye', 'hello', -1), - ('hell', 'hello', -1)] + ('hell', 'hello', -1), + ('', '', 0), + ('a', '', +1), + ('', 'a', -1), + ('a', 'A', 0), + ('aa', 'aA', 0), + ('Aa', 'aa', 0), + ('longstring ' * 100, 'longstring ' * 100, 0), + ('longstring ' * 100, 'longstring ' * 100 + 'a', -1), + ('longstring ' * 100 + 'a', 'longstring ' * 100, +1), + ] for a, b, expect in cases: self.run_strcmp(a, b, expect) - +# Define the tests exported by this module tests = [StrCaseCmp_Ascii_Tests] +# Handle execution of this file as a main program if __name__ == '__main__': comfychair.main(tests) -- cgit From 2323b1b52d78946ba6dd1221775f73aa80f57505 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 4 Apr 2003 03:20:24 +0000 Subject: StrCaseCmp_Ascii_Tests: comfychair.TestCase.runcmd has changed to return both stdout and stderr. Update to account for this. (This used to be commit 843c36143e07aa66b36014a35846143807676a10) --- source3/stf/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/stf/strings.py') diff --git a/source3/stf/strings.py b/source3/stf/strings.py index a67e137058..8fc12d4e39 100755 --- a/source3/stf/strings.py +++ b/source3/stf/strings.py @@ -33,7 +33,7 @@ def signum(a): class StrCaseCmp_Ascii_Tests(comfychair.TestCase): """String comparisons in simple ASCII""" def run_strcmp(self, a, b, expect): - out = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a, b)) + out, err = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a, b)) if signum(int(out)) != expect: self.fail("comparison failed:\n" " a=%s\n" -- cgit From 2228271d684753f6a0fb20da87ccf1454d554f39 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Apr 2003 00:21:52 +0000 Subject: Syncup stf directory with HEAD. (This used to be commit 161740392903e3e1b9281b9f72e61846b543b67f) --- source3/stf/strings.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'source3/stf/strings.py') diff --git a/source3/stf/strings.py b/source3/stf/strings.py index 8fc12d4e39..328849b1ce 100755 --- a/source3/stf/strings.py +++ b/source3/stf/strings.py @@ -1,4 +1,4 @@ -#! /usr/bin/python +#! /usr/bin/python # Comfychair test cases for Samba string functions. @@ -19,7 +19,22 @@ # 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,12 +43,29 @@ 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): +class StrCaseCmp(comfychair.TestCase): """String comparisons in simple ASCII""" def run_strcmp(self, a, b, expect): - out, err = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a, b)) + out, err = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a.encode('utf-8'), b.encode('utf-8'))) if signum(int(out)) != expect: self.fail("comparison failed:\n" " a=%s\n" @@ -56,14 +88,20 @@ class StrCaseCmp_Ascii_Tests(comfychair.TestCase): ('longstring ' * 100, 'longstring ' * 100, 0), ('longstring ' * 100, 'longstring ' * 100 + 'a', -1), ('longstring ' * 100 + 'a', 'longstring ' * 100, +1), + (KATAKANA_LETTER_A, KATAKANA_LETTER_A, 0), + (KATAKANA_LETTER_A, 'a', 1), ] for a, b, expect in cases: self.run_strcmp(a, b, expect) # Define the tests exported by this module -tests = [StrCaseCmp_Ascii_Tests] +tests = [StrCaseCmp, + PushUCS2_Tests] # Handle execution of this file as a main program if __name__ == '__main__': comfychair.main(tests) +# Local variables: +# coding: utf-8 +# End: -- cgit From 32665c36c88d9f650baa33248275b711799fd300 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 9 Mar 2004 11:15:44 +0000 Subject: Given how core this code is, I figure it should have it's own testsuite. Big thanks to tpot and mbp for showing how easy it can be to write a simple unit test, and for providing the STF. This also changes the strstr_m() code to use strstr_w() (avoiding duplication) and fixes it so that it passes the STF. (We now always restart before doing the unicode run, until sombody can show me why the testsuite is wrong). Andrew Bartlett (This used to be commit a893a324f37e6a171719db8ffffe66df31c2dbaa) --- source3/stf/strings.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'source3/stf/strings.py') diff --git a/source3/stf/strings.py b/source3/stf/strings.py index 328849b1ce..86f7acdeb4 100755 --- a/source3/stf/strings.py +++ b/source3/stf/strings.py @@ -94,8 +94,52 @@ class StrCaseCmp(comfychair.TestCase): for a, b, expect in cases: self.run_strcmp(a, b, expect) +class strstr_m(comfychair.TestCase): + """String comparisons in simple ASCII""" + def run_strstr(self, a, b, expect): + out, err = self.runcmd('t_strstr \"%s\" \"%s\"' % (a.encode('utf-8'), b.encode('utf-8'))) + if (out != (expect + '\n').encode('utf-8')): + self.fail("comparison failed:\n" + " a=%s\n" + " b=%s\n" + " expected=%s\n" + " result=%s\n" % (`a`, `b`, `expect+'\n'`, `out`)) + + def runtest(self): + # A, B, strstr_m(A, B) + cases = [('hello', 'hello', 'hello'), + ('hello', 'goodbye', '(null)'), + ('goodbye', 'hello', '(null)'), + ('hell', 'hello', '(null)'), + ('hello', 'hell', 'hello'), + ('', '', ''), + ('a', '', 'a'), + ('', 'a', '(null)'), + ('a', 'A', '(null)'), + ('aa', 'aA', '(null)'), + ('Aa', 'aa', '(null)'), + ('%v foo', '%v', '%v foo'), + ('foo %v foo', '%v', '%v foo'), + ('foo %v', '%v', '%v'), + ('longstring ' * 100, 'longstring ' * 99, 'longstring ' * 100), + ('longstring ' * 99, 'longstring ' * 100, '(null)'), + ('longstring a' * 99, 'longstring ' * 100 + 'a', '(null)'), + ('longstring ' * 100 + 'a', 'longstring ' * 100, 'longstring ' * 100 + 'a'), + (KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', '(null)'), + (KATAKANA_LETTER_A + 'bcde', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcde'), + ('d'+KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd'), + ('d'+KATAKANA_LETTER_A + 'bd', KATAKANA_LETTER_A + 'bcd', '(null)'), + + ('e'+KATAKANA_LETTER_A + 'bcdf', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcdf'), + (KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', '(null)'), + (KATAKANA_LETTER_A*3, 'a', '(null)'), + ] + for a, b, expect in cases: + self.run_strstr(a, b, expect) + # Define the tests exported by this module tests = [StrCaseCmp, + strstr_m, PushUCS2_Tests] # Handle execution of this file as a main program -- cgit From 34bb47c9b0f33c20a22df66326f674363ceea1a0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 01:52:05 +0000 Subject: r23791: found some more v2->v3 conversions (This used to be commit b6cbac3db3b478d5c7991cee78c6695fc8d22681) --- source3/stf/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/stf/strings.py') diff --git a/source3/stf/strings.py b/source3/stf/strings.py index 86f7acdeb4..ee192c28fe 100755 --- a/source3/stf/strings.py +++ b/source3/stf/strings.py @@ -6,7 +6,7 @@ # # 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 +# published by the Free Software Foundation; either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but -- cgit From 9fa1c63578733077c0aaaeeb2fc97c3b191089cc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit c676a971142d7176fd5dbf21405fca14515a0a76) --- source3/stf/strings.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/stf/strings.py') diff --git a/source3/stf/strings.py b/source3/stf/strings.py index ee192c28fe..4e00021525 100755 --- a/source3/stf/strings.py +++ b/source3/stf/strings.py @@ -15,9 +15,7 @@ # 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 +# along with this program; if not, see . # 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 -- cgit