dcerpc py tests: improve argument formatting
[amitay/samba.git] / python / samba / tests / glue.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 """Tests for the _glue Python bindings."""
19
20 from samba import _glue
21 from samba import param
22 import samba.tests
23
24
25 class GlueTests(samba.tests.TestCase):
26
27     def setUp(self):
28         super(GlueTests, self).setUp()
29
30     def test_generate_random_str(self):
31         string = _glue.generate_random_str(10)
32         self.assertEqual(type(string), str)
33         self.assertEqual(len(string), 10)
34
35     def test_generate_random_password(self):
36         password = _glue.generate_random_password(5, 10)
37         self.assertEqual(type(password), str)
38         self.assertTrue(5 <= len(password) <= 10)
39
40     def test_unix2nttime(self):
41         self.assertEqual(_glue.unix2nttime(1), 116444736010000000)
42
43     def test_nttime2unix(self):
44         self.assertEqual(_glue.nttime2unix(116444736010000000), 1)
45
46     def test_nttime2string(self):
47         string = _glue.nttime2string(116444736010000000)
48         self.assertEqual(type(string), str)
49         self.assertIn('1970', string)
50
51     def test_debug_level(self):
52         prev_level = _glue.get_debug_level()
53         try:
54             self.assertIsNone(_glue.set_debug_level(0))
55             self.assertEqual(_glue.get_debug_level(), 0)
56             self.assertIsNone(_glue.set_debug_level(5))
57             self.assertEqual(_glue.get_debug_level(), 5)
58         finally:
59             _glue.set_debug_level(prev_level)
60
61     def test_interface_ips(self):
62         lp = param.LoadParm()
63         ips = _glue.interface_ips(lp)
64         self.assertEqual(type(ips), list)
65
66     def test_strcasecmp(self):
67         self.assertEqual(_glue.strcasecmp_m('aA', 'Aa'), 0)
68         self.assertNotEqual(_glue.strcasecmp_m('ab', 'Aa'), 0)
69
70     def test_strstr_m(self):
71         string = 'testing_string_num__one'
72         self.assertEqual(_glue.strstr_m(string, '_'), '_string_num__one')
73         self.assertEqual(_glue.strstr_m(string, '__'), '__one')
74         self.assertEqual(_glue.strstr_m(string, 'ring'), 'ring_num__one')