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" |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace ping { |
| 27 | namespace server { |
| 28 | namespace tests { |
| 29 | |
| 30 | using namespace ndn::tests; |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(PingServerPingServer) |
| 33 | |
| 34 | class CreatePingServerFixture : public UnitTestTimeFixture |
| 35 | { |
| 36 | protected: |
| 37 | CreatePingServerFixture() |
| 38 | : face(util::makeDummyClientFace(io, {false, true})) |
| 39 | , pingOptions(makeOptions()) |
| 40 | , pingServer(*face, pingOptions) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | Interest |
| 45 | makePingInterest(int seq) const |
| 46 | { |
| 47 | Name name(pingOptions.prefix); |
| 48 | name.append("ping"); |
| 49 | name.append(std::to_string(seq)); |
| 50 | Interest interest(name); |
| 51 | interest.setMustBeFresh(true); |
| 52 | interest.setInterestLifetime(time::milliseconds(2000)); |
| 53 | return interest; |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | static Options |
| 58 | makeOptions() |
| 59 | { |
| 60 | Options opt; |
| 61 | opt.prefix = "ndn:/test-prefix"; |
| 62 | opt.freshnessPeriod = time::milliseconds(5000); |
| 63 | opt.nMaxPings = 2; |
| 64 | opt.shouldPrintTimestamp = false; |
| 65 | opt.payloadSize = 0; |
| 66 | return opt; |
| 67 | } |
| 68 | |
| 69 | protected: |
| 70 | boost::asio::io_service io; |
| 71 | shared_ptr<util::DummyClientFace> face; |
| 72 | Options pingOptions; |
| 73 | PingServer pingServer; |
| 74 | }; |
| 75 | |
| 76 | BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture) |
| 77 | { |
| 78 | BOOST_REQUIRE_EQUAL(0, pingServer.getNPings()); |
| 79 | pingServer.start(); |
| 80 | |
| 81 | this->advanceClocks(io, time::milliseconds(1), 200); |
| 82 | |
| 83 | face->receive(makePingInterest(1000)); |
| 84 | face->receive(makePingInterest(1001)); |
| 85 | |
| 86 | io.run(); |
| 87 | |
| 88 | BOOST_REQUIRE_EQUAL(2, pingServer.getNPings()); |
| 89 | } |
| 90 | |
| 91 | BOOST_AUTO_TEST_SUITE_END() |
| 92 | |
| 93 | } // namespace tests |
| 94 | } // namespace server |
| 95 | } // namespace ping |
| 96 | } // namespace ndn |