blob: ddcff150f5f0f005c91d27d5a09316b15a2f9b96 [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);
Shock Jiangcde28712014-10-19 21:17:20 -070035 rrset1.setZone(nullptr);
Shock Jiangb7370c22014-09-05 14:43:22 -070036 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);
Shock Jiangcde28712014-10-19 21:17:20 -070043 BOOST_CHECK_EQUAL(rrset1.getZone() == nullptr, true);
Shock Jiangb7370c22014-09-05 14:43:22 -070044 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
Shock Jiangb7370c22014-09-05 14:43:22 -070050 ndns::Rrset rrset2(rrset1);
Shock Jiangcde28712014-10-19 21:17:20 -070051 // rrset2.setZone(nullptr);
52 BOOST_CHECK_EQUAL(rrset1, rrset2); // zone point to nullptr
Shock Jiangb7370c22014-09-05 14:43:22 -070053
54 rrset2.setId(2);
Shock Jiangcde28712014-10-19 21:17:20 -070055 BOOST_CHECK_EQUAL(rrset1, rrset2); // with different Id
Shock Jiangb7370c22014-09-05 14:43:22 -070056
Shock Jiangcde28712014-10-19 21:17:20 -070057 Zone zone("/ndn");
58 Zone zone2("/ndn2");
Shock Jiangb7370c22014-09-05 14:43:22 -070059 rrset2.setZone(&zone);
Shock Jiangcde28712014-10-19 21:17:20 -070060 BOOST_CHECK_NE(rrset1, rrset2); // with different zone name
61
62 rrset1.setZone(&zone);
63 BOOST_CHECK_EQUAL(rrset1, rrset2);
64
65 Zone zone3("/ndn");
66 rrset1.setZone(&zone3);
67 BOOST_CHECK_EQUAL(rrset1, rrset2);
68
69 rrset1.setZone(&zone2);
Shock Jiangb7370c22014-09-05 14:43:22 -070070 BOOST_CHECK_NE(rrset1, rrset2);
71
72 rrset2 = rrset1;
Shock Jiangb7370c22014-09-05 14:43:22 -070073 rrset2.setLabel(Name("/www/2"));
74 BOOST_CHECK_NE(rrset1, rrset2);
75 rrset2 = rrset1;
76
77 rrset2.setType(name::Component("TXT"));
78 BOOST_CHECK_NE(rrset1, rrset2);
79 rrset2 = rrset1;
80
81 rrset2.setVersion(name::Component::fromVersion(2));
82 BOOST_CHECK_NE(rrset1, rrset2);
83 rrset2 = rrset1;
84
85 rrset2.setTtl(time::seconds(1));
86 BOOST_CHECK_EQUAL(rrset1, rrset2);
87 rrset2 = rrset1;
88
89 rrset2.setData(Name("/test/2").wireEncode());
90 BOOST_CHECK_EQUAL(rrset1, rrset2);
91 rrset2 = rrset1;
92}
93
94BOOST_AUTO_TEST_CASE(Ostream)
95{
96 ndns::Zone zone("/test");
97 ndns::Rrset rrset(&zone);
98
99 rrset.setId(1);
100 rrset.setLabel("/www/1");
101 rrset.setType(name::Component("NS"));
102 rrset.setVersion(name::Component::fromVersion(1));
103 rrset.setTtl(time::seconds(10));
104
105 boost::test_tools::output_test_stream os;
106 os << rrset;
107 BOOST_CHECK(os.is_equal("Rrset: Id=1 Zone=(Zone: Id=0 Name=/test)"
108 " Label=/www/1 Type=NS Version=%FD%01"));
109}
110
111BOOST_AUTO_TEST_SUITE_END()
112
113} // namespace tests
114} // namespace ndns
115} // namespace ndn