Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 7f27ec1 | 2022-03-10 20:10:54 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 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 Jiang | eb37bef | 2014-10-19 20:21:46 -0700 | [diff] [blame] | 20 | #include "daemon/rrset.hpp" |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 21 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 22 | #include "boost-test.hpp" |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 28229df | 2020-01-04 15:11:25 -0500 | [diff] [blame] | 24 | #include <boost/test/tools/output_test_stream.hpp> |
Davide Pesavento | 28229df | 2020-01-04 15:11:25 -0500 | [diff] [blame] | 25 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 26 | namespace ndn { |
| 27 | namespace ndns { |
| 28 | namespace tests { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(Rrset) |
| 31 | |
| 32 | BOOST_AUTO_TEST_CASE(Basic) |
| 33 | { |
| 34 | ndns::Rrset rrset1; |
| 35 | rrset1.setId(1); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 36 | rrset1.setZone(nullptr); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 37 | rrset1.setLabel("/www/1"); |
| 38 | rrset1.setType(name::Component("NS")); |
| 39 | rrset1.setVersion(name::Component::fromVersion(1)); |
| 40 | rrset1.setTtl(time::seconds(10)); |
| 41 | rrset1.setData(Name("/test/1").wireEncode()); |
| 42 | |
| 43 | BOOST_CHECK_EQUAL(rrset1.getId(), 1); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(rrset1.getZone() == nullptr, true); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(rrset1.getLabel(), Name("/www/1")); |
| 46 | BOOST_CHECK_EQUAL(rrset1.getType(), name::Component("NS")); |
| 47 | BOOST_CHECK_EQUAL(rrset1.getVersion(), name::Component::fromVersion(1)); |
| 48 | BOOST_CHECK_EQUAL(rrset1.getTtl(), time::seconds(10)); |
| 49 | BOOST_CHECK(rrset1.getData() == Name("/test/1").wireEncode()); |
| 50 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 51 | ndns::Rrset rrset2(rrset1); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 52 | // rrset2.setZone(nullptr); |
| 53 | BOOST_CHECK_EQUAL(rrset1, rrset2); // zone point to nullptr |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 54 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 55 | bool isLess = rrset1 < rrset2; |
| 56 | BOOST_CHECK_EQUAL(isLess, false); |
| 57 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 58 | rrset2.setId(2); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 59 | BOOST_CHECK_EQUAL(rrset1, rrset2); // with different Id |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 60 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 61 | Zone zone("/ndn"); |
| 62 | Zone zone2("/ndn2"); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 63 | rrset2.setZone(&zone); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 64 | BOOST_CHECK_NE(rrset1, rrset2); // with different zone name |
| 65 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 66 | BOOST_CHECK_THROW(isLess = rrset1 < rrset2, std::runtime_error); |
| 67 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 68 | rrset1.setZone(&zone); |
| 69 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
| 70 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 71 | isLess = rrset1 < rrset2; |
| 72 | BOOST_CHECK_EQUAL(isLess, false); |
| 73 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 74 | Zone zone3("/ndn"); |
| 75 | rrset1.setZone(&zone3); |
| 76 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
| 77 | |
| 78 | rrset1.setZone(&zone2); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 79 | BOOST_CHECK_NE(rrset1, rrset2); |
| 80 | |
| 81 | rrset2 = rrset1; |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 82 | rrset2.setLabel(Name("/www/2")); |
| 83 | BOOST_CHECK_NE(rrset1, rrset2); |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 84 | |
| 85 | isLess = rrset1 < rrset2; |
| 86 | BOOST_CHECK_EQUAL(isLess, true); |
| 87 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 88 | rrset2 = rrset1; |
| 89 | |
| 90 | rrset2.setType(name::Component("TXT")); |
| 91 | BOOST_CHECK_NE(rrset1, rrset2); |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 92 | |
| 93 | isLess = rrset1 < rrset2; |
| 94 | BOOST_CHECK_EQUAL(isLess, true); |
| 95 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 96 | rrset2 = rrset1; |
| 97 | |
| 98 | rrset2.setVersion(name::Component::fromVersion(2)); |
| 99 | BOOST_CHECK_NE(rrset1, rrset2); |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 100 | |
| 101 | isLess = rrset1 < rrset2; |
| 102 | BOOST_CHECK_EQUAL(isLess, true); |
| 103 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 104 | rrset2 = rrset1; |
| 105 | |
| 106 | rrset2.setTtl(time::seconds(1)); |
| 107 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
| 108 | rrset2 = rrset1; |
| 109 | |
| 110 | rrset2.setData(Name("/test/2").wireEncode()); |
| 111 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
| 112 | rrset2 = rrset1; |
| 113 | } |
| 114 | |
| 115 | BOOST_AUTO_TEST_CASE(Ostream) |
| 116 | { |
| 117 | ndns::Zone zone("/test"); |
| 118 | ndns::Rrset rrset(&zone); |
| 119 | |
| 120 | rrset.setId(1); |
| 121 | rrset.setLabel("/www/1"); |
| 122 | rrset.setType(name::Component("NS")); |
| 123 | rrset.setVersion(name::Component::fromVersion(1)); |
| 124 | rrset.setTtl(time::seconds(10)); |
| 125 | |
| 126 | boost::test_tools::output_test_stream os; |
| 127 | os << rrset; |
| 128 | BOOST_CHECK(os.is_equal("Rrset: Id=1 Zone=(Zone: Id=0 Name=/test)" |
Eric Newberry | b8adcdf | 2021-03-25 18:35:50 -0700 | [diff] [blame] | 129 | " Label=/www/1 Type=NS Version=v=1")); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_SUITE_END() |
| 133 | |
| 134 | } // namespace tests |
| 135 | } // namespace ndns |
| 136 | } // namespace ndn |