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 | /* |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2020 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 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/transport/tcp-transport.hpp" |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 27 | namespace tests { |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 28 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 29 | BOOST_AUTO_TEST_SUITE(Transport) |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(TestTcpTransport) |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 31 | |
| 32 | using ndn::Transport; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 33 | |
| 34 | BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOk) |
| 35 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 36 | const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1:6000"); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 37 | |
| 38 | BOOST_CHECK_EQUAL(got.first, "127.0.0.1"); |
| 39 | BOOST_CHECK_EQUAL(got.second, "6000"); |
| 40 | } |
| 41 | |
| 42 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMissingHost) |
| 43 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 44 | BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp://:6000"), |
| 45 | Transport::Error, |
| 46 | [] (const Transport::Error& error) { |
Davide Pesavento | db4da5e | 2018-06-15 11:37:52 -0400 | [diff] [blame] | 47 | return error.what() == "Malformed URI: tcp://:6000"s; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 48 | }); |
| 49 | } |
| 50 | |
| 51 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortOkOmittedPort) |
| 52 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 53 | const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1"); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 54 | |
| 55 | BOOST_CHECK_EQUAL(got.first, "127.0.0.1"); |
| 56 | BOOST_CHECK_EQUAL(got.second, "6363"); |
| 57 | } |
| 58 | |
| 59 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortNameOkOmittedHostOmittedPort) |
| 60 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 61 | const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://"); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 62 | |
| 63 | BOOST_CHECK_EQUAL(got.first, "localhost"); |
| 64 | BOOST_CHECK_EQUAL(got.second, "6363"); |
| 65 | } |
| 66 | |
| 67 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadWrongTransport) |
| 68 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 69 | BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("unix://"), |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 70 | Transport::Error, |
| 71 | [] (const Transport::Error& error) { |
Davide Pesavento | db4da5e | 2018-06-15 11:37:52 -0400 | [diff] [blame] | 72 | return error.what() == "Cannot create TcpTransport from \"unix\" URI"s; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 73 | }); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMalformedUri) |
| 77 | { |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 78 | BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp"), |
| 79 | Transport::Error, |
| 80 | [] (const Transport::Error& error) { |
Davide Pesavento | db4da5e | 2018-06-15 11:37:52 -0400 | [diff] [blame] | 81 | return error.what() == "Malformed URI: tcp"s; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 82 | }); |
| 83 | } |
| 84 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 85 | BOOST_AUTO_TEST_SUITE_END() // TestTcpTransport |
| 86 | BOOST_AUTO_TEST_SUITE_END() // Transport |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 87 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 88 | } // namespace tests |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 89 | } // namespace ndn |