Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 7 | #include "transport/unix-transport.hpp" |
| 8 | #include "util/config-file.hpp" |
| 9 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 10 | #include "boost-test.hpp" |
| 11 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 12 | namespace ndn { |
| 13 | |
| 14 | class UnixTransportFixture |
| 15 | { |
| 16 | public: |
| 17 | UnixTransportFixture() |
| 18 | { |
| 19 | m_HOME = std::getenv("HOME"); |
| 20 | } |
| 21 | |
| 22 | ~UnixTransportFixture() |
| 23 | { |
| 24 | setenv("HOME", m_HOME.c_str(), 1); |
| 25 | // std::cerr << "restoring home = " << m_HOME << std::endl; |
| 26 | } |
| 27 | |
| 28 | protected: |
| 29 | std::string m_HOME; |
| 30 | }; |
| 31 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 32 | BOOST_FIXTURE_TEST_SUITE(TransportTestUnixTransport, UnixTransportFixture) |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 33 | |
| 34 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameOk) |
| 35 | { |
| 36 | setenv("HOME", "tests/transport/test-homes/ok", 1); |
| 37 | ConfigFile config; |
| 38 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock"); |
| 39 | } |
| 40 | |
| 41 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketMissingProtocol) |
| 42 | { |
| 43 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-missing-protocol", 1); |
| 44 | ConfigFile config; |
| 45 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 46 | } |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol) |
| 49 | { |
| 50 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1); |
| 51 | ConfigFile config; |
| 52 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock"); |
| 53 | } |
| 54 | |
| 55 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol) |
| 56 | { |
| 57 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-protocol", 1); |
| 58 | ConfigFile config; |
| 59 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 60 | } |
| 61 | |
| 62 | BOOST_AUTO_TEST_SUITE_END() |
| 63 | |
| 64 | } // namespace ndn |