blob: 535b63cebf291c750850fe69efb8a8be1c82d4c9 [file] [log] [blame]
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -06001/* -*- 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 DiBenedettoc07b3a22014-03-19 12:32:52 -06007#include "transport/unix-transport.hpp"
8#include "util/config-file.hpp"
9
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070010#include "boost-test.hpp"
11
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060012namespace ndn {
13
14class UnixTransportFixture
15{
16public:
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
28protected:
29 std::string m_HOME;
30};
31
32BOOST_FIXTURE_TEST_SUITE(TestTransportUnixTransport, UnixTransportFixture)
33
34BOOST_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
41BOOST_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
48BOOST_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
55BOOST_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
62BOOST_AUTO_TEST_SUITE_END()
63
64} // namespace ndn