Patch from Steve Langasek <corlon@netexpress.net>
[samba.git] / source3 / stf / strings.py
1 #! /usr/bin/python
2
3 # Comfychair test cases for Samba string functions.
4
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.
11
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.
16
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
21
22 import sys, re, comfychair
23
24 def signum(a):
25     if a < 0:
26         return -1
27     elif a > 0:
28         return +1
29     else:
30         return 0
31     
32
33 class StrCaseCmp_Ascii_Tests(comfychair.TestCase):
34     """String comparisons in simple ASCII""" 
35     def run_strcmp(self, a, b, expect):
36         out = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a, b))
37         if signum(int(out)) != expect:
38             self.fail("comparison failed:\n"
39                       "  a=%s\n"
40                       "  b=%s\n"
41                       "  expected=%s\n"
42                       "  result=%s\n" % (`a`, `b`, `expect`, `out`))
43
44     def runtest(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                  ]
60         for a, b, expect in cases:
61             self.run_strcmp(a, b, expect)
62         
63 # Define the tests exported by this module
64 tests = [StrCaseCmp_Ascii_Tests]
65
66 # Handle execution of this file as a main program
67 if __name__ == '__main__':
68     comfychair.main(tests)
69