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 | /* |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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 | |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 28 | #include "face-system-fixture.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 29 | #include "factory-test-common.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 32 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 33 | namespace tests { |
| 34 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 35 | using UnixStreamFactoryFixture = FaceSystemFactoryFixture<UnixStreamFactory>; |
| 36 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 37 | BOOST_AUTO_TEST_SUITE(Face) |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 38 | BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, UnixStreamFactoryFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 39 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 40 | static const std::string CHANNEL_PATH1("unix-stream-test.1.sock"); |
| 41 | static const std::string CHANNEL_PATH2("unix-stream-test.2.sock"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 42 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 43 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 44 | |
| 45 | BOOST_AUTO_TEST_CASE(Normal) |
| 46 | { |
| 47 | const std::string CONFIG = R"CONFIG( |
| 48 | face_system |
| 49 | { |
| 50 | unix |
| 51 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 52 | path /tmp/nfd-test.sock |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | )CONFIG"; |
| 56 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 57 | parseConfig(CONFIG, true); |
| 58 | parseConfig(CONFIG, false); |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 59 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 60 | BOOST_REQUIRE_EQUAL(factory.getChannels().size(), 1); |
| 61 | const auto& uri = factory.getChannels().front()->getUri(); |
| 62 | BOOST_CHECK_EQUAL(uri.getScheme(), "unix"); |
| 63 | BOOST_CHECK_NE(uri.getPath().find("nfd-test.sock"), std::string::npos); |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_CASE(Omitted) |
| 67 | { |
| 68 | const std::string CONFIG = R"CONFIG( |
| 69 | face_system |
| 70 | { |
| 71 | } |
| 72 | )CONFIG"; |
| 73 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 74 | parseConfig(CONFIG, true); |
| 75 | parseConfig(CONFIG, false); |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 76 | |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 78 | } |
| 79 | |
| 80 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 81 | { |
| 82 | const std::string CONFIG = R"CONFIG( |
| 83 | face_system |
| 84 | { |
| 85 | unix |
| 86 | { |
| 87 | hello |
| 88 | } |
| 89 | } |
| 90 | )CONFIG"; |
| 91 | |
| 92 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 93 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 94 | } |
| 95 | |
| 96 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 97 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 98 | BOOST_AUTO_TEST_CASE(GetChannels) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 99 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 101 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 102 | std::set<std::string> expected; |
| 103 | expected.insert(factory.createChannel(CHANNEL_PATH1)->getUri().toString()); |
| 104 | expected.insert(factory.createChannel(CHANNEL_PATH2)->getUri().toString()); |
| 105 | checkChannelListEqual(factory, expected); |
| 106 | } |
| 107 | |
| 108 | BOOST_AUTO_TEST_CASE(CreateChannel) |
| 109 | { |
| 110 | auto channel1 = factory.createChannel(CHANNEL_PATH1); |
| 111 | auto channel1a = factory.createChannel(CHANNEL_PATH1); |
| 112 | BOOST_CHECK_EQUAL(channel1, channel1a); |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 113 | |
| 114 | const auto& uri = channel1->getUri(); |
| 115 | BOOST_CHECK_EQUAL(uri.getScheme(), "unix"); |
| 116 | BOOST_CHECK_EQUAL(uri.getHost(), ""); |
| 117 | BOOST_CHECK_EQUAL(uri.getPort(), ""); |
| 118 | BOOST_CHECK_EQUAL(uri.getPath().rfind(CHANNEL_PATH1), uri.getPath().size() - CHANNEL_PATH1.size()); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 119 | |
| 120 | auto channel2 = factory.createChannel(CHANNEL_PATH2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 121 | BOOST_CHECK_NE(channel1, channel2); |
| 122 | } |
| 123 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 124 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 125 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 126 | createFace(factory, |
| 127 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 128 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 129 | {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 130 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 131 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 132 | createFace(factory, |
| 133 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 134 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 135 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 136 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 137 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 138 | createFace(factory, |
| 139 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 140 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 141 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 142 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamFactory |
| 146 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 147 | |
| 148 | } // namespace tests |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 149 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 150 | } // namespace nfd |