blob: 0b6a63339b5e24ba069c17e1d29b4d2e44116b48 [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");
27 BOOST_CHECK_EQUAL(uri.getDomain(), "hostname");
28 BOOST_CHECK_EQUAL(uri.getPort(), "80");
29
30 BOOST_CHECK(uri.parse("udp4://192.0.2.1:20"));
31 BOOST_CHECK_EQUAL(uri.getScheme(), "udp4");
32 BOOST_CHECK_EQUAL(uri.getDomain(), "192.0.2.1");
33 BOOST_CHECK_EQUAL(uri.getPort(), "20");
34
35 BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0::1]:6363"));
36 BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
37 BOOST_CHECK_EQUAL(uri.getDomain(), "2001:db8:3f9:0::1");
38 BOOST_CHECK_EQUAL(uri.getPort(), "6363");
39
40 BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86d3]:6363"));
41 BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
42 BOOST_CHECK_EQUAL(uri.getDomain(), "2001:db8:3f9:0:3025:ccc5:eeeb:86d3");
43 BOOST_CHECK_EQUAL(uri.getPort(), "6363");
44
45 BOOST_CHECK(uri.parse("tcp://random.host.name"));
46 BOOST_CHECK_EQUAL(uri.getScheme(), "tcp");
47 BOOST_CHECK_EQUAL(uri.getDomain(), "random.host.name");
48 BOOST_CHECK_EQUAL(uri.getPort(), "");
49
50 BOOST_CHECK_EQUAL(uri.parse("tcp://192.0.2.1:"), false);
51 BOOST_CHECK_EQUAL(uri.parse("tcp://[::zzzz]"), false);
52 BOOST_CHECK_EQUAL(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86dg]:6363"), false);
53}
54
55BOOST_AUTO_TEST_SUITE_END()
56
57} // namespace tests
58} // namespace nfd