blob: 78126646fb94bb7acdcc87c82fe90fca12fd861f [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -06002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060020 */
21
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060022#include "transport/unix-transport.hpp"
23#include "util/config-file.hpp"
24
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025#include "boost-test.hpp"
26
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060027namespace ndn {
28
29class UnixTransportFixture
30{
31public:
32 UnixTransportFixture()
33 {
Yingdi Yud9715e32014-06-27 08:48:47 -070034 m_HOME = std::getenv("TEST_HOME");
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060035 }
36
37 ~UnixTransportFixture()
38 {
Yingdi Yud9715e32014-06-27 08:48:47 -070039 setenv("TEST_HOME", m_HOME.c_str(), 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060040 // std::cerr << "restoring home = " << m_HOME << std::endl;
41 }
42
43protected:
44 std::string m_HOME;
45};
46
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070047BOOST_FIXTURE_TEST_SUITE(TransportTestUnixTransport, UnixTransportFixture)
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060048
49BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameOk)
50{
Yingdi Yud9715e32014-06-27 08:48:47 -070051 setenv("TEST_HOME", "tests/unit-tests/transport/test-homes/ok", 1);
Yingdi Yuf56c68f2014-04-24 21:50:13 -070052
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060053 ConfigFile config;
54 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock");
55}
56
57BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketMissingProtocol)
58{
Yingdi Yud9715e32014-06-27 08:48:47 -070059 setenv("TEST_HOME",
60 "tests/unit-tests/transport/test-homes/missing-unix-socket-missing-protocol", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060061 ConfigFile config;
62 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock");
63}
64
65BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol)
66{
Yingdi Yud9715e32014-06-27 08:48:47 -070067 setenv("TEST_HOME",
68 "tests/unit-tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060069 ConfigFile config;
70 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock");
71}
72
73BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol)
74{
Yingdi Yud9715e32014-06-27 08:48:47 -070075 setenv("TEST_HOME",
76 "tests/unit-tests/transport/test-homes/missing-unix-socket-with-protocol", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060077 ConfigFile config;
78 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock");
79}
80
81BOOST_AUTO_TEST_SUITE_END()
82
83} // namespace ndn