1 # This file is part of python-rwhoisd
3 # Copyright (C) 2008 David E. Blacka
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.
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.
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
23 import unittest, types
26 class TestGood(unittest.TestCase):
28 data = [ "::", "::7", "f::", "ab:0:0:c:0:0:0:d", "ab:0:0:0:c:0:0:d",
29 "1:2:3:4:5:6:7:8", "1:2:3::7:8", "2001:3c09:102::23:af",
30 "::ffff:1.2.3.4", "1:2:3:4:5:6:4.3.2.1" ]
33 for addr in self.data:
34 a = v6addr.v6str_to_addr(addr)
35 b = v6addr.v6addr_to_str(a)
36 c = v6addr.v6str_to_addr(b)
37 self.assertEquals(a, c)
40 class TestBad(unittest.TestCase):
42 data = [ ":", ":::", "1::2::3", "::3::", "::1.2.3", "12345::1",
43 "1:2:3:4:5:6:7:4.3.2.1" ]
46 for addr in self.data:
47 self.assertRaises(socket.error, v6addr.v6str_to_addr, addr)
50 class TestNormalize(unittest.TestCase):
52 data = [ ("0:0:0:0:0:0:0:0", "::"), ("0::0:0:7", "::7"),
53 ("00ab:00:00:c:00:00:00:d", "ab:0:0:c::d"),
54 ("00ab:0000:0000:0000:000c:0000:0000:000d", "ab::c:0:0:d"),
55 ("1:02:3:04:5:006:7:0008", "1:2:3:4:5:6:7:8"),
56 ("::FFFF:1.2.3.4", "::ffff:102:304") ]
58 def testNormalize(self):
59 for addr, b in self.data:
60 numaddr = v6addr.v6str_to_addr(addr)
61 a = v6addr.v6addr_to_str(numaddr)
62 self.assertEquals(a, b)
64 if __name__ == "__main__":