blob: ffb049408cf84b3a8664f2379cbcd3a300c9d5b8 [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
7#include <boost/test/unit_test.hpp>
8#include <boost/test/output_test_stream.hpp>
9
10#include "transport/unix-transport.hpp"
11#include "util/config-file.hpp"
12
13namespace ndn {
14
15class UnixTransportFixture
16{
17public:
18 UnixTransportFixture()
19 {
20 m_HOME = std::getenv("HOME");
21 }
22
23 ~UnixTransportFixture()
24 {
25 setenv("HOME", m_HOME.c_str(), 1);
26 // std::cerr << "restoring home = " << m_HOME << std::endl;
27 }
28
29protected:
30 std::string m_HOME;
31};
32
33BOOST_FIXTURE_TEST_SUITE(TestTransportUnixTransport, UnixTransportFixture)
34
35BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameOk)
36{
37 setenv("HOME", "tests/transport/test-homes/ok", 1);
38 ConfigFile config;
39 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/test/nfd.sock");
40}
41
42BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketMissingProtocol)
43{
44 setenv("HOME", "tests/transport/test-homes/missing-unix-socket-missing-protocol", 1);
45 ConfigFile config;
46 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock");
47}
48
49BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketNdndProtocol)
50{
51 setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-ndnd-protocol", 1);
52 ConfigFile config;
53 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/tmp/.ndnd.sock");
54}
55
56BOOST_AUTO_TEST_CASE(TestGetDefaultSocketNameMissingSocketWithProtocol)
57{
58 setenv("HOME", "tests/transport/test-homes/missing-unix-socket-with-protocol", 1);
59 ConfigFile config;
60 BOOST_REQUIRE_EQUAL(UnixTransport::getDefaultSocketName(config), "/var/run/nfd.sock");
61}
62
63BOOST_AUTO_TEST_SUITE_END()
64
65} // namespace ndn
66