Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 7 | * 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 DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 22 | #include "transport/unix-transport.hpp" |
| 23 | #include "util/config-file.hpp" |
| 24 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 25 | #include "boost-test.hpp" |
| 26 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 27 | namespace ndn { |
| 28 | |
| 29 | class UnixTransportFixture |
| 30 | { |
| 31 | public: |
| 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 | |
| 43 | protected: |
| 44 | std::string m_HOME; |
| 45 | }; |
| 46 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 47 | BOOST_FIXTURE_TEST_SUITE(TransportTestUnixTransport, UnixTransportFixture) |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 48 | |
| 49 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameOk) |
| 50 | { |
| 51 | setenv("HOME", "tests/transport/test-homes/ok", 1); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 52 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 53 | ConfigFile config; |
| 54 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock"); |
| 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketMissingProtocol) |
| 58 | { |
| 59 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-missing-protocol", 1); |
| 60 | ConfigFile config; |
| 61 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 62 | } |
| 63 | |
| 64 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol) |
| 65 | { |
| 66 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1); |
| 67 | ConfigFile config; |
| 68 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock"); |
| 69 | } |
| 70 | |
| 71 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol) |
| 72 | { |
| 73 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-protocol", 1); |
| 74 | ConfigFile config; |
| 75 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 76 | } |
| 77 | |
| 78 | BOOST_AUTO_TEST_SUITE_END() |
| 79 | |
| 80 | } // namespace ndn |