blob: 7713a5bdd639df7b131e075532c09d2311cc4a8b [file] [log] [blame]
Shock Jiang698e6ed2014-11-09 11:22:24 -08001/* -*- 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 "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 {
33NDNS_LOG_INIT("IterativeQueryControllerTest");
34
35class QueryControllerFixture : public DbTestData
36{
37public:
38 QueryControllerFixture()
39 : producerFace(ndn::util::makeDummyClientFace(io, { false, true }))
40 , consumerFace(ndn::util::makeDummyClientFace(io, { false, true }))
41 , validator(*producerFace)
42 , top(m_root.getName(), m_certName, *producerFace, m_session, m_keyChain, validator)
43 , net(m_net.getName(), m_certName, *producerFace, m_session, m_keyChain, validator)
44 , ndnsim(m_ndnsim.getName(), m_certName, *producerFace, m_session, m_keyChain, validator)
45 {
46 run();
47 producerFace->onInterest += [&] (const Interest& interest) { consumerFace->receive(interest); };
48 consumerFace->onInterest += [&] (const Interest& interest) { producerFace->receive(interest); };
49 producerFace->onData += [&] (const Data& data) { consumerFace->receive(data); };
50 consumerFace->onData += [&] (const Data& data) { producerFace->receive(data); };
51 }
52
53 void
54 run()
55 {
56 io.poll();
57 io.reset();
58 }
59
60public:
61 boost::asio::io_service io;
62 shared_ptr<ndn::util::DummyClientFace> producerFace;
63 shared_ptr<ndn::util::DummyClientFace> consumerFace;
64
65 Name hint;
66 Validator validator;
67 ndns::NameServer top;
68 ndns::NameServer net;
69 ndns::NameServer ndnsim;
70};
71
72
73BOOST_AUTO_TEST_SUITE(IterativeQueryController)
74
75BOOST_FIXTURE_TEST_CASE(Basic, QueryControllerFixture)
76{
77 using std::string;
78 using ndns::NameServer;
79
80 string hint;
81 Name name = m_ndnsim.getName();
82 Name dstLabel(name.append("www"));
83 name::Component rrType("TXT");
84 time::milliseconds lifetime(4000);
85
86 bool hasDataBack = false;
87 auto ctr = make_shared<ndns::IterativeQueryController>(
88 dstLabel, rrType, lifetime,
89 [&hasDataBack] (const Data&, const Response&) {
90 hasDataBack = true;
91 BOOST_CHECK(true);
92 },
93 [&hasDataBack] (uint32_t errCode, const std::string& errMsg) {
94 BOOST_CHECK(false);
95 },
96 *consumerFace);
97
98 // IterativeQueryController is a whole process
99 // the tester should not send Interest one by one
100 // instead of starting it and letting it handle Interest/Data automatically
Shock Jiang5d5928c2014-12-03 13:41:22 -0800101 ctr->setStartComponentIndex(1);
Shock Jiang698e6ed2014-11-09 11:22:24 -0800102
103 ctr->start();
104
105 run();
106 BOOST_CHECK_EQUAL(hasDataBack, true);
107}
108
109BOOST_AUTO_TEST_SUITE_END()
110
111} // namespace tests
112} // namespace ndns
113} // namespace ndn