blob: 6c20302f52f5ceb68d29de1632d282edfa01e879 [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 {
34 m_HOME = std::getenv("HOME");
35 }
36
37 ~UnixTransportFixture()
38 {
39 setenv("HOME", m_HOME.c_str(), 1);
40 // 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{
Alexander Afanasyev8b1674a2014-05-15 00:58:43 -070051 setenv("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{
Alexander Afanasyev8b1674a2014-05-15 00:58:43 -070059 setenv("HOME", "tests/unit-tests/transport/test-homes/missing-unix-socket-missing-protocol", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060060 ConfigFile config;
61 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock");
62}
63
64BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol)
65{
Alexander Afanasyev8b1674a2014-05-15 00:58:43 -070066 setenv("HOME", "tests/unit-tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060067 ConfigFile config;
68 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock");
69}
70
71BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol)
72{
Alexander Afanasyev8b1674a2014-05-15 00:58:43 -070073 setenv("HOME", "tests/unit-tests/transport/test-homes/missing-unix-socket-with-protocol", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060074 ConfigFile config;
75 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock");
76}
77
78BOOST_AUTO_TEST_SUITE_END()
79
80} // namespace ndn