blob: 8b745239a5e76142e2dc381c73708d9fcf264923 [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -06002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 DiBenedettoc07b3a22014-03-19 12:32:52 -060011 */
12
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060013#include "transport/unix-transport.hpp"
14#include "util/config-file.hpp"
15
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070016#include "boost-test.hpp"
17
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060018namespace ndn {
19
20class UnixTransportFixture
21{
22public:
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
34protected:
35 std::string m_HOME;
36};
37
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070038BOOST_FIXTURE_TEST_SUITE(TransportTestUnixTransport, UnixTransportFixture)
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060039
40BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameOk)
41{
42 setenv("HOME", "tests/transport/test-homes/ok", 1);
Yingdi Yuf56c68f2014-04-24 21:50:13 -070043
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060044 ConfigFile config;
45 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock");
46}
47
48BOOST_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
55BOOST_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
62BOOST_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
69BOOST_AUTO_TEST_SUITE_END()
70
71} // namespace ndn