Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame^] | 2 | /* |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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 | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 29 | #include "face-system-fixture.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 30 | #include "tests/limited-io.hpp" |
| 31 | |
| 32 | namespace nfd { |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 33 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 34 | namespace tests { |
| 35 | |
| 36 | #define CHANNEL_PATH1 "unix-stream-test.1.sock" |
| 37 | #define CHANNEL_PATH2 "unix-stream-test.2.sock" |
| 38 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame^] | 39 | using UnixStreamFactoryFixture = FaceSystemFactoryFixture<UnixStreamFactory>; |
| 40 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 41 | BOOST_AUTO_TEST_SUITE(Face) |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame^] | 42 | BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, UnixStreamFactoryFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 43 | |
| 44 | using nfd::Face; |
| 45 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame^] | 46 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 47 | |
| 48 | BOOST_AUTO_TEST_CASE(Normal) |
| 49 | { |
| 50 | const std::string CONFIG = R"CONFIG( |
| 51 | face_system |
| 52 | { |
| 53 | unix |
| 54 | { |
| 55 | path /tmp/nfd.sock |
| 56 | } |
| 57 | } |
| 58 | )CONFIG"; |
| 59 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 60 | parseConfig(CONFIG, true); |
| 61 | parseConfig(CONFIG, false); |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 62 | |
| 63 | auto& factory = this->getFactoryById<UnixStreamFactory>("unix"); |
| 64 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 1); |
| 65 | } |
| 66 | |
| 67 | BOOST_AUTO_TEST_CASE(Omitted) |
| 68 | { |
| 69 | const std::string CONFIG = R"CONFIG( |
| 70 | face_system |
| 71 | { |
| 72 | } |
| 73 | )CONFIG"; |
| 74 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 75 | parseConfig(CONFIG, true); |
| 76 | parseConfig(CONFIG, false); |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 77 | |
| 78 | auto& factory = this->getFactoryById<UnixStreamFactory>("unix"); |
| 79 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 83 | { |
| 84 | const std::string CONFIG = R"CONFIG( |
| 85 | face_system |
| 86 | { |
| 87 | unix |
| 88 | { |
| 89 | hello |
| 90 | } |
| 91 | } |
| 92 | )CONFIG"; |
| 93 | |
| 94 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 95 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 96 | } |
| 97 | |
| 98 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 99 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 100 | BOOST_AUTO_TEST_CASE(ChannelMap) |
| 101 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 102 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
| 103 | shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1); |
| 104 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 105 | std::string channel1uri = channel1->getUri().toString(); |
| 106 | BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator |
| 107 | BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1), |
| 108 | channel1uri.size() - std::string(CHANNEL_PATH1).size()); |
| 109 | |
| 110 | shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2); |
| 111 | BOOST_CHECK_NE(channel1, channel2); |
| 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 115 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 116 | BOOST_CHECK(factory.getChannels().empty()); |
| 117 | |
| 118 | std::vector<shared_ptr<const Channel>> expectedChannels; |
| 119 | expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1)); |
| 120 | expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2)); |
| 121 | |
| 122 | for (const auto& channel : factory.getChannels()) { |
| 123 | auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel); |
| 124 | BOOST_REQUIRE(pos != expectedChannels.end()); |
| 125 | expectedChannels.erase(pos); |
| 126 | } |
| 127 | |
| 128 | BOOST_CHECK_EQUAL(expectedChannels.size(), 0); |
| 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) |
| 132 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 133 | createFace(factory, |
| 134 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 135 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 136 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 137 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 138 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 139 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 140 | createFace(factory, |
| 141 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 142 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 143 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 144 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 145 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 146 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 147 | createFace(factory, |
| 148 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 149 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 150 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 151 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 152 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamFactory |
| 156 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 157 | |
| 158 | } // namespace tests |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 159 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 160 | } // namespace nfd |