blob: 93bbb4e63b4abeb19c261dbf6f697556d5684a16 [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"
Shock Jiang698e6ed2014-11-09 11:22:24 -080022
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080023#include "test-common.hpp"
24#include "unit/database-test-data.hpp"
Shock Jiang698e6ed2014-11-09 11:22:24 -080025
26namespace ndn {
27namespace ndns {
28namespace tests {
Alexander Afanasyevc7c99002015-10-09 17:27:30 -070029
30NDNS_LOG_INIT("IterativeQueryControllerTest")
Shock Jiang698e6ed2014-11-09 11:22:24 -080031
32class QueryControllerFixture : public DbTestData
33{
34public:
35 QueryControllerFixture()
Junxiao Shibbf7ac82016-07-14 14:45:15 +000036 : producerFace(io, {false, true})
37 , consumerFace(io, {false, true})
38 , validator(producerFace)
39 , top(m_root.getName(), m_certName, producerFace, m_session, m_keyChain, validator)
40 , net(m_net.getName(), m_certName, producerFace, m_session, m_keyChain, validator)
41 , ndnsim(m_ndnsim.getName(), m_certName, producerFace, m_session, m_keyChain, validator)
Shock Jiang698e6ed2014-11-09 11:22:24 -080042 {
43 run();
Junxiao Shibbf7ac82016-07-14 14:45:15 +000044 producerFace.onSendInterest.connect([this] (const Interest& interest) {
45 io.post([=] { consumerFace.receive(interest); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070046 });
Junxiao Shibbf7ac82016-07-14 14:45:15 +000047 consumerFace.onSendInterest.connect([this] (const Interest& interest) {
48 io.post([=] { producerFace.receive(interest); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070049 });
Junxiao Shibbf7ac82016-07-14 14:45:15 +000050 producerFace.onSendData.connect([this] (const Data& data) {
51 io.post([=] { consumerFace.receive(data); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070052 });
Junxiao Shibbf7ac82016-07-14 14:45:15 +000053 consumerFace.onSendData.connect([this] (const Data& data) {
54 io.post([=] { producerFace.receive(data); });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070055 });
Shock Jiang698e6ed2014-11-09 11:22:24 -080056 }
57
58 void
59 run()
60 {
61 io.poll();
62 io.reset();
63 }
64
65public:
66 boost::asio::io_service io;
Junxiao Shibbf7ac82016-07-14 14:45:15 +000067 ndn::util::DummyClientFace producerFace;
68 ndn::util::DummyClientFace consumerFace;
Shock Jiang698e6ed2014-11-09 11:22:24 -080069
70 Name hint;
71 Validator validator;
72 ndns::NameServer top;
73 ndns::NameServer net;
74 ndns::NameServer ndnsim;
75};
76
77
78BOOST_AUTO_TEST_SUITE(IterativeQueryController)
79
80BOOST_FIXTURE_TEST_CASE(Basic, QueryControllerFixture)
81{
82 using std::string;
83 using ndns::NameServer;
84
85 string hint;
86 Name name = m_ndnsim.getName();
87 Name dstLabel(name.append("www"));
88 name::Component rrType("TXT");
89 time::milliseconds lifetime(4000);
90
91 bool hasDataBack = false;
92 auto ctr = make_shared<ndns::IterativeQueryController>(
93 dstLabel, rrType, lifetime,
94 [&hasDataBack] (const Data&, const Response&) {
95 hasDataBack = true;
96 BOOST_CHECK(true);
97 },
98 [&hasDataBack] (uint32_t errCode, const std::string& errMsg) {
99 BOOST_CHECK(false);
100 },
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000101 consumerFace);
Shock Jiang698e6ed2014-11-09 11:22:24 -0800102
103 // IterativeQueryController is a whole process
104 // the tester should not send Interest one by one
105 // instead of starting it and letting it handle Interest/Data automatically
Shock Jiang5d5928c2014-12-03 13:41:22 -0800106 ctr->setStartComponentIndex(1);
Shock Jiang698e6ed2014-11-09 11:22:24 -0800107
108 ctr->start();
109
110 run();
111 BOOST_CHECK_EQUAL(hasDataBack, true);
112}
113
114BOOST_AUTO_TEST_SUITE_END()
115
116} // namespace tests
117} // namespace ndns
118} // namespace ndn