blob: 7d2a8da22f76584988c5d2a8625285ad13fd4205 [file] [log] [blame]
Eric Newberrya93680e2015-07-15 19:25:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shiaa1b3c92016-07-14 14:56:53 +00003 * Copyright (c) 2014-2016, Arizona Board of Regents.
Eric Newberrya93680e2015-07-15 19:25:29 -07004 *
5 * This file is part of ndn-tools (Named Data Networking Essential Tools).
6 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
7 *
8 * ndn-tools 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 * ndn-tools 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 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "tools/ping/server/ping-server.hpp"
21#include <ndn-cxx/util/dummy-client-face.hpp>
22
23#include "tests/test-common.hpp"
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070024#include "../../identity-management-time-fixture.hpp"
Eric Newberrya93680e2015-07-15 19:25:29 -070025
26namespace ndn {
27namespace ping {
28namespace server {
29namespace tests {
30
31using namespace ndn::tests;
32
33BOOST_AUTO_TEST_SUITE(PingServerPingServer)
34
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070035class CreatePingServerFixture : public IdentityManagementTimeFixture
Eric Newberrya93680e2015-07-15 19:25:29 -070036{
37protected:
38 CreatePingServerFixture()
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000039 : face(io, m_keyChain, {false, true})
Eric Newberrya93680e2015-07-15 19:25:29 -070040 , pingOptions(makeOptions())
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000041 , pingServer(face, m_keyChain, pingOptions)
Eric Newberrya93680e2015-07-15 19:25:29 -070042 {
43 }
44
45 Interest
46 makePingInterest(int seq) const
47 {
48 Name name(pingOptions.prefix);
49 name.append("ping");
50 name.append(std::to_string(seq));
51 Interest interest(name);
52 interest.setMustBeFresh(true);
53 interest.setInterestLifetime(time::milliseconds(2000));
54 return interest;
55 }
56
57private:
58 static Options
59 makeOptions()
60 {
61 Options opt;
62 opt.prefix = "ndn:/test-prefix";
63 opt.freshnessPeriod = time::milliseconds(5000);
64 opt.nMaxPings = 2;
65 opt.shouldPrintTimestamp = false;
66 opt.payloadSize = 0;
67 return opt;
68 }
69
70protected:
71 boost::asio::io_service io;
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000072 util::DummyClientFace face;
Eric Newberrya93680e2015-07-15 19:25:29 -070073 Options pingOptions;
74 PingServer pingServer;
75};
76
77BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture)
78{
79 BOOST_REQUIRE_EQUAL(0, pingServer.getNPings());
80 pingServer.start();
81
82 this->advanceClocks(io, time::milliseconds(1), 200);
83
Junxiao Shiaa1b3c92016-07-14 14:56:53 +000084 face.receive(makePingInterest(1000));
85 face.receive(makePingInterest(1001));
Eric Newberrya93680e2015-07-15 19:25:29 -070086
87 io.run();
88
89 BOOST_REQUIRE_EQUAL(2, pingServer.getNPings());
90}
91
92BOOST_AUTO_TEST_SUITE_END()
93
94} // namespace tests
95} // namespace server
96} // namespace ping
97} // namespace ndn