Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [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 | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 11 | */ |
| 12 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 13 | #include "transport/unix-transport.hpp" |
| 14 | #include "util/config-file.hpp" |
| 15 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 16 | #include "boost-test.hpp" |
| 17 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 18 | namespace ndn { |
| 19 | |
| 20 | class UnixTransportFixture |
| 21 | { |
| 22 | public: |
| 23 | UnixTransportFixture() |
| 24 | { |
| 25 | m_HOME = std::getenv("HOME"); |
| 26 | } |
| 27 | |
| 28 | ~UnixTransportFixture() |
| 29 | { |
| 30 | setenv("HOME", m_HOME.c_str(), 1); |
| 31 | // std::cerr << "restoring home = " << m_HOME << std::endl; |
| 32 | } |
| 33 | |
| 34 | protected: |
| 35 | std::string m_HOME; |
| 36 | }; |
| 37 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 38 | BOOST_FIXTURE_TEST_SUITE(TransportTestUnixTransport, UnixTransportFixture) |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 39 | |
| 40 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameOk) |
| 41 | { |
| 42 | setenv("HOME", "tests/transport/test-homes/ok", 1); |
| 43 | ConfigFile config; |
| 44 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock"); |
| 45 | } |
| 46 | |
| 47 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketMissingProtocol) |
| 48 | { |
| 49 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-missing-protocol", 1); |
| 50 | ConfigFile config; |
| 51 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 52 | } |
| 53 | |
| 54 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol) |
| 55 | { |
| 56 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1); |
| 57 | ConfigFile config; |
| 58 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock"); |
| 59 | } |
| 60 | |
| 61 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol) |
| 62 | { |
| 63 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-protocol", 1); |
| 64 | ConfigFile config; |
| 65 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_SUITE_END() |
| 69 | |
| 70 | } // namespace ndn |