start of test driver impl.
[python-rwhoisd.git] / test / TestCidr.py
1 # This file is part of python-rwhoisd
2 #
3 # Copyright (C) 2008 David E. Blacka
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 # USA
19
20 import sys, os
21
22 this_path = sys.path[0]
23 rwhoisd_path = os.path.join(this_path, "..", "rwhoisd")
24 if os.path.isdir(rwhoisd_path):
25     sys.path.append(rwhoisd_path)
26
27 import Cidr
28 import unittest, types
29
30 class TestCidr(unittest.TestCase):
31
32     known_good_v4_cidr = [ ("127.00.000.1/24",      0x7F000000, 0xFFFFFF00),
33                            (("127.0.0.1", 32),      0x7F000001, 0xFFFFFFFF),
34                            (("24.232.119.192", 26), 0x18E877C0, 0xFFFFFFC0),
35                            (("24.232.119.0", 24),   0x18E87700, 0xFFFFFF00),
36                            (("24.224.0.0", 11),     0x18E00000, 0xFFE00000),
37                            ("216.168.111.0/27",     0xD8A86F00, 0xFFFFFFE0),
38                            ("127.0.0.2/31",         0x7F000002, 0xFFFFFFFE),
39                            ("127.0.0.16/32",        0x7F000010, 0xFFFFFFFF) ]
40
41     known_good_v6_cidr = [ ("3ffe:4:201e:beef::0/64", 
42                             0x3FFE0004201EBEEF0000000000000000L, 
43                             0xFFFFFFFFFFFFFFFF0000000000000000L),
44                            ("2001:3c01::/32", 
45                             0x20013C01000000000000000000000000L, 
46                             0xFFFFFFFF000000000000000000000000L),
47                            (("3ffe:b03d:fc1e::2002:1010:deaC", 126),
48                             0x3FFEB03DFC1E0000000020021010DEACL,
49                             0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCL),
50                            ("3ffe:b03d:fc1e:2002:1010:2a2a:7:1",
51                             0x3FFEB03dFC1E200210102A2A00070001L,
52                             0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL),
53                            ("3ffe:b03d:fc1e:2002:1010:2a2a:7:1/32",
54                             0x3FFEB03D000000000000000000000000L,
55                             0xFFFFFFFF000000000000000000000000L) ]
56
57
58     def testCreateV4(self):
59         """createV4 should give known results with known input."""
60         for args, value, mask in self.known_good_v4_cidr:
61             if type(args) == types.TupleType:
62                 cidr = Cidr.CidrV4(args[0], args[1])
63             else:
64                 cidr = Cidr.CidrV4(args)
65             self.assertEquals(cidr.numaddr, value)
66             self.assertEquals(cidr.mask, mask)
67
68     def testCreateV6(self):
69         "createV6 should give known results with known input."""
70         for args, value, mask in self.known_good_v6_cidr:
71             if type(args) == types.TupleType:
72                 cidr = Cidr.CidrV6(args[0], args[1])
73             else:
74                 cidr = Cidr.CidrV6(args)
75             self.assertEquals(cidr.numaddr, value)
76             self.assertEquals(cidr.mask, mask)
77
78     def testCreate(self):
79         """create should give known results with known input."""
80         all_good = self.known_good_v4_cidr + self.known_good_v6_cidr
81         for args, value, mask in all_good:
82             if type(args) == types.TupleType:
83                 cidr = Cidr.new(args[0], args[1])
84             else:
85                 cidr = Cidr.new(args)
86             self.assertEquals(cidr.numaddr, value)
87             self.assertEquals(cidr.mask, mask)
88
89
90     def testSort(self):
91         pass
92
93     def testSupernet(self):
94         pass
95
96     def testSubnet(self):
97         pass
98
99     def testNetblockV4(self):
100         pass
101
102     def testNetblockV6(self):
103         pass
104
105
106 if __name__ == "__main__":
107     unittest.main()