Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/unix-stream-factory.hpp" |
| 27 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 28 | #include "factory-test-common.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 29 | #include "tests/limited-io.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace tests { |
| 33 | |
| 34 | #define CHANNEL_PATH1 "unix-stream-test.1.sock" |
| 35 | #define CHANNEL_PATH2 "unix-stream-test.2.sock" |
| 36 | |
| 37 | BOOST_AUTO_TEST_SUITE(Face) |
| 38 | BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, BaseFixture) |
| 39 | |
| 40 | using nfd::Face; |
| 41 | |
| 42 | BOOST_AUTO_TEST_CASE(ChannelMap) |
| 43 | { |
| 44 | UnixStreamFactory factory; |
| 45 | |
| 46 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
| 47 | shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1); |
| 48 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 49 | std::string channel1uri = channel1->getUri().toString(); |
| 50 | BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator |
| 51 | BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1), |
| 52 | channel1uri.size() - std::string(CHANNEL_PATH1).size()); |
| 53 | |
| 54 | shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2); |
| 55 | BOOST_CHECK_NE(channel1, channel2); |
| 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 59 | { |
| 60 | UnixStreamFactory factory; |
| 61 | BOOST_CHECK(factory.getChannels().empty()); |
| 62 | |
| 63 | std::vector<shared_ptr<const Channel>> expectedChannels; |
| 64 | expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1)); |
| 65 | expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2)); |
| 66 | |
| 67 | for (const auto& channel : factory.getChannels()) { |
| 68 | auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel); |
| 69 | BOOST_REQUIRE(pos != expectedChannels.end()); |
| 70 | expectedChannels.erase(pos); |
| 71 | } |
| 72 | |
| 73 | BOOST_CHECK_EQUAL(expectedChannels.size(), 0); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) |
| 77 | { |
| 78 | UnixStreamFactory factory; |
| 79 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 80 | createFace(factory, |
| 81 | FaceUri("unix:///var/run/nfd.sock"), |
| 82 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 83 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 84 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 85 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 86 | createFace(factory, |
| 87 | FaceUri("unix:///var/run/nfd.sock"), |
| 88 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 89 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 90 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 91 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 92 | createFace(factory, |
| 93 | FaceUri("unix:///var/run/nfd.sock"), |
| 94 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 95 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 96 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamFactory |
| 100 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 101 | |
| 102 | } // namespace tests |
| 103 | } // namespace nfd |