blob: f9e2704d518a8738bfcef6e2bf5bf1f0a7e7c9b0 [file] [log] [blame]
Shock Jiangb7370c22014-09-05 14:43:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia55a7cc42017-05-14 18:43:34 -07002/*
Davide Pesavento28229df2020-01-04 15:11:25 -05003 * Copyright (c) 2014-2020, Regents of the University of California.
Shock Jiangb7370c22014-09-05 14:43:22 -07004 *
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"
Shock Jiangb7370c22014-09-05 14:43:22 -070021
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080022#include "test-common.hpp"
Shock Jiangb7370c22014-09-05 14:43:22 -070023
Davide Pesavento28229df2020-01-04 15:11:25 -050024#if BOOST_VERSION >= 105900
25#include <boost/test/tools/output_test_stream.hpp>
26#else
27#include <boost/test/output_test_stream.hpp>
28#endif
29
Shock Jiangb7370c22014-09-05 14:43:22 -070030namespace ndn {
31namespace ndns {
32namespace tests {
33
34BOOST_AUTO_TEST_SUITE(Rrset)
35
36BOOST_AUTO_TEST_CASE(Basic)
37{
38 ndns::Rrset rrset1;
39 rrset1.setId(1);
Shock Jiangcde28712014-10-19 21:17:20 -070040 rrset1.setZone(nullptr);
Shock Jiangb7370c22014-09-05 14:43:22 -070041 rrset1.setLabel("/www/1");
42 rrset1.setType(name::Component("NS"));
43 rrset1.setVersion(name::Component::fromVersion(1));
44 rrset1.setTtl(time::seconds(10));
45 rrset1.setData(Name("/test/1").wireEncode());
46
47 BOOST_CHECK_EQUAL(rrset1.getId(), 1);
Shock Jiangcde28712014-10-19 21:17:20 -070048 BOOST_CHECK_EQUAL(rrset1.getZone() == nullptr, true);
Shock Jiangb7370c22014-09-05 14:43:22 -070049 BOOST_CHECK_EQUAL(rrset1.getLabel(), Name("/www/1"));
50 BOOST_CHECK_EQUAL(rrset1.getType(), name::Component("NS"));
51 BOOST_CHECK_EQUAL(rrset1.getVersion(), name::Component::fromVersion(1));
52 BOOST_CHECK_EQUAL(rrset1.getTtl(), time::seconds(10));
53 BOOST_CHECK(rrset1.getData() == Name("/test/1").wireEncode());
54
Shock Jiangb7370c22014-09-05 14:43:22 -070055 ndns::Rrset rrset2(rrset1);
Shock Jiangcde28712014-10-19 21:17:20 -070056 // rrset2.setZone(nullptr);
57 BOOST_CHECK_EQUAL(rrset1, rrset2); // zone point to nullptr
Shock Jiangb7370c22014-09-05 14:43:22 -070058
Yumin Xia55a7cc42017-05-14 18:43:34 -070059 bool isLess = rrset1 < rrset2;
60 BOOST_CHECK_EQUAL(isLess, false);
61
Shock Jiangb7370c22014-09-05 14:43:22 -070062 rrset2.setId(2);
Shock Jiangcde28712014-10-19 21:17:20 -070063 BOOST_CHECK_EQUAL(rrset1, rrset2); // with different Id
Shock Jiangb7370c22014-09-05 14:43:22 -070064
Shock Jiangcde28712014-10-19 21:17:20 -070065 Zone zone("/ndn");
66 Zone zone2("/ndn2");
Shock Jiangb7370c22014-09-05 14:43:22 -070067 rrset2.setZone(&zone);
Shock Jiangcde28712014-10-19 21:17:20 -070068 BOOST_CHECK_NE(rrset1, rrset2); // with different zone name
69
Yumin Xia55a7cc42017-05-14 18:43:34 -070070 BOOST_CHECK_THROW(isLess = rrset1 < rrset2, std::runtime_error);
71
Shock Jiangcde28712014-10-19 21:17:20 -070072 rrset1.setZone(&zone);
73 BOOST_CHECK_EQUAL(rrset1, rrset2);
74
Yumin Xia55a7cc42017-05-14 18:43:34 -070075 isLess = rrset1 < rrset2;
76 BOOST_CHECK_EQUAL(isLess, false);
77
Shock Jiangcde28712014-10-19 21:17:20 -070078 Zone zone3("/ndn");
79 rrset1.setZone(&zone3);
80 BOOST_CHECK_EQUAL(rrset1, rrset2);
81
82 rrset1.setZone(&zone2);
Shock Jiangb7370c22014-09-05 14:43:22 -070083 BOOST_CHECK_NE(rrset1, rrset2);
84
85 rrset2 = rrset1;
Shock Jiangb7370c22014-09-05 14:43:22 -070086 rrset2.setLabel(Name("/www/2"));
87 BOOST_CHECK_NE(rrset1, rrset2);
Yumin Xia55a7cc42017-05-14 18:43:34 -070088
89 isLess = rrset1 < rrset2;
90 BOOST_CHECK_EQUAL(isLess, true);
91
Shock Jiangb7370c22014-09-05 14:43:22 -070092 rrset2 = rrset1;
93
94 rrset2.setType(name::Component("TXT"));
95 BOOST_CHECK_NE(rrset1, rrset2);
Yumin Xia55a7cc42017-05-14 18:43:34 -070096
97 isLess = rrset1 < rrset2;
98 BOOST_CHECK_EQUAL(isLess, true);
99
Shock Jiangb7370c22014-09-05 14:43:22 -0700100 rrset2 = rrset1;
101
102 rrset2.setVersion(name::Component::fromVersion(2));
103 BOOST_CHECK_NE(rrset1, rrset2);
Yumin Xia55a7cc42017-05-14 18:43:34 -0700104
105 isLess = rrset1 < rrset2;
106 BOOST_CHECK_EQUAL(isLess, true);
107
Shock Jiangb7370c22014-09-05 14:43:22 -0700108 rrset2 = rrset1;
109
110 rrset2.setTtl(time::seconds(1));
111 BOOST_CHECK_EQUAL(rrset1, rrset2);
112 rrset2 = rrset1;
113
114 rrset2.setData(Name("/test/2").wireEncode());
115 BOOST_CHECK_EQUAL(rrset1, rrset2);
116 rrset2 = rrset1;
117}
118
119BOOST_AUTO_TEST_CASE(Ostream)
120{
121 ndns::Zone zone("/test");
122 ndns::Rrset rrset(&zone);
123
124 rrset.setId(1);
125 rrset.setLabel("/www/1");
126 rrset.setType(name::Component("NS"));
127 rrset.setVersion(name::Component::fromVersion(1));
128 rrset.setTtl(time::seconds(10));
129
130 boost::test_tools::output_test_stream os;
131 os << rrset;
132 BOOST_CHECK(os.is_equal("Rrset: Id=1 Zone=(Zone: Id=0 Name=/test)"
133 " Label=/www/1 Type=NS Version=%FD%01"));
134}
135
136BOOST_AUTO_TEST_SUITE_END()
137
138} // namespace tests
139} // namespace ndns
140} // namespace ndn