1 from ctypescrypto.oid import Oid,create,cleanup
4 class TestStandard(unittest.TestCase):
7 self.assertEqual(repr(o),"Oid('2.5.4.3')")
8 self.assertEqual(o.dotted(),"2.5.4.3")
9 self.assertEqual(str(o),"2.5.4.3")
10 self.assertEqual(o.shortname(),"CN")
11 self.assertEqual(o.longname(),"commonName")
12 def test_getnid(self):
15 self.assertEqual(o.nid,x.nid)
17 self.assertEqual(hash(o),hash(x))
22 self.assertEqual(o.nid,x.nid)
26 self.assertEqual(o.nid,x.nid)
30 self.assertEqual(o1.nid,o2.nid)
31 def test_fromunicode(self):
33 self.assertEqual(o.shortname(),'CN')
34 def test_wrongoid(self):
35 with self.assertRaises(ValueError):
36 o=Oid("1.2.3.4.5.6.7.8.10.111.1111")
37 def test_wrongname(self):
38 with self.assertRaises(ValueError):
39 o=Oid("No such oid in the database")
40 def test_wrongnid(self):
41 with self.assertRaises(ValueError):
43 def test_wrongtype(self):
44 with self.assertRaises(TypeError):
47 class TestCustom(unittest.TestCase):
48 def _no_testCreate(self):
50 sn="CtypesCryptoTestOid"
51 long_name="Test Oid in CryptoCom namespace"
52 o=create(d,sn,long_name)
53 self.assertEqual(str(o),d)
54 self.assertEqual(o.shortname(),sn)
55 self.assertEqual(o.longname(),long_name)
58 sn="CtypesCryptoTestOid"
59 long_name="Test Oid In CryptoCom Namespace"
60 o=create(d,sn,long_name)
63 def _no_testFromObj(self):
64 from ctypescrypto import libcrypto
65 from ctypes import c_int, c_char_p, c_void_p
66 libcrypto.OBJ_txt2obj.argtypes = (c_char_p, c_int)
67 libcrypto.OBJ_txt2obj.restype = c_void_p
68 obj= libcrypto.OBJ_txt2obj("1.2.643.100.9",1)
70 self.assertEqual(str(oid),'1.2.643.100.9')
72 # Always call cleanup before next test
78 if __name__ == '__main__':