Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Arizona Board of Regents. |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 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" |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame^] | 24 | #include "../../identity-management-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 | |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame^] | 33 | BOOST_AUTO_TEST_SUITE(Ping) |
| 34 | BOOST_AUTO_TEST_SUITE(TestPingServer) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 36 | class CreatePingServerFixture : public IdentityManagementTimeFixture |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 37 | { |
| 38 | protected: |
| 39 | CreatePingServerFixture() |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 40 | : face(io, m_keyChain, {false, true}) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 41 | , pingOptions(makeOptions()) |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 42 | , pingServer(face, m_keyChain, pingOptions) |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | Interest |
| 47 | makePingInterest(int seq) const |
| 48 | { |
| 49 | Name name(pingOptions.prefix); |
| 50 | name.append("ping"); |
| 51 | name.append(std::to_string(seq)); |
| 52 | Interest interest(name); |
| 53 | interest.setMustBeFresh(true); |
| 54 | interest.setInterestLifetime(time::milliseconds(2000)); |
| 55 | return interest; |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | static Options |
| 60 | makeOptions() |
| 61 | { |
| 62 | Options opt; |
| 63 | opt.prefix = "ndn:/test-prefix"; |
| 64 | opt.freshnessPeriod = time::milliseconds(5000); |
| 65 | opt.nMaxPings = 2; |
| 66 | opt.shouldPrintTimestamp = false; |
| 67 | opt.payloadSize = 0; |
| 68 | return opt; |
| 69 | } |
| 70 | |
| 71 | protected: |
| 72 | boost::asio::io_service io; |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 73 | util::DummyClientFace face; |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 74 | Options pingOptions; |
| 75 | PingServer pingServer; |
| 76 | }; |
| 77 | |
| 78 | BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture) |
| 79 | { |
| 80 | BOOST_REQUIRE_EQUAL(0, pingServer.getNPings()); |
| 81 | pingServer.start(); |
| 82 | |
| 83 | this->advanceClocks(io, time::milliseconds(1), 200); |
| 84 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 85 | face.receive(makePingInterest(1000)); |
| 86 | face.receive(makePingInterest(1001)); |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 87 | |
| 88 | io.run(); |
| 89 | |
| 90 | BOOST_REQUIRE_EQUAL(2, pingServer.getNPings()); |
| 91 | } |
| 92 | |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame^] | 93 | BOOST_AUTO_TEST_SUITE_END() // TestPingServer |
| 94 | BOOST_AUTO_TEST_SUITE_END() // Ping |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 95 | |
| 96 | } // namespace tests |
| 97 | } // namespace server |
| 98 | } // namespace ping |
| 99 | } // namespace ndn |