blob: db51d27cb725b11cb8f429a674992e2e1867e0ae [file] [log] [blame]
Shock Jiangb7370c22014-09-05 14:43:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
Shock Jiangeb37bef2014-10-19 20:21:46 -070020#include "daemon/rrset.hpp"
21#include "../../boost-test.hpp"
Shock Jiangb7370c22014-09-05 14:43:22 -070022
23#include <ndn-cxx/name.hpp>
24
25namespace ndn {
26namespace ndns {
27namespace tests {
28
29BOOST_AUTO_TEST_SUITE(Rrset)
30
31BOOST_AUTO_TEST_CASE(Basic)
32{
33 ndns::Rrset rrset1;
34 rrset1.setId(1);
35 rrset1.setZone(0);
36 rrset1.setLabel("/www/1");
37 rrset1.setType(name::Component("NS"));
38 rrset1.setVersion(name::Component::fromVersion(1));
39 rrset1.setTtl(time::seconds(10));
40 rrset1.setData(Name("/test/1").wireEncode());
41
42 BOOST_CHECK_EQUAL(rrset1.getId(), 1);
43 BOOST_CHECK_EQUAL(rrset1.getZone(), static_cast<Zone*>(0));
44 BOOST_CHECK_EQUAL(rrset1.getLabel(), Name("/www/1"));
45 BOOST_CHECK_EQUAL(rrset1.getType(), name::Component("NS"));
46 BOOST_CHECK_EQUAL(rrset1.getVersion(), name::Component::fromVersion(1));
47 BOOST_CHECK_EQUAL(rrset1.getTtl(), time::seconds(10));
48 BOOST_CHECK(rrset1.getData() == Name("/test/1").wireEncode());
49
50 Name zoneName("/net/ndnsim");
51
52 ndns::Rrset rrset2(rrset1);
53 BOOST_CHECK_EQUAL(rrset1, rrset2);
54
55 rrset2.setId(2);
56 BOOST_CHECK_EQUAL(rrset1, rrset2);
57 rrset2 = rrset1;
58
59 Zone zone;
60 rrset2.setZone(&zone);
61 BOOST_CHECK_NE(rrset1, rrset2);
62
63 rrset2 = rrset1;
64 BOOST_CHECK_EQUAL(rrset1, rrset2);
65
66 rrset2.setLabel(Name("/www/2"));
67 BOOST_CHECK_NE(rrset1, rrset2);
68 rrset2 = rrset1;
69
70 rrset2.setType(name::Component("TXT"));
71 BOOST_CHECK_NE(rrset1, rrset2);
72 rrset2 = rrset1;
73
74 rrset2.setVersion(name::Component::fromVersion(2));
75 BOOST_CHECK_NE(rrset1, rrset2);
76 rrset2 = rrset1;
77
78 rrset2.setTtl(time::seconds(1));
79 BOOST_CHECK_EQUAL(rrset1, rrset2);
80 rrset2 = rrset1;
81
82 rrset2.setData(Name("/test/2").wireEncode());
83 BOOST_CHECK_EQUAL(rrset1, rrset2);
84 rrset2 = rrset1;
85}
86
87BOOST_AUTO_TEST_CASE(Ostream)
88{
89 ndns::Zone zone("/test");
90 ndns::Rrset rrset(&zone);
91
92 rrset.setId(1);
93 rrset.setLabel("/www/1");
94 rrset.setType(name::Component("NS"));
95 rrset.setVersion(name::Component::fromVersion(1));
96 rrset.setTtl(time::seconds(10));
97
98 boost::test_tools::output_test_stream os;
99 os << rrset;
100 BOOST_CHECK(os.is_equal("Rrset: Id=1 Zone=(Zone: Id=0 Name=/test)"
101 " Label=/www/1 Type=NS Version=%FD%01"));
102}
103
104BOOST_AUTO_TEST_SUITE_END()
105
106} // namespace tests
107} // namespace ndns
108} // namespace ndn