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); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame^] | 43 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 44 | ConfigFile config; |
| 45 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock"); |
| 46 | } |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketMissingProtocol) |
| 49 | { |
| 50 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-missing-protocol", 1); |
| 51 | ConfigFile config; |
| 52 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 53 | } |
| 54 | |
| 55 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol) |
| 56 | { |
| 57 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1); |
| 58 | ConfigFile config; |
| 59 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock"); |
| 60 | } |
| 61 | |
| 62 | BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol) |
| 63 | { |
| 64 | setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-protocol", 1); |
| 65 | ConfigFile config; |
| 66 | BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock"); |
| 67 | } |
| 68 | |
| 69 | BOOST_AUTO_TEST_SUITE_END() |
| 70 | |
| 71 | } // namespace ndn |