1# Copyright (C) 2014 Red Hat, Inc.
2# Author: Petr Spacek <pspacek@redhat.com>
3#
4# Permission to use, copy, modify, and distribute this software and its
5# documentation for any purpose with or without fee is hereby granted,
6# provided that the above copyright notice and this permission notice
7# appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17import unittest
18
19import dns.rrset
20import dns.rdtypes.ANY.LOC
21
22class RdtypeAnyLocTestCase(unittest.TestCase):
23
24    def testEqual1(self):
25        '''Test default values for size, horizontal and vertical precision.'''
26        r1 = dns.rrset.from_text('foo', 300, 'IN', 'LOC',
27                                 '49 11 42.400 N 16 36 29.600 E 227.64m')
28        r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc',
29                                 '49 11 42.400 N 16 36 29.600 E 227.64m '
30                                 '1.00m 10000.00m 10.00m')
31        self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
32
33    def testEqual2(self):
34        '''Test default values for size, horizontal and vertical precision.'''
35        r1 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400, 1),
36                                     (16, 36, 29, 600, 1),
37                                     22764.0) # centimeters
38        r2 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400, 1),
39                                     (16, 36, 29, 600, 1),
40                                     22764.0, # centimeters
41                                     100.0, 1000000.00, 1000.0)  # centimeters
42        self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
43
44    def testEqual3(self):
45        '''Test size, horizontal and vertical precision parsers: 100 cm == 1 m.
46
47        Parsers in from_text() and __init__() have to produce equal results.'''
48        r1 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400, 1),
49                                     (16, 36, 29, 600, 1), 22764.0,
50                                     200.0, 1000.00, 200.0)      # centimeters
51        r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc',
52                                 '49 11 42.400 N 16 36 29.600 E 227.64m '
53                                 '2.00m 10.00m 2.00m')[0]
54        self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
55
56    def testEqual4(self):
57        '''Test size, horizontal and vertical precision parsers without unit.
58
59        Parsers in from_text() and __init__() have produce equal result
60        for values with and without trailing "m".'''
61        r1 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400, 1),
62                                     (16, 36, 29, 600, 1), 22764.0,
63                                     200.0, 1000.00, 200.0)      # centimeters
64        r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc',
65                                 '49 11 42.400 N 16 36 29.600 E 227.64 '
66                                 '2 10 2')[0] # meters without explicit unit
67        self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
68
69if __name__ == '__main__':
70    unittest.main()
71