blob: 7eb9b62a70d9703370a9081bf14858bed3c21395 [file] [log] [blame]
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -08001/* -*- 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
11namespace nfd {
12namespace tests {
13
14BOOST_FIXTURE_TEST_SUITE(CoreFaceUri, BaseFixture)
15
16BOOST_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 Shi61e3cc52014-03-03 20:40:28 -070027 BOOST_CHECK_EQUAL(uri.getHost(), "hostname");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080028 BOOST_CHECK_EQUAL(uri.getPort(), "80");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070029 BOOST_CHECK_EQUAL(uri.getPath(), "");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080030
31 BOOST_CHECK(uri.parse("udp4://192.0.2.1:20"));
32 BOOST_CHECK_EQUAL(uri.getScheme(), "udp4");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070033 BOOST_CHECK_EQUAL(uri.getHost(), "192.0.2.1");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080034 BOOST_CHECK_EQUAL(uri.getPort(), "20");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070035 BOOST_CHECK_EQUAL(uri.getPath(), "");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080036
37 BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0::1]:6363"));
38 BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070039 BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0::1");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080040 BOOST_CHECK_EQUAL(uri.getPort(), "6363");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070041 BOOST_CHECK_EQUAL(uri.getPath(), "");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080042
43 BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86d3]:6363"));
44 BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070045 BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0:3025:ccc5:eeeb:86d3");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080046 BOOST_CHECK_EQUAL(uri.getPort(), "6363");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070047 BOOST_CHECK_EQUAL(uri.getPath(), "");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080048
49 BOOST_CHECK(uri.parse("tcp://random.host.name"));
50 BOOST_CHECK_EQUAL(uri.getScheme(), "tcp");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070051 BOOST_CHECK_EQUAL(uri.getHost(), "random.host.name");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080052 BOOST_CHECK_EQUAL(uri.getPort(), "");
Junxiao Shi61e3cc52014-03-03 20:40:28 -070053 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 Afanasyev7b9347b2014-02-28 08:37:56 -080060
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 Shi61e3cc52014-03-03 20:40:28 -070064 BOOST_CHECK_EQUAL(uri.getPath(), "");
Alexander Afanasyev7b9347b2014-02-28 08:37:56 -080065}
66
67BOOST_AUTO_TEST_SUITE_END()
68
69} // namespace tests
70} // namespace nfd