| #include "ccnx-wrapper.h" |
| #include "ccnx-closure.h" |
| #include "ccnx-name.h" |
| #include "ccnx-pco.h" |
| #include <unistd.h> |
| |
| #include <boost/test/unit_test.hpp> |
| |
| |
| using namespace Ccnx; |
| using namespace std; |
| using namespace boost; |
| |
| BOOST_AUTO_TEST_SUITE(CcnxWrapperTests) |
| |
| CcnxWrapperPtr c1(new CcnxWrapper()); |
| CcnxWrapperPtr c2(new CcnxWrapper()); |
| |
| void publish1(const Name &name) |
| { |
| string content = name.toString(); |
| c1->publishData(name, (const unsigned char*)content.c_str(), content.size(), 5); |
| } |
| |
| void publish2(const Name &name) |
| { |
| string content = name.toString(); |
| c2->publishData(name, (const unsigned char*)content.c_str(), content.size(), 5); |
| } |
| |
| void dataCallback(const Name &name, const Bytes &content) |
| { |
| string msg((const char*)&content[0], content.size()); |
| BOOST_CHECK_EQUAL(name, msg); |
| } |
| |
| Closure::TimeoutCallbackReturnValue timeout(const Name &name) |
| { |
| cout << "Timeout: "<< name; |
| return Closure::RESULT_OK; |
| } |
| |
| BOOST_AUTO_TEST_CASE (CcnxWrapperTest) |
| { |
| Name prefix1("/c1"); |
| Name prefix2("/c2"); |
| |
| c1->setInterestFilter(prefix1, bind(publish1, _1)); |
| c2->setInterestFilter(prefix2, bind(publish2, _1)); |
| |
| Closure *closure = new Closure(1, bind(dataCallback, _1, _2), bind(timeout, _1)); |
| |
| c1->sendInterest(Name("/c2/hi"), closure); |
| usleep(100000); |
| c2->sendInterest(Name("/c1/hi"), closure); |
| sleep(100000); |
| delete closure; |
| } |
| |
| BOOST_AUTO_TEST_SUITE_END() |