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 | |
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 | |
| 35 | #define CHANNEL_PATH1 "unix-stream-test.1.sock" |
| 36 | #define CHANNEL_PATH2 "unix-stream-test.2.sock" |
| 37 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 38 | using UnixStreamFactoryFixture = FaceSystemFactoryFixture<UnixStreamFactory>; |
| 39 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 40 | BOOST_AUTO_TEST_SUITE(Face) |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 41 | BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, UnixStreamFactoryFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 42 | |
| 43 | using nfd::Face; |
| 44 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 45 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 46 | |
| 47 | BOOST_AUTO_TEST_CASE(Normal) |
| 48 | { |
| 49 | const std::string CONFIG = R"CONFIG( |
| 50 | face_system |
| 51 | { |
| 52 | unix |
| 53 | { |
| 54 | path /tmp/nfd.sock |
| 55 | } |
| 56 | } |
| 57 | )CONFIG"; |
| 58 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 59 | parseConfig(CONFIG, true); |
| 60 | parseConfig(CONFIG, false); |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 61 | |
| 62 | auto& factory = this->getFactoryById<UnixStreamFactory>("unix"); |
| 63 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 1); |
| 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 | |
| 77 | auto& factory = this->getFactoryById<UnixStreamFactory>("unix"); |
| 78 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 79 | } |
| 80 | |
| 81 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 82 | { |
| 83 | const std::string CONFIG = R"CONFIG( |
| 84 | face_system |
| 85 | { |
| 86 | unix |
| 87 | { |
| 88 | hello |
| 89 | } |
| 90 | } |
| 91 | )CONFIG"; |
| 92 | |
| 93 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 94 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 95 | } |
| 96 | |
| 97 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 98 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 99 | BOOST_AUTO_TEST_CASE(GetChannels) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 100 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 102 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 103 | std::set<std::string> expected; |
| 104 | expected.insert(factory.createChannel(CHANNEL_PATH1)->getUri().toString()); |
| 105 | expected.insert(factory.createChannel(CHANNEL_PATH2)->getUri().toString()); |
| 106 | checkChannelListEqual(factory, expected); |
| 107 | } |
| 108 | |
| 109 | BOOST_AUTO_TEST_CASE(CreateChannel) |
| 110 | { |
| 111 | auto channel1 = factory.createChannel(CHANNEL_PATH1); |
| 112 | auto channel1a = factory.createChannel(CHANNEL_PATH1); |
| 113 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 114 | std::string uri = channel1->getUri().toString(); |
| 115 | BOOST_CHECK_EQUAL(uri.find("unix:///"), 0); // third '/' is the path separator |
| 116 | BOOST_CHECK_EQUAL(uri.rfind(CHANNEL_PATH1), |
| 117 | uri.size() - std::string(CHANNEL_PATH1).size()); |
| 118 | |
| 119 | auto channel2 = factory.createChannel(CHANNEL_PATH2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 120 | BOOST_CHECK_NE(channel1, channel2); |
| 121 | } |
| 122 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 123 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 124 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 125 | createFace(factory, |
| 126 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 127 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 128 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 129 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame^] | 130 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 131 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 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_ON_DEMAND, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 137 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame^] | 138 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 139 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 140 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 141 | createFace(factory, |
| 142 | FaceUri("unix:///var/run/nfd.sock"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 143 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 144 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 145 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame^] | 146 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 147 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamFactory |
| 151 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 152 | |
| 153 | } // namespace tests |
Junxiao Shi | 406deb5 | 2017-01-05 20:07:44 +0000 | [diff] [blame] | 154 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 155 | } // namespace nfd |