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 | { |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 34 | m_HOME = std::getenv("TEST_HOME"); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | ~UnixTransportFixture() |
| 38 | { |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 39 | setenv("TEST_HOME", m_HOME.c_str(), 1); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 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 | { |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 51 | setenv("TEST_HOME", "tests/unit-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 | { |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 59 | setenv("TEST_HOME", |
| 60 | "tests/unit-tests/transport/test-homes/missing-unix-socket-missing-protocol", 1); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 61 | ConfigFile config; |
| 62 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol) |
| 66 | { |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 67 | setenv("TEST_HOME", |
| 68 | "tests/unit-tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 69 | ConfigFile config; |
| 70 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock"); |
| 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol) |
| 74 | { |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 75 | setenv("TEST_HOME", |
| 76 | "tests/unit-tests/transport/test-homes/missing-unix-socket-with-protocol", 1); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 77 | ConfigFile config; |
| 78 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 79 | } |
| 80 | |
| 81 | BOOST_AUTO_TEST_SUITE_END() |
| 82 | |
| 83 | } // namespace ndn |