blob: 7e3d36f3b64e3549037a9be947ab358b880e6756 [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);
43 ConfigFile config;
44 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock");
45}
46
47BOOST_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
54BOOST_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
61BOOST_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
68BOOST_AUTO_TEST_SUITE_END()
69
70} // namespace ndn