Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | |
| 8 | #include "name.hpp" |
| 9 | |
| 10 | namespace ndn { |
| 11 | |
| 12 | BOOST_AUTO_TEST_SUITE(TestName) |
| 13 | |
| 14 | static const uint8_t TestName[] = { |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 15 | 0x7, 0x14, // Name |
| 16 | 0x8, 0x5, // NameComponent |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 17 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 18 | 0x8, 0x3, // NameComponent |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 19 | 0x6e, 0x64, 0x6e, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 20 | 0x8, 0x6, // NameComponent |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 21 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78 |
| 22 | }; |
| 23 | |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 24 | const uint8_t Name1[] = {0x7, 0x7, // Name |
| 25 | 0x8, 0x5, // NameComponent |
| 26 | 0x6c, 0x6f, 0x63, 0x61, 0x6c}; |
| 27 | |
| 28 | const 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 Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 35 | BOOST_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 Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL_COLLECTIONS(TestName, TestName+sizeof(TestName), |
| 56 | wire.begin(), wire.end()); |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | |
| 60 | BOOST_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 Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 69 | BOOST_AUTO_TEST_CASE (AppendsAndMultiEncode) |
| 70 | { |
| 71 | Name name("/local"); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 72 | |
| 73 | BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(), |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 74 | Name1, Name1 + sizeof(Name1)); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 75 | |
| 76 | name.append("ndn"); |
| 77 | |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 78 | BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(), |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 79 | Name2, Name2 + sizeof(Name2)); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 80 | |
| 81 | name.append("prefix"); |
| 82 | BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(), |
| 83 | TestName, TestName+sizeof(TestName)); |
| 84 | } |
| 85 | |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 86 | BOOST_AUTO_TEST_SUITE_END() |
| 87 | |
| 88 | } // namespace ndn |