Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "transport/tcp-transport.hpp" |
| 23 | #include "transport-fixture.hpp" |
| 24 | |
| 25 | #include "boost-test.hpp" |
| 26 | |
| 27 | namespace ndn { |
| 28 | |
| 29 | |
| 30 | |
| 31 | BOOST_FIXTURE_TEST_SUITE(TransportTestTcpTransport, TransportFixture) |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOk) |
| 34 | { |
| 35 | initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/ok"); |
| 36 | |
| 37 | const auto got = TcpTransport::getDefaultSocketHostAndPort(*m_config); |
| 38 | |
| 39 | BOOST_CHECK_EQUAL(got.first, "127.0.0.1"); |
| 40 | BOOST_CHECK_EQUAL(got.second, "6000"); |
| 41 | } |
| 42 | |
| 43 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMissingHost) |
| 44 | { |
| 45 | initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/" |
| 46 | "bad-missing-host"); |
| 47 | |
| 48 | BOOST_CHECK_EXCEPTION(TcpTransport::getDefaultSocketHostAndPort(*m_config), |
| 49 | ConfigFile::Error, |
| 50 | [] (const ConfigFile::Error& error) { |
| 51 | return error.what() == std::string("Malformed URI: tcp://:6000"); |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortOkOmittedPort) |
| 56 | { |
| 57 | initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/" |
| 58 | "ok-omitted-port"); |
| 59 | |
| 60 | const auto got = TcpTransport::getDefaultSocketHostAndPort(*m_config); |
| 61 | |
| 62 | BOOST_CHECK_EQUAL(got.first, "127.0.0.1"); |
| 63 | BOOST_CHECK_EQUAL(got.second, "6363"); |
| 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortNameOkOmittedHostOmittedPort) |
| 67 | { |
| 68 | initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/" |
| 69 | "ok-omitted-host-omitted-port"); |
| 70 | |
| 71 | const auto got = TcpTransport::getDefaultSocketHostAndPort(*m_config); |
| 72 | |
| 73 | BOOST_CHECK_EQUAL(got.first, "localhost"); |
| 74 | BOOST_CHECK_EQUAL(got.second, "6363"); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadWrongTransport) |
| 78 | { |
| 79 | initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/" |
| 80 | "bad-wrong-transport"); |
| 81 | |
| 82 | BOOST_CHECK_EXCEPTION(TcpTransport::getDefaultSocketHostAndPort(*m_config), |
| 83 | Transport::Error, |
| 84 | [] (const Transport::Error& error) { |
| 85 | return error.what() == std::string("Cannot create TcpTransport " |
| 86 | "from \"unix\" URI"); |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMalformedUri) |
| 91 | { |
| 92 | initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/" |
| 93 | "bad-malformed-uri"); |
| 94 | |
| 95 | BOOST_CHECK_EXCEPTION(TcpTransport::getDefaultSocketHostAndPort(*m_config), |
| 96 | ConfigFile::Error, |
| 97 | [] (const ConfigFile::Error& error) { |
| 98 | return error.what() == std::string("Malformed URI: tcp"); |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | BOOST_AUTO_TEST_SUITE_END() |
| 103 | |
| 104 | } // namespace ndn |