Alexander Afanasyev | 72ac219 | 2013-01-03 19:33:43 -0800 | [diff] [blame] | 1 | |
Zhenkai Zhu | 85dc03d | 2013-01-03 19:22:12 -0800 | [diff] [blame] | 2 | #include "ccnx-name.h" |
Alexander Afanasyev | 72ac219 | 2013-01-03 19:33:43 -0800 | [diff] [blame] | 3 | |
| 4 | #define BOOST_TEST_MAIN 1 |
Alexander Afanasyev | 72ac219 | 2013-01-03 19:33:43 -0800 | [diff] [blame] | 5 | |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | |
Zhenkai Zhu | 85dc03d | 2013-01-03 19:22:12 -0800 | [diff] [blame] | 8 | using namespace Ccnx; |
| 9 | using namespace std; |
| 10 | using namespace boost; |
Zhenkai Zhu | 85dc03d | 2013-01-03 19:22:12 -0800 | [diff] [blame] | 11 | |
| 12 | BOOST_AUTO_TEST_SUITE(CcnxNameTests) |
| 13 | |
| 14 | BOOST_AUTO_TEST_CASE (CcnxNameTest) |
| 15 | { |
| 16 | Name empty = Name(); |
| 17 | Name root = Name("/"); |
| 18 | BOOST_CHECK_EQUAL(empty, root); |
Zhenkai Zhu | 3b82d43 | 2013-01-03 22:48:40 -0800 | [diff] [blame] | 19 | BOOST_CHECK_EQUAL(empty, "/"); |
| 20 | BOOST_CHECK_EQUAL(root.size(), 0); |
| 21 | empty.appendComp("hello"); |
| 22 | empty.appendComp("world"); |
| 23 | BOOST_CHECK_EQUAL(empty.size(), 2); |
| 24 | BOOST_CHECK_EQUAL(empty.toString(), "/hello/world"); |
| 25 | empty = empty + root; |
| 26 | BOOST_CHECK_EQUAL(empty.toString(), "/hello/world"); |
| 27 | BOOST_CHECK_EQUAL(empty.getCompAsString(0), "hello"); |
| 28 | BOOST_CHECK_EQUAL(empty.getPartialName(1, 1), Name("/world")); |
| 29 | Name name("/hello/world"); |
| 30 | BOOST_CHECK_EQUAL(empty, name); |
| 31 | BOOST_CHECK_EQUAL(name, Name("/hello") + Name("/world")); |
| 32 | |
Alexander Afanasyev | c9eb68f | 2013-01-07 13:40:00 -0800 | [diff] [blame] | 33 | |
| 34 | name.appendComp (1); |
| 35 | name.appendComp (255); |
| 36 | name.appendComp (256); |
| 37 | name.appendComp (1234567890); |
| 38 | |
| 39 | BOOST_CHECK_EQUAL (name.toString (), "/hello/world/%00%01/%00%ff/%00%00%01/%00%d2%02%96I"); |
| 40 | |
| 41 | BOOST_CHECK_EQUAL (name.getCompAsInt (5), 1234567890); |
| 42 | BOOST_CHECK_EQUAL (name.getCompAsInt (4), 256); |
| 43 | BOOST_CHECK_EQUAL (name.getCompAsInt (3), 255); |
| 44 | BOOST_CHECK_EQUAL (name.getCompAsInt (2), 1); |
| 45 | |
Zhenkai Zhu | 3b82d43 | 2013-01-03 22:48:40 -0800 | [diff] [blame] | 46 | // Charbuf related stuff will be checked in other place |
Zhenkai Zhu | 85dc03d | 2013-01-03 19:22:12 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Zhenkai Zhu | 85dc03d | 2013-01-03 19:22:12 -0800 | [diff] [blame] | 49 | BOOST_AUTO_TEST_SUITE_END() |