blob: 961f98ea60d2133cec2387830a3e5e089fe83f27 [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 Afanasyev6835ad82014-02-12 10:07:20 -080015 0x1, 0x14, // Name
16 0x2, 0x5, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080017 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080018 0x2, 0x3, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080019 0x6e, 0x64, 0x6e,
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080020 0x2, 0x6, // NameComponent
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080021 0x70, 0x72, 0x65, 0x66, 0x69, 0x78
22};
23
24BOOST_AUTO_TEST_CASE (Encode)
25{
26 Name name("/local/ndn/prefix");
27
28 const Block &wire = name.wireEncode();
29
30 // for (Buffer::const_iterator i = wire.begin();
31 // i != wire.end();
32 // ++i)
33 // {
34 // std::ios::fmtflags saveFlags = std::cout.flags(std::ios::hex);
35
36 // if (i != wire.begin())
37 // std::cout << ", ";
38 // std::cout << "0x" << static_cast<uint32_t>(*i);
39
40 // std::cout.flags(saveFlags);
41 // }
42 // std::cout << std::endl;
43
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080044 BOOST_CHECK_EQUAL_COLLECTIONS(TestName, TestName+sizeof(TestName),
45 wire.begin(), wire.end());
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080046}
47
48
49BOOST_AUTO_TEST_CASE (Decode)
50{
51 Block block(TestName, sizeof(TestName));
52
53 Name name(block);
54
55 BOOST_CHECK_EQUAL(name.toUri(), "/local/ndn/prefix");
56}
57
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080058BOOST_AUTO_TEST_CASE (AppendsAndMultiEncode)
59{
60 Name name("/local");
61
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080062 const uint8_t name1[] = {0x1, 0x7, // Name
63 0x2, 0x5, // NameComponent
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080064 0x6c, 0x6f, 0x63, 0x61, 0x6c};
65
66 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
67 name1, name1 + sizeof(name1));
68
69 name.append("ndn");
70
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080071 const uint8_t name2[] = {0x1, 0xc, // Name
72 0x2, 0x5, // NameComponent
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080073 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080074 0x2, 0x3, // NameComponent
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080075 0x6e, 0x64, 0x6e};
76
77 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
78 name2, name2 + sizeof(name2));
79
80 name.append("prefix");
81 BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
82 TestName, TestName+sizeof(TestName));
83}
84
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080085BOOST_AUTO_TEST_SUITE_END()
86
87} // namespace ndn