Clean up a comment noticed by Jonathan Shao@Panasas.com and remove an
[Samba/gebeck_regimport.git] / source3 / stf / strings.py
blob328849b1ceb44c095b75e653838edc935bc59d9d
1 #! /usr/bin/python
3 # Comfychair test cases for Samba string functions.
5 # Copyright (C) 2003 by Martin Pool <mbp@samba.org>
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 # USA
22 # XXX: All this code assumes that the Unix character set is UTF-8,
23 # which is the most common setting. I guess it would be better to
24 # force it to that value while running the tests. I'm not sure of the
25 # best way to do that yet.
27 # Note that this is NOT the case in C code until the loadparm table is
28 # intialized -- the default seems to be ASCII, which rather lets Samba
29 # off the hook. :-) The best way seems to be to put this in the test
30 # harnesses:
32 # lp_load("/dev/null", True, False, False);
34 # -- mbp
36 import sys, re, comfychair
37 from unicodenames import *
39 def signum(a):
40 if a < 0:
41 return -1
42 elif a > 0:
43 return +1
44 else:
45 return 0
48 class PushUCS2_Tests(comfychair.TestCase):
49 """Conversion to/from UCS2"""
50 def runtest(self):
51 OE = LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
52 oe = LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
53 cases = ['hello',
54 'hello world',
55 'g' + OE + OE + 'gomobile',
56 'g' + OE + oe + 'gomobile',
57 u'foo\u0100',
58 KATAKANA_LETTER_A * 20,
60 for u8str in cases:
61 out, err = self.runcmd("t_push_ucs2 \"%s\"" % u8str.encode('utf-8'))
62 self.assert_equal(out, "0\n")
65 class StrCaseCmp(comfychair.TestCase):
66 """String comparisons in simple ASCII"""
67 def run_strcmp(self, a, b, expect):
68 out, err = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a.encode('utf-8'), b.encode('utf-8')))
69 if signum(int(out)) != expect:
70 self.fail("comparison failed:\n"
71 " a=%s\n"
72 " b=%s\n"
73 " expected=%s\n"
74 " result=%s\n" % (`a`, `b`, `expect`, `out`))
76 def runtest(self):
77 # A, B, strcasecmp(A, B)
78 cases = [('hello', 'hello', 0),
79 ('hello', 'goodbye', +1),
80 ('goodbye', 'hello', -1),
81 ('hell', 'hello', -1),
82 ('', '', 0),
83 ('a', '', +1),
84 ('', 'a', -1),
85 ('a', 'A', 0),
86 ('aa', 'aA', 0),
87 ('Aa', 'aa', 0),
88 ('longstring ' * 100, 'longstring ' * 100, 0),
89 ('longstring ' * 100, 'longstring ' * 100 + 'a', -1),
90 ('longstring ' * 100 + 'a', 'longstring ' * 100, +1),
91 (KATAKANA_LETTER_A, KATAKANA_LETTER_A, 0),
92 (KATAKANA_LETTER_A, 'a', 1),
94 for a, b, expect in cases:
95 self.run_strcmp(a, b, expect)
97 # Define the tests exported by this module
98 tests = [StrCaseCmp,
99 PushUCS2_Tests]
101 # Handle execution of this file as a main program
102 if __name__ == '__main__':
103 comfychair.main(tests)
105 # Local variables:
106 # coding: utf-8
107 # End: