blob: 583b5876c59331a4b1c85dded8e0e26da9836ea3 [file] [log] [blame]
Zhenkai Zhu3b82d432013-01-03 22:48:40 -08001#include "ccnx-wrapper.h"
2#include "ccnx-closure.h"
3#include "ccnx-name.h"
4#include "ccnx-pco.h"
5#include <unistd.h>
6
7#include <boost/test/unit_test.hpp>
8
9
10using namespace Ccnx;
11using namespace std;
12using namespace boost;
13
14BOOST_AUTO_TEST_SUITE(CcnxWrapperTests)
15
16CcnxWrapperPtr c1(new CcnxWrapper());
17CcnxWrapperPtr c2(new CcnxWrapper());
18
19void publish1(const Name &name)
20{
21 string content = name.toString();
22 c1->publishData(name, (const unsigned char*)content.c_str(), content.size(), 5);
23}
24
25void publish2(const Name &name)
26{
27 string content = name.toString();
28 c2->publishData(name, (const unsigned char*)content.c_str(), content.size(), 5);
29}
30
31void dataCallback(const Name &name, const Bytes &content)
32{
33 string msg((const char*)&content[0], content.size());
34 BOOST_CHECK_EQUAL(name, msg);
35}
36
37Closure::TimeoutCallbackReturnValue timeout(const Name &name)
38{
39 cout << "Timeout: "<< name;
40 return Closure::RESULT_OK;
41}
42
43BOOST_AUTO_TEST_CASE (CcnxWrapperTest)
44{
45 Name prefix1("/c1");
46 Name prefix2("/c2");
47
48 c1->setInterestFilter(prefix1, bind(publish1, _1));
49 c2->setInterestFilter(prefix2, bind(publish2, _1));
50
51 Closure *closure = new Closure(1, bind(dataCallback, _1, _2), bind(timeout, _1));
52
53 c1->sendInterest(Name("/c2/hi"), closure);
54 usleep(100000);
55 c2->sendInterest(Name("/c1/hi"), closure);
Zhenkai Zhud34106a2013-01-04 15:51:55 -080056 sleep(1);
Zhenkai Zhu3b82d432013-01-03 22:48:40 -080057 delete closure;
58}
59
60BOOST_AUTO_TEST_SUITE_END()