blob: a876ba44cc8e646417780a6fef6115926d753fe4 [file] [log] [blame]
Alexander Afanasyev72ac2192013-01-03 19:33:43 -08001
Zhenkai Zhu85dc03d2013-01-03 19:22:12 -08002#include "ccnx-name.h"
Alexander Afanasyev72ac2192013-01-03 19:33:43 -08003
4#define BOOST_TEST_MAIN 1
Alexander Afanasyev72ac2192013-01-03 19:33:43 -08005
6#include <boost/test/unit_test.hpp>
7
Zhenkai Zhu85dc03d2013-01-03 19:22:12 -08008using namespace Ccnx;
9using namespace std;
10using namespace boost;
Zhenkai Zhu85dc03d2013-01-03 19:22:12 -080011
12BOOST_AUTO_TEST_SUITE(CcnxNameTests)
13
14BOOST_AUTO_TEST_CASE (CcnxNameTest)
15{
16 Name empty = Name();
17 Name root = Name("/");
18 BOOST_CHECK_EQUAL(empty, root);
Zhenkai Zhu3b82d432013-01-03 22:48:40 -080019 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 Afanasyevc9eb68f2013-01-07 13:40:00 -080033
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 Zhu3b82d432013-01-03 22:48:40 -080046 // Charbuf related stuff will be checked in other place
Zhenkai Zhu85dc03d2013-01-03 19:22:12 -080047}
48
Zhenkai Zhu85dc03d2013-01-03 19:22:12 -080049BOOST_AUTO_TEST_SUITE_END()