Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | db4da5e | 2018-06-15 11:37:52 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 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 { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 28 | namespace tests { |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 29 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(Transport) |
| 31 | BOOST_FIXTURE_TEST_SUITE(TestTcpTransport, TransportFixture) |
| 32 | |
| 33 | using ndn::Transport; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 34 | |
| 35 | BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOk) |
| 36 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 37 | const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1:6000"); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 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 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp://:6000"), |
| 46 | Transport::Error, |
| 47 | [] (const Transport::Error& error) { |
Davide Pesavento | db4da5e | 2018-06-15 11:37:52 -0400 | [diff] [blame] | 48 | return error.what() == "Malformed URI: tcp://:6000"s; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 49 | }); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortOkOmittedPort) |
| 53 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 54 | const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1"); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 55 | |
| 56 | BOOST_CHECK_EQUAL(got.first, "127.0.0.1"); |
| 57 | BOOST_CHECK_EQUAL(got.second, "6363"); |
| 58 | } |
| 59 | |
| 60 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortNameOkOmittedHostOmittedPort) |
| 61 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 62 | const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://"); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 63 | |
| 64 | BOOST_CHECK_EQUAL(got.first, "localhost"); |
| 65 | BOOST_CHECK_EQUAL(got.second, "6363"); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadWrongTransport) |
| 69 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 70 | BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("unix://"), |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 71 | Transport::Error, |
| 72 | [] (const Transport::Error& error) { |
Davide Pesavento | db4da5e | 2018-06-15 11:37:52 -0400 | [diff] [blame] | 73 | return error.what() == "Cannot create TcpTransport from \"unix\" URI"s; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 74 | }); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMalformedUri) |
| 78 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 79 | BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp"), |
| 80 | Transport::Error, |
| 81 | [] (const Transport::Error& error) { |
Davide Pesavento | db4da5e | 2018-06-15 11:37:52 -0400 | [diff] [blame] | 82 | return error.what() == "Malformed URI: tcp"s; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 83 | }); |
| 84 | } |
| 85 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 86 | BOOST_AUTO_TEST_SUITE_END() // TestTcpTransport |
| 87 | BOOST_AUTO_TEST_SUITE_END() // Transport |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 88 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 89 | } // namespace tests |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 90 | } // namespace ndn |