blob: 2ac1fad6bd5b2164b155908d8c897f928fe1407f [file] [log] [blame]
Vince Lehman27f1add2014-10-16 17:14:46 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir R Chowdhury800833b2016-07-29 13:43:59 -05003 * Copyright (c) 2014-2016, The University of Memphis,
Vince Lehman7ccf6942015-02-09 15:08:41 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
Vince Lehman27f1add2014-10-16 17:14:46 -05006 *
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 Lehman27f1add2014-10-16 17:14:46 -050020 **/
21
22#include "tests/test-common.hpp"
23#include "tests/control-commands.hpp"
Vince Lehman27f1add2014-10-16 17:14:46 -050024
25#include "utility/face-controller.hpp"
26
Junxiao Shiee29a032014-11-12 00:48:59 -070027#include <ndn-cxx/security/key-chain.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000028#include <ndn-cxx/mgmt/nfd/controller.hpp>
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060029#include <ndn-cxx/util/dummy-client-face.hpp>
Vince Lehman27f1add2014-10-16 17:14:46 -050030
31namespace nlsr {
32namespace test {
33
34using ndn::bind;
35using ndn::shared_ptr;
36using ndn::Interest;
37
38class FaceControllerFixture : public BaseFixture
39{
40public:
41 FaceControllerFixture()
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060042 : face(make_shared<ndn::util::DummyClientFace>())
43 , interests(face->sentInterests)
Junxiao Shiee29a032014-11-12 00:48:59 -070044 , controller(*face, keyChain)
Vince Lehman7ccf6942015-02-09 15:08:41 -060045 , faceController(g_ioService, controller)
Vince Lehman27f1add2014-10-16 17:14:46 -050046 {
47 }
48
49 void
Junxiao Shi63bd0342016-08-17 16:57:14 +000050 onFailure(const ndn::nfd::ControlResponse& response)
Vince Lehman27f1add2014-10-16 17:14:46 -050051 {
Junxiao Shi63bd0342016-08-17 16:57:14 +000052 BOOST_CHECK_EQUAL(response.getCode(), 408);
Vince Lehman27f1add2014-10-16 17:14:46 -050053 }
54
55public:
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060056 shared_ptr<ndn::util::DummyClientFace> face;
Junxiao Shiee29a032014-11-12 00:48:59 -070057 ndn::KeyChain keyChain;
Vince Lehman27f1add2014-10-16 17:14:46 -050058 std::vector<Interest>& interests;
59 ndn::nfd::Controller controller;
Vince Lehman7ccf6942015-02-09 15:08:41 -060060 util::FaceController faceController;
Vince Lehman27f1add2014-10-16 17:14:46 -050061};
62
63BOOST_FIXTURE_TEST_SUITE(TestFaceController, FaceControllerFixture)
64
Vince Lehman7ccf6942015-02-09 15:08:41 -060065BOOST_AUTO_TEST_CASE(FaceCreateCanonizeSuccess)
Vince Lehman27f1add2014-10-16 17:14:46 -050066{
Vince Lehman7ccf6942015-02-09 15:08:41 -060067 const std::string uri("udp4://192.0.2.1:6363");
68 faceController.createFace(uri, nullptr, nullptr);
Vince Lehman27f1add2014-10-16 17:14:46 -050069
Vince Lehman27f1add2014-10-16 17:14:46 -050070 face->processEvents(ndn::time::milliseconds(1));
71
Vince Lehman7ccf6942015-02-09 15:08:41 -060072 BOOST_REQUIRE_EQUAL(interests.size(), 1);
73 Interest interest = interests.front();
Vince Lehman27f1add2014-10-16 17:14:46 -050074
Vince Lehman7ccf6942015-02-09 15:08:41 -060075 ndn::nfd::ControlParameters extractedParameters;
76 ndn::Name::Component verb;
Vince Lehman27f1add2014-10-16 17:14:46 -050077
Vince Lehman7ccf6942015-02-09 15:08:41 -060078 extractFaceCommandParameters(interest, verb, extractedParameters);
Vince Lehman27f1add2014-10-16 17:14:46 -050079
Vince Lehman7ccf6942015-02-09 15:08:41 -060080 BOOST_CHECK_EQUAL(verb, ndn::Name::Component("create"));
81 BOOST_CHECK_EQUAL(uri, extractedParameters.getUri());
Vince Lehman27f1add2014-10-16 17:14:46 -050082}
83
Vince Lehman7ccf6942015-02-09 15:08:41 -060084BOOST_AUTO_TEST_CASE(FaceCreateCanonizeFailure)
Vince Lehman27f1add2014-10-16 17:14:46 -050085{
Vince Lehman7ccf6942015-02-09 15:08:41 -060086 faceController.createFace("invalid://256.0.0.1:6363",
87 nullptr,
Junxiao Shi63bd0342016-08-17 16:57:14 +000088 bind(&FaceControllerFixture::onFailure, this, _1));
Vince Lehman27f1add2014-10-16 17:14:46 -050089
Vince Lehman27f1add2014-10-16 17:14:46 -050090 face->processEvents(ndn::time::milliseconds(1));
91
92 BOOST_CHECK_EQUAL(interests.size(), 0);
93}
94
95BOOST_AUTO_TEST_SUITE_END()
96
Nick Gordonfad8e252016-08-11 14:21:38 -050097} // namespace test
98} // namespace nlsr