Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 1 | /* -*- 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 "core/face-uri.hpp" |
| 8 | |
| 9 | #include "tests/test-common.hpp" |
| 10 | |
| 11 | namespace nfd { |
| 12 | namespace tests { |
| 13 | |
| 14 | BOOST_FIXTURE_TEST_SUITE(CoreFaceUri, BaseFixture) |
| 15 | |
| 16 | BOOST_AUTO_TEST_CASE(Basic) |
| 17 | { |
| 18 | BOOST_CHECK_NO_THROW(FaceUri("udp://hostname:6363")); |
| 19 | BOOST_CHECK_THROW(FaceUri("udp//hostname:6363"), FaceUri::Error); |
| 20 | BOOST_CHECK_THROW(FaceUri("udp://hostname:port"), FaceUri::Error); |
| 21 | |
| 22 | FaceUri uri; |
| 23 | BOOST_CHECK_EQUAL(uri.parse("udp//hostname:6363"), false); |
| 24 | |
| 25 | BOOST_CHECK(uri.parse("udp://hostname:80")); |
| 26 | BOOST_CHECK_EQUAL(uri.getScheme(), "udp"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 27 | BOOST_CHECK_EQUAL(uri.getHost(), "hostname"); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 28 | BOOST_CHECK_EQUAL(uri.getPort(), "80"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 29 | BOOST_CHECK_EQUAL(uri.getPath(), ""); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 30 | |
| 31 | BOOST_CHECK(uri.parse("udp4://192.0.2.1:20")); |
| 32 | BOOST_CHECK_EQUAL(uri.getScheme(), "udp4"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 33 | BOOST_CHECK_EQUAL(uri.getHost(), "192.0.2.1"); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 34 | BOOST_CHECK_EQUAL(uri.getPort(), "20"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 35 | BOOST_CHECK_EQUAL(uri.getPath(), ""); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 36 | |
| 37 | BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0::1]:6363")); |
| 38 | BOOST_CHECK_EQUAL(uri.getScheme(), "udp6"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 39 | BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0::1"); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 40 | BOOST_CHECK_EQUAL(uri.getPort(), "6363"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 41 | BOOST_CHECK_EQUAL(uri.getPath(), ""); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 42 | |
| 43 | BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86d3]:6363")); |
| 44 | BOOST_CHECK_EQUAL(uri.getScheme(), "udp6"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0:3025:ccc5:eeeb:86d3"); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 46 | BOOST_CHECK_EQUAL(uri.getPort(), "6363"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(uri.getPath(), ""); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 48 | |
| 49 | BOOST_CHECK(uri.parse("tcp://random.host.name")); |
| 50 | BOOST_CHECK_EQUAL(uri.getScheme(), "tcp"); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(uri.getHost(), "random.host.name"); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(uri.getPort(), ""); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(uri.getPath(), ""); |
| 54 | |
| 55 | BOOST_CHECK(uri.parse("unix:///var/run/example.sock")); |
| 56 | BOOST_CHECK_EQUAL(uri.getScheme(), "unix"); |
| 57 | BOOST_CHECK_EQUAL(uri.getHost(), ""); |
| 58 | BOOST_CHECK_EQUAL(uri.getPort(), ""); |
| 59 | BOOST_CHECK_EQUAL(uri.getPath(), "/var/run/example.sock"); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 60 | |
| 61 | BOOST_CHECK_EQUAL(uri.parse("tcp://192.0.2.1:"), false); |
| 62 | BOOST_CHECK_EQUAL(uri.parse("tcp://[::zzzz]"), false); |
| 63 | BOOST_CHECK_EQUAL(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86dg]:6363"), false); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 64 | BOOST_CHECK_EQUAL(uri.getPath(), ""); |
Alexander Afanasyev | 7b9347b | 2014-02-28 08:37:56 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | BOOST_AUTO_TEST_SUITE_END() |
| 68 | |
| 69 | } // namespace tests |
| 70 | } // namespace nfd |