1 # Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
3 # Permission to use, copy, modify, and distribute this software and its
4 # documentation for any purpose with or without fee is hereby granted,
5 # provided that the above copyright notice and this permission notice
6 # appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 class NameTestCase(unittest
.TestCase
):
24 self
.ndict
= dns
.namedict
.NameDict()
25 n1
= dns
.name
.from_text('foo.bar.')
26 n2
= dns
.name
.from_text('bar.')
29 self
.rndict
= dns
.namedict
.NameDict()
30 n1
= dns
.name
.from_text('foo.bar', None)
31 n2
= dns
.name
.from_text('bar', None)
36 self
.failUnless(self
.ndict
.max_depth
== 3)
38 def testLookup1(self
):
39 k
= dns
.name
.from_text('foo.bar.')
40 self
.failUnless(self
.ndict
[k
] == 1)
42 def testLookup2(self
):
43 k
= dns
.name
.from_text('foo.bar.')
44 self
.failUnless(self
.ndict
.get_deepest_match(k
)[1] == 1)
46 def testLookup3(self
):
47 k
= dns
.name
.from_text('a.b.c.foo.bar.')
48 self
.failUnless(self
.ndict
.get_deepest_match(k
)[1] == 1)
50 def testLookup4(self
):
51 k
= dns
.name
.from_text('a.b.c.bar.')
52 self
.failUnless(self
.ndict
.get_deepest_match(k
)[1] == 2)
54 def testLookup5(self
):
56 n
= dns
.name
.from_text('a.b.c.')
57 (k
, v
) = self
.ndict
.get_deepest_match(n
)
58 self
.failUnlessRaises(KeyError, bad
)
60 def testLookup6(self
):
62 (k
, v
) = self
.ndict
.get_deepest_match(dns
.name
.empty
)
63 self
.failUnlessRaises(KeyError, bad
)
65 def testLookup7(self
):
66 self
.ndict
[dns
.name
.empty
] = 100
67 n
= dns
.name
.from_text('a.b.c.')
68 (k
, v
) = self
.ndict
.get_deepest_match(n
)
69 self
.failUnless(v
== 100)
71 def testLookup8(self
):
73 self
.ndict
['foo'] = 100
74 self
.failUnlessRaises(ValueError, bad
)
76 def testRelDepth(self
):
77 self
.failUnless(self
.rndict
.max_depth
== 2)
79 def testRelLookup1(self
):
80 k
= dns
.name
.from_text('foo.bar', None)
81 self
.failUnless(self
.rndict
[k
] == 1)
83 def testRelLookup2(self
):
84 k
= dns
.name
.from_text('foo.bar', None)
85 self
.failUnless(self
.rndict
.get_deepest_match(k
)[1] == 1)
87 def testRelLookup3(self
):
88 k
= dns
.name
.from_text('a.b.c.foo.bar', None)
89 self
.failUnless(self
.rndict
.get_deepest_match(k
)[1] == 1)
91 def testRelLookup4(self
):
92 k
= dns
.name
.from_text('a.b.c.bar', None)
93 self
.failUnless(self
.rndict
.get_deepest_match(k
)[1] == 2)
95 def testRelLookup7(self
):
96 self
.rndict
[dns
.name
.empty
] = 100
97 n
= dns
.name
.from_text('a.b.c', None)
98 (k
, v
) = self
.rndict
.get_deepest_match(n
)
99 self
.failUnless(v
== 100)
101 if __name__
== '__main__':