mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
tests/dcerpc/misc.GUID: improve tests
1. Merge tests for different formats into a for loop, make it easy to read and extend. 2. Add test for invalid formats. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
f6db12e236
commit
bb88292cee
@ -23,10 +23,7 @@ from samba.compat import PY3
|
||||
|
||||
text1 = "76f53846-a7c2-476a-ae2c-20e2b80d7b34"
|
||||
text2 = "344edffa-330a-4b39-b96e-2c34da52e8b1"
|
||||
text3_s = "00112233-4455-6677-8899-aabbccddeeff"
|
||||
text3_b = b"00112233-4455-6677-8899-aabbccddeeff"
|
||||
text3_b16 = b"\x33\x22\x11\x00\x55\x44\x77\x66\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
|
||||
text3_h = "33221100554477668899aabbccddeeff"
|
||||
text3 = "00112233-4455-6677-8899-aabbccddeeff"
|
||||
|
||||
|
||||
if PY3:
|
||||
@ -59,21 +56,39 @@ class GUIDTests(samba.tests.TestCase):
|
||||
self.assertEquals(guid1, guid2)
|
||||
self.assertEquals(0, cmp(guid1, guid2))
|
||||
|
||||
def test_bytes_equals_string(self):
|
||||
guid = misc.GUID(text3_b)
|
||||
self.assertEquals(text3_s, str(guid))
|
||||
def test_valid_formats(self):
|
||||
fmts = [
|
||||
"00112233-4455-6677-8899-aabbccddeeff", # 36
|
||||
b"00112233-4455-6677-8899-aabbccddeeff", # 36 as bytes
|
||||
"{00112233-4455-6677-8899-aabbccddeeff}", # 38
|
||||
|
||||
def test_binary_format(self):
|
||||
guid = misc.GUID(text3_b16)
|
||||
self.assertEquals(text3_s, str(guid))
|
||||
"33221100554477668899aabbccddeeff", # 32
|
||||
b"33221100554477668899aabbccddeeff", # 32 as bytes
|
||||
|
||||
def test_strhex_format(self):
|
||||
guid = misc.GUID(text3_h)
|
||||
self.assertEquals(text3_s, str(guid))
|
||||
# 16 as hex bytes
|
||||
b"\x33\x22\x11\x00\x55\x44\x77\x66\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
|
||||
]
|
||||
for fmt in fmts:
|
||||
guid = misc.GUID(fmt)
|
||||
self.assertEquals(text3, str(guid))
|
||||
|
||||
def test_bracketed_format(self):
|
||||
guid = misc.GUID('{'+ text3_s + '}')
|
||||
self.assertEquals(text3_s, str(guid))
|
||||
def test_invalid_formats(self):
|
||||
fmts = [
|
||||
"00112233-4455-6677-8899-aabbccddee", # 34
|
||||
"{33221100554477668899aabbccddeeff}",
|
||||
"33221100554477668899aabbccddee", # 30
|
||||
"\\x33\\x22\\x11\\x00\\x55\\x44\\x77\\x66\\x88\\x99\\xaa\\xbb\\xcc\\xdd\\xee\\xff",
|
||||
r"\x33\x22\x11\x00\x55\x44\x77\x66\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
|
||||
]
|
||||
for fmt in fmts:
|
||||
try:
|
||||
misc.GUID(fmt)
|
||||
except samba.NTSTATUSError:
|
||||
# invalid formats should get this error
|
||||
continue
|
||||
else:
|
||||
# otherwise, test fail
|
||||
self.fail()
|
||||
|
||||
|
||||
class PolicyHandleTests(samba.tests.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user