ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / dcerpc / misc.py
blob6b58e9451c8a675ea515cd85a5cfc37e67e70080
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
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.
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.
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/>.
18 """Tests for samba.dcerpc.misc."""
20 from samba.dcerpc import misc
21 import samba.tests
22 from samba.common import cmp
24 text1 = "76f53846-a7c2-476a-ae2c-20e2b80d7b34"
25 text2 = "344edffa-330a-4b39-b96e-2c34da52e8b1"
26 text3 = "00112233-4455-6677-8899-aabbccddeeff"
29 class GUIDTests(samba.tests.TestCase):
31 def test_str(self):
32 guid = misc.GUID(text1)
33 self.assertEqual(text1, str(guid))
35 def test_repr(self):
36 guid = misc.GUID(text1)
37 self.assertEqual("GUID('%s')" % text1, repr(guid))
39 def test_compare_different(self):
40 guid1 = misc.GUID(text1)
41 guid2 = misc.GUID(text2)
42 self.assertFalse(guid1 == guid2)
43 self.assertGreater(guid1, guid2)
44 self.assertTrue(cmp(guid1, guid2) > 0)
46 def test_compare_same(self):
47 guid1 = misc.GUID(text1)
48 guid2 = misc.GUID(text1)
49 self.assertTrue(guid1 == guid2)
50 self.assertEqual(guid1, guid2)
51 self.assertEqual(0, cmp(guid1, guid2))
53 def test_valid_formats(self):
54 fmts = [
55 "00112233-4455-6677-8899-aabbccddeeff", # 36
56 b"00112233-4455-6677-8899-aabbccddeeff", # 36 as bytes
57 "{00112233-4455-6677-8899-aabbccddeeff}", # 38
59 "33221100554477668899aabbccddeeff", # 32
60 b"33221100554477668899aabbccddeeff", # 32 as bytes
62 # 16 as hex bytes
63 b"\x33\x22\x11\x00\x55\x44\x77\x66\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
65 for fmt in fmts:
66 guid = misc.GUID(fmt)
67 self.assertEqual(text3, str(guid))
69 def test_invalid_formats(self):
70 fmts = [
71 "00112233-4455-6677-8899-aabbccddee", # 34
72 "{33221100554477668899aabbccddeeff}",
73 "33221100554477668899aabbccddee", # 30
74 "\\x33\\x22\\x11\\x00\\x55\\x44\\x77\\x66\\x88\\x99\\xaa\\xbb\\xcc\\xdd\\xee\\xff",
75 r"\x33\x22\x11\x00\x55\x44\x77\x66\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
77 for fmt in fmts:
78 try:
79 misc.GUID(fmt)
80 except samba.NTSTATUSError:
81 # invalid formats should get this error
82 continue
83 else:
84 # otherwise, test fail
85 self.fail()
88 class PolicyHandleTests(samba.tests.TestCase):
90 def test_init(self):
91 x = misc.policy_handle(text1, 1)
92 self.assertEqual(1, x.handle_type)
93 self.assertEqual(text1, str(x.uuid))
95 def test_repr(self):
96 x = misc.policy_handle(text1, 42)
97 self.assertEqual("policy_handle(%d, '%s')" % (42, text1), repr(x))
99 def test_str(self):
100 x = misc.policy_handle(text1, 42)
101 self.assertEqual("%d, %s" % (42, text1), str(x))