blob: cb2e47e89de5fe2eb4e9a23acd4d72eb38de68e9 [file] [log] [blame]
Shock Jiang6cce21a2014-09-07 10:14:12 -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
20#include "ndns-label.hpp"
21#include "../boost-test.hpp"
22
23namespace ndn {
24namespace ndns {
25namespace tests {
26
27BOOST_AUTO_TEST_SUITE(NdnsLabel)
28
29BOOST_AUTO_TEST_CASE(MatchInterest)
30{
31 using namespace label;
32 Name hint("/att");
33 Name zone("/net/ndnsim");
34
35 Interest interest1("/att/%F0./net/ndnsim/NDNS/www/dsk-111/NS");
36 Interest interest2("/att/%F0./net/ndnsim/NDNS/www/dsk-111/NS/%FD%00");
37
38 MatchResult re;
39 BOOST_CHECK_EQUAL(matchName(interest1, hint, zone, re), true);
40 BOOST_CHECK_EQUAL(re.rrLabel, Name("/www/dsk-111"));
41 BOOST_CHECK_EQUAL(re.rrType, name::Component("NS"));
42 BOOST_CHECK_EQUAL(re.version, name::Component());
43
44 BOOST_CHECK_EQUAL(matchName(interest2, hint, zone, re), true);
45 BOOST_CHECK_EQUAL(re.rrLabel, Name("/www/dsk-111/NS"));
46 BOOST_CHECK_EQUAL(re.rrType, name::Component::fromEscapedString("%FD%00"));
47 BOOST_CHECK_EQUAL(re.version, name::Component());
48}
49
50BOOST_AUTO_TEST_CASE(MatchData)
51{
52 using namespace label;
53 Name hint("/att");
54 Name zone("/net/ndnsim");
55
56 Data data1("/att/%F0./net/ndnsim/NDNS/www/dsk-111/NS/%FD%00");
57 Data data2("/att/%F0./net/ndnsim/NDNS/www/dsk-111/NS");
58
59 MatchResult re;
60 BOOST_CHECK_EQUAL(matchName(data1, hint, zone, re), true);
61 BOOST_CHECK_EQUAL(re.rrLabel, Name("/www/dsk-111"));
62 BOOST_CHECK_EQUAL(re.rrType, name::Component("NS"));
63 BOOST_REQUIRE_NO_THROW(re.version.toVersion());
64 BOOST_CHECK_EQUAL(re.version.toVersion(), 0);
65
66 BOOST_CHECK_EQUAL(matchName(data2, hint, zone, re), true);
67 BOOST_CHECK_EQUAL(re.rrLabel, Name("/www"));
68 BOOST_CHECK_EQUAL(re.rrType, name::Component("dsk-111"));
69 BOOST_REQUIRE_THROW(re.version.toVersion(), ndn::tlv::Error);
70}
71
72BOOST_AUTO_TEST_SUITE_END()
73
74} // namespace tests
75} // namespace ndns
76} // namespace ndn