3 # Comfychair test cases for Samba string functions.
5 # Copyright (C) 2003 by Martin Pool <mbp@samba.org>
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
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
32 # lp_load("/dev/null", True, False, False);
36 import sys
, re
, comfychair
37 from unicodenames
import *
48 class PushUCS2_Tests(comfychair
.TestCase
):
49 """Conversion to/from UCS2"""
51 OE
= LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
52 oe
= LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
55 'g' + OE
+ OE
+ 'gomobile',
56 'g' + OE
+ oe
+ 'gomobile',
58 KATAKANA_LETTER_A
* 20,
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"
74 " result=%s\n" % (`a`
, `b`
, `expect`
, `out`
))
77 # A, B, strcasecmp(A, B)
78 cases
= [('hello', 'hello', 0),
79 ('hello', 'goodbye', +1),
80 ('goodbye', 'hello', -1),
81 ('hell', 'hello', -1),
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
101 # Handle execution of this file as a main program
102 if __name__
== '__main__':
103 comfychair
.main(tests
)