blob: 02bd9c3dbe1a238d557532573fbf35490dcc9da2 [file] [log] [blame]
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventodb4da5e2018-06-15 11:37:52 -04002/*
3 * Copyright (c) 2013-2018 Regents of the University of California.
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -07004 *
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
27namespace ndn {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070029
Davide Pesaventoeee3e822016-11-26 19:19:34 +010030BOOST_AUTO_TEST_SUITE(Transport)
31BOOST_FIXTURE_TEST_SUITE(TestTcpTransport, TransportFixture)
32
33using ndn::Transport;
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070034
35BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOk)
36{
Alexander Afanasyev57e00362016-06-23 13:22:54 -070037 const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1:6000");
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070038
39 BOOST_CHECK_EQUAL(got.first, "127.0.0.1");
40 BOOST_CHECK_EQUAL(got.second, "6000");
41}
42
43BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMissingHost)
44{
Alexander Afanasyev57e00362016-06-23 13:22:54 -070045 BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp://:6000"),
46 Transport::Error,
47 [] (const Transport::Error& error) {
Davide Pesaventodb4da5e2018-06-15 11:37:52 -040048 return error.what() == "Malformed URI: tcp://:6000"s;
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070049 });
50}
51
52BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortOkOmittedPort)
53{
Alexander Afanasyev57e00362016-06-23 13:22:54 -070054 const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1");
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070055
56 BOOST_CHECK_EQUAL(got.first, "127.0.0.1");
57 BOOST_CHECK_EQUAL(got.second, "6363");
58}
59
60BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortNameOkOmittedHostOmittedPort)
61{
Alexander Afanasyev57e00362016-06-23 13:22:54 -070062 const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://");
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070063
64 BOOST_CHECK_EQUAL(got.first, "localhost");
65 BOOST_CHECK_EQUAL(got.second, "6363");
66}
67
68BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadWrongTransport)
69{
Alexander Afanasyev57e00362016-06-23 13:22:54 -070070 BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("unix://"),
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070071 Transport::Error,
72 [] (const Transport::Error& error) {
Davide Pesaventodb4da5e2018-06-15 11:37:52 -040073 return error.what() == "Cannot create TcpTransport from \"unix\" URI"s;
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070074 });
75}
76
77BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMalformedUri)
78{
Alexander Afanasyev57e00362016-06-23 13:22:54 -070079 BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp"),
80 Transport::Error,
81 [] (const Transport::Error& error) {
Davide Pesaventodb4da5e2018-06-15 11:37:52 -040082 return error.what() == "Malformed URI: tcp"s;
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070083 });
84}
85
Davide Pesaventoeee3e822016-11-26 19:19:34 +010086BOOST_AUTO_TEST_SUITE_END() // TestTcpTransport
87BOOST_AUTO_TEST_SUITE_END() // Transport
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070088
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080089} // namespace tests
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070090} // namespace ndn