Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Arizona Board of Regents. |
| 4 | * |
| 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 Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 24 | #include "../../identity-management-time-fixture.hpp" |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace ping { |
| 28 | namespace server { |
| 29 | namespace tests { |
| 30 | |
| 31 | using namespace ndn::tests; |
| 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(PingServerPingServer) |
| 34 | |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 35 | class CreatePingServerFixture : public IdentityManagementTimeFixture |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 36 | { |
| 37 | protected: |
| 38 | CreatePingServerFixture() |
| 39 | : face(util::makeDummyClientFace(io, {false, true})) |
| 40 | , pingOptions(makeOptions()) |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 41 | , pingServer(*face, m_keyChain, pingOptions) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 42 | { |
| 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 | |
| 57 | private: |
| 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 | |
| 70 | protected: |
| 71 | boost::asio::io_service io; |
| 72 | shared_ptr<util::DummyClientFace> face; |
| 73 | Options pingOptions; |
| 74 | PingServer pingServer; |
| 75 | }; |
| 76 | |
| 77 | BOOST_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 | |
| 84 | face->receive(makePingInterest(1000)); |
| 85 | face->receive(makePingInterest(1001)); |
| 86 | |
| 87 | io.run(); |
| 88 | |
| 89 | BOOST_REQUIRE_EQUAL(2, pingServer.getNPings()); |
| 90 | } |
| 91 | |
| 92 | BOOST_AUTO_TEST_SUITE_END() |
| 93 | |
| 94 | } // namespace tests |
| 95 | } // namespace server |
| 96 | } // namespace ping |
| 97 | } // namespace ndn |