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.
27 from unicodenames
import *
30 from samba
import strcasecmp_m
, strstr_m
41 class strcasecmp_m_Tests(samba
.tests
.TestCase
):
42 """String comparisons in simple ASCII and unicode"""
43 def test_strcasecmp_m(self
):
44 # A, B, strcasecmp(A, B)
45 cases
= [('hello', 'hello', 0),
46 ('hello', 'goodbye', +1),
47 ('goodbye', 'hello', -1),
48 ('hell', 'hello', -1),
55 ('longstring ' * 100, 'longstring ' * 100, 0),
56 ('longstring ' * 100, 'longstring ' * 100 + 'a', -1),
57 ('longstring ' * 100 + 'a', 'longstring ' * 100, +1),
58 (KATAKANA_LETTER_A
, KATAKANA_LETTER_A
, 0),
59 (KATAKANA_LETTER_A
, 'a', 1),
61 for a
, b
, expect
in cases
:
62 self
.assertEquals(signum(strcasecmp_m(a
.encode('utf-8'),
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'),
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 if expect
is not None:
100 expect
= expect
.encode('utf-8')
101 self
.assertEquals(strstr_m(a
.encode('utf-8'),