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