blob: dd6f5cf68d60acbee223502c965b41ea7083df90 [file] [log] [blame]
Junxiao Shicde37ad2015-12-24 01:02:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0ba6d642017-07-17 00:53:22 +00002/*
Davide Pesavento15b55052018-01-27 19:09:28 -05003 * Copyright (c) 2014-2018, Regents of the University of California,
Junxiao Shicde37ad2015-12-24 01:02:05 -07004 * 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 Shi406deb52017-01-05 20:07:44 +000028#include "face-system-fixture.hpp"
Davide Pesaventob15276f2017-07-15 16:27:13 -040029#include "factory-test-common.hpp"
Junxiao Shicde37ad2015-12-24 01:02:05 -070030
31namespace nfd {
Junxiao Shi406deb52017-01-05 20:07:44 +000032namespace face {
Junxiao Shicde37ad2015-12-24 01:02:05 -070033namespace tests {
34
Junxiao Shi0ba6d642017-07-17 00:53:22 +000035using UnixStreamFactoryFixture = FaceSystemFactoryFixture<UnixStreamFactory>;
36
Junxiao Shicde37ad2015-12-24 01:02:05 -070037BOOST_AUTO_TEST_SUITE(Face)
Junxiao Shi0ba6d642017-07-17 00:53:22 +000038BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, UnixStreamFactoryFixture)
Junxiao Shicde37ad2015-12-24 01:02:05 -070039
Davide Pesavento494a9552018-02-04 22:16:05 -050040static const std::string CHANNEL_PATH1("unix-stream-test.1.sock");
41static const std::string CHANNEL_PATH2("unix-stream-test.2.sock");
Junxiao Shicde37ad2015-12-24 01:02:05 -070042
Junxiao Shi0ba6d642017-07-17 00:53:22 +000043BOOST_AUTO_TEST_SUITE(ProcessConfig)
Junxiao Shi406deb52017-01-05 20:07:44 +000044
45BOOST_AUTO_TEST_CASE(Normal)
46{
47 const std::string CONFIG = R"CONFIG(
48 face_system
49 {
50 unix
51 {
Davide Pesavento494a9552018-02-04 22:16:05 -050052 path /tmp/nfd-test.sock
Junxiao Shi406deb52017-01-05 20:07:44 +000053 }
54 }
55 )CONFIG";
56
Junxiao Shi1b65ca12017-01-21 23:04:41 +000057 parseConfig(CONFIG, true);
58 parseConfig(CONFIG, false);
Junxiao Shi406deb52017-01-05 20:07:44 +000059
Davide Pesavento494a9552018-02-04 22:16:05 -050060 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 Shi406deb52017-01-05 20:07:44 +000064}
65
66BOOST_AUTO_TEST_CASE(Omitted)
67{
68 const std::string CONFIG = R"CONFIG(
69 face_system
70 {
71 }
72 )CONFIG";
73
Junxiao Shi1b65ca12017-01-21 23:04:41 +000074 parseConfig(CONFIG, true);
75 parseConfig(CONFIG, false);
Junxiao Shi406deb52017-01-05 20:07:44 +000076
Junxiao Shi406deb52017-01-05 20:07:44 +000077 BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
78}
79
80BOOST_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
96BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
97
Davide Pesaventob15276f2017-07-15 16:27:13 -040098BOOST_AUTO_TEST_CASE(GetChannels)
Junxiao Shicde37ad2015-12-24 01:02:05 -070099{
Davide Pesaventob15276f2017-07-15 16:27:13 -0400100 BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101
Davide Pesaventob15276f2017-07-15 16:27:13 -0400102 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
108BOOST_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 Pesavento494a9552018-02-04 22:16:05 -0500113
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 Pesaventob15276f2017-07-15 16:27:13 -0400119
120 auto channel2 = factory.createChannel(CHANNEL_PATH2);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700121 BOOST_CHECK_NE(channel1, channel2);
122}
123
Davide Pesaventob15276f2017-07-15 16:27:13 -0400124BOOST_AUTO_TEST_CASE(UnsupportedCreateFace)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700125{
Eric Newberry42602412016-08-27 09:33:18 -0700126 createFace(factory,
127 FaceUri("unix:///var/run/nfd.sock"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000128 {},
Eric Newberry812d6152018-06-06 15:06:01 -0700129 {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, {}, false, false, false},
Eric Newberry42602412016-08-27 09:33:18 -0700130 {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700131
Eric Newberry42602412016-08-27 09:33:18 -0700132 createFace(factory,
133 FaceUri("unix:///var/run/nfd.sock"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000134 {},
Eric Newberry812d6152018-06-06 15:06:01 -0700135 {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false},
Eric Newberry42602412016-08-27 09:33:18 -0700136 {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700137
Eric Newberry42602412016-08-27 09:33:18 -0700138 createFace(factory,
139 FaceUri("unix:///var/run/nfd.sock"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000140 {},
Eric Newberry812d6152018-06-06 15:06:01 -0700141 {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false},
Eric Newberry42602412016-08-27 09:33:18 -0700142 {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700143}
144
145BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamFactory
146BOOST_AUTO_TEST_SUITE_END() // Face
147
148} // namespace tests
Junxiao Shi406deb52017-01-05 20:07:44 +0000149} // namespace face
Junxiao Shicde37ad2015-12-24 01:02:05 -0700150} // namespace nfd