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 | |
| 7 | #include <boost/test/unit_test.hpp> |
| 8 | #include <boost/test/output_test_stream.hpp> |
| 9 | |
| 10 | #include "transport/unix-transport.hpp" |
| 11 | #include "util/config-file.hpp" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | class UnixTransportFixture |
| 16 | { |
| 17 | public: |
| 18 | UnixTransportFixture() |
| 19 | { |
| 20 | m_HOME = std::getenv("HOME"); |
| 21 | } |
| 22 | |
| 23 | ~UnixTransportFixture() |
| 24 | { |
| 25 | setenv("HOME", m_HOME.c_str(), 1); |
| 26 | // std::cerr << "restoring home = " << m_HOME << std::endl; |
| 27 | } |
| 28 | |
| 29 | protected: |
| 30 | std::string m_HOME; |
| 31 | }; |
| 32 | |
| 33 | BOOST_FIXTURE_TEST_SUITE(TestTransportUnixTransport, UnixTransportFixture) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameOk) |
| 36 | { |
| 37 | setenv("HOME", "tests/transport/test-homes/ok", 1); |
| 38 | ConfigFile config; |
| 39 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock"); |
| 40 | } |
| 41 | |
| 42 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketMissingProtocol) |
| 43 | { |
| 44 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-missing-protocol", 1); |
| 45 | ConfigFile config; |
| 46 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 47 | } |
| 48 | |
| 49 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol) |
| 50 | { |
| 51 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1); |
| 52 | ConfigFile config; |
| 53 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock"); |
| 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol) |
| 57 | { |
| 58 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-protocol", 1); |
| 59 | ConfigFile config; |
| 60 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_SUITE_END() |
| 64 | |
| 65 | } // namespace ndn |
| 66 | |