Zhenkai Zhu | 3b82d43 | 2013-01-03 22:48:40 -0800 | [diff] [blame] | 1 | #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 | |
| 10 | using namespace Ccnx; |
| 11 | using namespace std; |
| 12 | using namespace boost; |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(CcnxWrapperTests) |
| 15 | |
| 16 | CcnxWrapperPtr c1(new CcnxWrapper()); |
| 17 | CcnxWrapperPtr c2(new CcnxWrapper()); |
| 18 | |
| 19 | void 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 | |
| 25 | void 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 | |
| 31 | void 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 | |
| 37 | Closure::TimeoutCallbackReturnValue timeout(const Name &name) |
| 38 | { |
| 39 | cout << "Timeout: "<< name; |
| 40 | return Closure::RESULT_OK; |
| 41 | } |
| 42 | |
| 43 | BOOST_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); |
| 56 | sleep(100000); |
| 57 | delete closure; |
| 58 | } |
| 59 | |
| 60 | BOOST_AUTO_TEST_SUITE_END() |