3 # subunit test cases for Samba string functions.
5 # Copyright (C) 2003 by Martin Pool <mbp@samba.org>
6 # Copyright (C) 2011 Andrew Bartlett
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, see <http://www.gnu.org/licenses/>.
21 # XXX: All this code assumes that the Unix character set is UTF-8,
22 # which is the most common setting. I guess it would be better to
23 # force it to that value while running the tests. I'm not sure of the
24 # best way to do that yet.
29 from unicodenames import *
32 from samba import strcasecmp_m, strstr_m
43 class strcasecmp_m_Tests(samba.tests.TestCase):
44 """String comparisons in simple ASCII and unicode"""
45 def test_strcasecmp_m(self):
46 # A, B, strcasecmp(A, B)
47 cases = [('hello', 'hello', 0),
48 ('hello', 'goodbye', +1),
49 ('goodbye', 'hello', -1),
50 ('hell', 'hello', -1),
57 ('longstring ' * 100, 'longstring ' * 100, 0),
58 ('longstring ' * 100, 'longstring ' * 100 + 'a', -1),
59 ('longstring ' * 100 + 'a', 'longstring ' * 100, +1),
60 (KATAKANA_LETTER_A, KATAKANA_LETTER_A, 0),
61 (KATAKANA_LETTER_A, 'a', 1),
63 for a, b, expect in cases:
64 self.assertEquals(signum(strcasecmp_m(a.encode('utf-8'),
68 class strstr_m_Tests(samba.tests.TestCase):
69 """strstr_m tests in simple ASCII and unicode strings"""
70 def test_strstr_m(self):
71 # A, B, strstr_m(A, B)
72 cases = [('hello', 'hello', 'hello'),
73 ('hello', 'goodbye', None),
74 ('goodbye', 'hello', None),
75 ('hell', 'hello', None),
76 ('hello', 'hell', 'hello'),
83 ('%v foo', '%v', '%v foo'),
84 ('foo %v foo', '%v', '%v foo'),
85 ('foo %v', '%v', '%v'),
86 ('longstring ' * 100, 'longstring ' * 99, 'longstring ' * 100),
87 ('longstring ' * 99, 'longstring ' * 100, None),
88 ('longstring a' * 99, 'longstring ' * 100 + 'a', None),
89 ('longstring ' * 100 + 'a', 'longstring ' * 100, 'longstring ' * 100 + 'a'),
90 (KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', None),
91 (KATAKANA_LETTER_A + 'bcde', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcde'),
92 ('d'+KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd'),
93 ('d'+KATAKANA_LETTER_A + 'bd', KATAKANA_LETTER_A + 'bcd', None),
95 ('e'+KATAKANA_LETTER_A + 'bcdf', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcdf'),
96 (KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', None),
97 (KATAKANA_LETTER_A*3, 'a', None),
99 for a, b, expect in cases:
100 if expect is not None:
101 expect = expect.encode('utf-8')
102 self.assertEquals(strstr_m(a.encode('utf-8'),