Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Muktadir R Chowdhury | 800833b | 2016-07-29 13:43:59 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, The University of Memphis, |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 20 | **/ |
| 21 | |
| 22 | #include "tests/test-common.hpp" |
| 23 | #include "tests/control-commands.hpp" |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 24 | |
| 25 | #include "utility/face-controller.hpp" |
| 26 | |
Junxiao Shi | ee29a03 | 2014-11-12 00:48:59 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/security/key-chain.hpp> |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 28 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 29 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 30 | |
| 31 | namespace nlsr { |
| 32 | namespace test { |
| 33 | |
| 34 | using ndn::bind; |
| 35 | using ndn::shared_ptr; |
| 36 | using ndn::Interest; |
| 37 | |
| 38 | class FaceControllerFixture : public BaseFixture |
| 39 | { |
| 40 | public: |
| 41 | FaceControllerFixture() |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 42 | : face(make_shared<ndn::util::DummyClientFace>()) |
| 43 | , interests(face->sentInterests) |
Junxiao Shi | ee29a03 | 2014-11-12 00:48:59 -0700 | [diff] [blame] | 44 | , controller(*face, keyChain) |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 45 | , faceController(g_ioService, controller) |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 46 | { |
| 47 | } |
| 48 | |
| 49 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 50 | onFailure(const ndn::nfd::ControlResponse& response) |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 51 | { |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(response.getCode(), 408); |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public: |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 56 | shared_ptr<ndn::util::DummyClientFace> face; |
Junxiao Shi | ee29a03 | 2014-11-12 00:48:59 -0700 | [diff] [blame] | 57 | ndn::KeyChain keyChain; |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 58 | std::vector<Interest>& interests; |
| 59 | ndn::nfd::Controller controller; |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 60 | util::FaceController faceController; |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | BOOST_FIXTURE_TEST_SUITE(TestFaceController, FaceControllerFixture) |
| 64 | |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 65 | BOOST_AUTO_TEST_CASE(FaceCreateCanonizeSuccess) |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 66 | { |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 67 | const std::string uri("udp4://192.0.2.1:6363"); |
| 68 | faceController.createFace(uri, nullptr, nullptr); |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 69 | |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 70 | face->processEvents(ndn::time::milliseconds(1)); |
| 71 | |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 72 | BOOST_REQUIRE_EQUAL(interests.size(), 1); |
| 73 | Interest interest = interests.front(); |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 74 | |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 75 | ndn::nfd::ControlParameters extractedParameters; |
| 76 | ndn::Name::Component verb; |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 77 | |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 78 | extractFaceCommandParameters(interest, verb, extractedParameters); |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 79 | |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(verb, ndn::Name::Component("create")); |
| 81 | BOOST_CHECK_EQUAL(uri, extractedParameters.getUri()); |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(FaceCreateCanonizeFailure) |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 85 | { |
Vince Lehman | 7ccf694 | 2015-02-09 15:08:41 -0600 | [diff] [blame] | 86 | faceController.createFace("invalid://256.0.0.1:6363", |
| 87 | nullptr, |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 88 | bind(&FaceControllerFixture::onFailure, this, _1)); |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 89 | |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 90 | face->processEvents(ndn::time::milliseconds(1)); |
| 91 | |
| 92 | BOOST_CHECK_EQUAL(interests.size(), 0); |
| 93 | } |
| 94 | |
| 95 | BOOST_AUTO_TEST_SUITE_END() |
| 96 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 97 | } // namespace test |
| 98 | } // namespace nlsr |