Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Jiang | eb37bef | 2014-10-19 20:21:46 -0700 | [diff] [blame] | 20 | #include "daemon/rrset.hpp" |
| 21 | #include "../../boost-test.hpp" |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 22 | |
| 23 | #include <ndn-cxx/name.hpp> |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace ndns { |
| 27 | namespace tests { |
| 28 | |
| 29 | BOOST_AUTO_TEST_SUITE(Rrset) |
| 30 | |
| 31 | BOOST_AUTO_TEST_CASE(Basic) |
| 32 | { |
| 33 | ndns::Rrset rrset1; |
| 34 | rrset1.setId(1); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 35 | rrset1.setZone(nullptr); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 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); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 43 | BOOST_CHECK_EQUAL(rrset1.getZone() == nullptr, true); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 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 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 50 | ndns::Rrset rrset2(rrset1); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 51 | // rrset2.setZone(nullptr); |
| 52 | BOOST_CHECK_EQUAL(rrset1, rrset2); // zone point to nullptr |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 53 | |
| 54 | rrset2.setId(2); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(rrset1, rrset2); // with different Id |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 56 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 57 | Zone zone("/ndn"); |
| 58 | Zone zone2("/ndn2"); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 59 | rrset2.setZone(&zone); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 60 | 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 Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 70 | BOOST_CHECK_NE(rrset1, rrset2); |
| 71 | |
| 72 | rrset2 = rrset1; |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 73 | 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 | |
| 94 | BOOST_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 | |
| 111 | BOOST_AUTO_TEST_SUITE_END() |
| 112 | |
| 113 | } // namespace tests |
| 114 | } // namespace ndns |
| 115 | } // namespace ndn |