blob: a34375b9de7a690b9de1d574a976296a274c5870 [file] [log] [blame]
Shock Jiang698e6ed2014-11-09 11:22:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shibbf7ac82016-07-14 14:45:15 +00003 * Copyright (c) 2014-2016, Regents of the University of California.
Shock Jiang698e6ed2014-11-09 11:22:24 -08004 *
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 "clients/iterative-query-controller.hpp"
21#include "daemon/name-server.hpp"
22#include "logger.hpp"
23#include "../database-test-data.hpp"
24#include "../../boost-test.hpp"
25
26#include <ndn-cxx/util/dummy-client-face.hpp>
27
28#include <boost/asio.hpp>
29
30namespace ndn {
31namespace ndns {
32namespace tests {
Alexander Afanasyevc7c99002015-10-09 17:27:30 -070033
34NDNS_LOG_INIT("IterativeQueryControllerTest")
Shock Jiang698e6ed2014-11-09 11:22:24 -080035
36class QueryControllerFixture : public DbTestData
37{
38public:
39 QueryControllerFixture()
Junxiao Shibbf7ac82016-07-14 14:45:15 +000040 : producerFace(io, {false, true})
41 , consumerFace(io, {false, true})
42 , validator(producerFace)
43 , top(m_root.getName(), m_certName, producerFace, m_session, m_keyChain, validator)
44 , net(m_net.getName(), m_certName, producerFace, m_session, m_keyChain, validator)
45 , ndnsim(m_ndnsim.getName(), m_certName, producerFace, m_session, m_keyChain, validator)
Shock Jiang698e6ed2014-11-09 11:22:24 -080046 {
47 run();
Junxiao Shibbf7ac82016-07-14 14:45:15 +000048 producerFace.onSendInterest.connect([this] (const Interest& interest) {
49 io.post([=] { consumerFace.receive(interest); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070050 });
Junxiao Shibbf7ac82016-07-14 14:45:15 +000051 consumerFace.onSendInterest.connect([this] (const Interest& interest) {
52 io.post([=] { producerFace.receive(interest); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070053 });
Junxiao Shibbf7ac82016-07-14 14:45:15 +000054 producerFace.onSendData.connect([this] (const Data& data) {
55 io.post([=] { consumerFace.receive(data); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070056 });
Junxiao Shibbf7ac82016-07-14 14:45:15 +000057 consumerFace.onSendData.connect([this] (const Data& data) {
58 io.post([=] { producerFace.receive(data); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070059 });
Shock Jiang698e6ed2014-11-09 11:22:24 -080060 }
61
62 void
63 run()
64 {
65 io.poll();
66 io.reset();
67 }
68
69public:
70 boost::asio::io_service io;
Junxiao Shibbf7ac82016-07-14 14:45:15 +000071 ndn::util::DummyClientFace producerFace;
72 ndn::util::DummyClientFace consumerFace;
Shock Jiang698e6ed2014-11-09 11:22:24 -080073
74 Name hint;
75 Validator validator;
76 ndns::NameServer top;
77 ndns::NameServer net;
78 ndns::NameServer ndnsim;
79};
80
81
82BOOST_AUTO_TEST_SUITE(IterativeQueryController)
83
84BOOST_FIXTURE_TEST_CASE(Basic, QueryControllerFixture)
85{
86 using std::string;
87 using ndns::NameServer;
88
89 string hint;
90 Name name = m_ndnsim.getName();
91 Name dstLabel(name.append("www"));
92 name::Component rrType("TXT");
93 time::milliseconds lifetime(4000);
94
95 bool hasDataBack = false;
96 auto ctr = make_shared<ndns::IterativeQueryController>(
97 dstLabel, rrType, lifetime,
98 [&hasDataBack] (const Data&, const Response&) {
99 hasDataBack = true;
100 BOOST_CHECK(true);
101 },
102 [&hasDataBack] (uint32_t errCode, const std::string& errMsg) {
103 BOOST_CHECK(false);
104 },
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000105 consumerFace);
Shock Jiang698e6ed2014-11-09 11:22:24 -0800106
107 // IterativeQueryController is a whole process
108 // the tester should not send Interest one by one
109 // instead of starting it and letting it handle Interest/Data automatically
Shock Jiang5d5928c2014-12-03 13:41:22 -0800110 ctr->setStartComponentIndex(1);
Shock Jiang698e6ed2014-11-09 11:22:24 -0800111
112 ctr->start();
113
114 run();
115 BOOST_CHECK_EQUAL(hasDataBack, true);
116}
117
118BOOST_AUTO_TEST_SUITE_END()
119
120} // namespace tests
121} // namespace ndns
122} // namespace ndn