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[] = { |
| 15 | 0x3, 0x14, // Name |
| 16 | 0x4, 0x5, // NameComponent |
| 17 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 18 | 0x4, 0x3, // NameComponent |
| 19 | 0x6e, 0x64, 0x6e, |
| 20 | 0x4, 0x6, // NameComponent |
| 21 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78 |
| 22 | }; |
| 23 | |
| 24 | BOOST_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 | |
| 44 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestName, TestName+sizeof(TestName), |
| 45 | wire.begin(), wire.end()); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | BOOST_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 | |
| 58 | BOOST_AUTO_TEST_SUITE_END() |
| 59 | |
| 60 | } // namespace ndn |