blob: 236f8b1290510e592af3ec53d520c17c0d9d902d [file] [log] [blame]
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -08003 * See COPYING for copyright and distribution information.
4 */
5
6#include <boost/test/unit_test.hpp>
7
8#include "name.hpp"
9
10namespace ndn {
11
12BOOST_AUTO_TEST_SUITE(TestName)
13
14static const uint8_t TestName[] = {
Alexander Afanasyev4b456282014-02-13 00:34:34 -080015 0x7, 0x14, // Name
16 0x8, 0x5, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080017 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080018 0x8, 0x3, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080019 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080020 0x8, 0x6, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080021 0x70, 0x72, 0x65, 0x66, 0x69, 0x78
22};
23
Alexander Afanasyev4b456282014-02-13 00:34:34 -080024const uint8_t Name1[] = {0x7, 0x7, // Name
25 0x8, 0x5, // NameComponent
26 0x6c, 0x6f, 0x63, 0x61, 0x6c};
27
28const uint8_t Name2[] = {0x7, 0xc, // Name
29 0x8, 0x5, // NameComponent
30 0x6c, 0x6f, 0x63, 0x61, 0x6c,
31 0x8, 0x3, // NameComponent
32 0x6e, 0x64, 0x6e};
33
34
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080035BOOST_AUTO_TEST_CASE (Encode)
36{
37 Name name("/local/ndn/prefix");
38
39 const Block &wire = name.wireEncode();
40
41 // for (Buffer::const_iterator i = wire.begin();
42 // i != wire.end();
43 // ++i)
44 // {
45 // std::ios::fmtflags saveFlags = std::cout.flags(std::ios::hex);
46
47 // if (i != wire.begin())
48 // std::cout << ", ";
49 // std::cout << "0x" << static_cast<uint32_t>(*i);
50
51 // std::cout.flags(saveFlags);
52 // }
53 // std::cout << std::endl;
54
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080055 BOOST_CHECK_EQUAL_COLLECTIONS(TestName, TestName+sizeof(TestName),
56 wire.begin(), wire.end());
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080057}
58
59
60BOOST_AUTO_TEST_CASE (Decode)
61{
62 Block block(TestName, sizeof(TestName));
63
64 Name name(block);
65
66 BOOST_CHECK_EQUAL(name.toUri(), "/local/ndn/prefix");
67}
68
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080069BOOST_AUTO_TEST_CASE (AppendsAndMultiEncode)
70{
71 Name name("/local");
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080072
73 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
Alexander Afanasyev4b456282014-02-13 00:34:34 -080074 Name1, Name1 + sizeof(Name1));
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080075
76 name.append("ndn");
77
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080078 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
Alexander Afanasyev4b456282014-02-13 00:34:34 -080079 Name2, Name2 + sizeof(Name2));
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080080
81 name.append("prefix");
82 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
83 TestName, TestName+sizeof(TestName));
84}
85
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080086BOOST_AUTO_TEST_SUITE_END()
87
88} // namespace ndn