ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / strings.py
blobe812df8a97e1f590d61d95db194ccb2383afa1c5
1 # subunit test cases for Samba string functions.
3 # Copyright (C) 2003 by Martin Pool <mbp@samba.org>
4 # Copyright (C) 2011 Andrew Bartlett
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # XXX: All this code assumes that the Unix character set is UTF-8,
21 # which is the most common setting. I guess it would be better to
22 # force it to that value while running the tests. I'm not sure of the
23 # best way to do that yet.
25 # -- mbp
26 import unicodedata
27 import samba.tests
28 from samba import strcasecmp_m, strstr_m
31 KATAKANA_LETTER_A = unicodedata.lookup("KATAKANA LETTER A")
34 def signum(a):
35 if a < 0:
36 return -1
37 elif a > 0:
38 return +1
39 else:
40 return 0
42 class strcasecmp_m_Tests(samba.tests.TestCase):
43 """String comparisons in simple ASCII and unicode"""
44 def test_strcasecmp_m(self):
45 # A, B, strcasecmp(A, B)
46 cases = [('hello', 'hello', 0),
47 ('hello', 'goodbye', +1),
48 ('goodbye', 'hello', -1),
49 ('hell', 'hello', -1),
50 ('', '', 0),
51 ('a', '', +1),
52 ('', 'a', -1),
53 ('a', 'A', 0),
54 ('aa', 'aA', 0),
55 ('Aa', 'aa', 0),
56 ('longstring ' * 100, 'longstring ' * 100, 0),
57 ('longstring ' * 100, 'longstring ' * 100 + 'a', -1),
58 ('longstring ' * 100 + 'a', 'longstring ' * 100, +1),
59 (KATAKANA_LETTER_A, KATAKANA_LETTER_A, 0),
60 (KATAKANA_LETTER_A, 'a', 1),
62 for a, b, expect in cases:
63 self.assertEqual(signum(strcasecmp_m(a, b)), expect)
66 class strstr_m_Tests(samba.tests.TestCase):
67 """strstr_m tests in simple ASCII and unicode strings"""
69 def test_strstr_m(self):
70 # A, B, strstr_m(A, B)
71 cases = [('hello', 'hello', 'hello'),
72 ('hello', 'goodbye', None),
73 ('goodbye', 'hello', None),
74 ('hell', 'hello', None),
75 ('hello', 'hell', 'hello'),
76 ('', '', ''),
77 ('a', '', 'a'),
78 ('', 'a', None),
79 ('a', 'A', None),
80 ('aa', 'aA', None),
81 ('Aa', 'aa', None),
82 ('%v foo', '%v', '%v foo'),
83 ('foo %v foo', '%v', '%v foo'),
84 ('foo %v', '%v', '%v'),
85 ('longstring ' * 100, 'longstring ' * 99, 'longstring ' * 100),
86 ('longstring ' * 99, 'longstring ' * 100, None),
87 ('longstring a' * 99, 'longstring ' * 100 + 'a', None),
88 ('longstring ' * 100 + 'a', 'longstring ' * 100, 'longstring ' * 100 + 'a'),
89 (KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', None),
90 (KATAKANA_LETTER_A + 'bcde', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcde'),
91 ('d' +KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd'),
92 ('d' +KATAKANA_LETTER_A + 'bd', KATAKANA_LETTER_A + 'bcd', None),
94 ('e' + KATAKANA_LETTER_A + 'bcdf', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcdf'),
95 (KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', None),
96 (KATAKANA_LETTER_A * 3, 'a', None),
98 for a, b, expect in cases:
99 self.assertEqual(strstr_m(a, b), expect)