Zhenkai Zhu | 0ccc9ec | 2013-01-04 19:24:09 -0800 | [diff] [blame^] | 1 | #include "ccnx-tunnel.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(CcnxTunnelTests) |
| 15 | |
| 16 | class DummyTunnel : public CcnxTunnel |
| 17 | { |
| 18 | public: |
| 19 | DummyTunnel(); |
| 20 | virtual ~DummyTunnel() {} |
| 21 | |
| 22 | virtual Name |
| 23 | queryRoutableName(const Name &name); |
| 24 | |
| 25 | }; |
| 26 | |
| 27 | DummyTunnel::DummyTunnel() : CcnxTunnel() {m_localPrefix = Name("/");} |
| 28 | |
| 29 | Name |
| 30 | DummyTunnel::queryRoutableName (const Name &name) |
| 31 | { |
| 32 | return Name("/local") + name; |
| 33 | } |
| 34 | |
| 35 | CcnxWrapperPtr t1(new DummyTunnel()); |
| 36 | CcnxWrapperPtr t2(new DummyTunnel()); |
| 37 | CcnxWrapperPtr c1(new CcnxWrapper()); |
| 38 | |
| 39 | // global data callback counter; |
| 40 | int g_dc_i = 0; |
| 41 | int g_dc_o = 0; |
| 42 | |
| 43 | void innerCallback(const Name &name, const Bytes &content) |
| 44 | { |
| 45 | g_dc_i ++; |
| 46 | string str((const char *)&content[0], content.size()); |
| 47 | BOOST_CHECK_EQUAL(name, str); |
| 48 | } |
| 49 | |
| 50 | void outerCallback(const Name &name, const Bytes &content) |
| 51 | { |
| 52 | g_dc_o ++; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | |
| 57 | BOOST_AUTO_TEST_CASE (CcnxTunnelTest) |
| 58 | { |
| 59 | // test publish |
| 60 | string inner = "/hello"; |
| 61 | |
| 62 | g_dc_o = 0; |
| 63 | t1->publishData(Name(inner), (const unsigned char *)inner.c_str(), inner.size(), 5); |
| 64 | usleep(100000); |
| 65 | Closure *outerClosure = new Closure(1, bind(outerCallback, _1, _2)); |
| 66 | c1->sendInterest(Name("/local/hello"), outerClosure); |
| 67 | usleep(100000); |
| 68 | // it is indeed published as /local/hello |
| 69 | BOOST_CHECK_EQUAL(g_dc_o, 1); |
| 70 | |
| 71 | g_dc_i = 0; |
| 72 | Closure *innerClosure = new Closure(1, bind(innerCallback, _1, _2)); |
| 73 | t2->sendInterest(Name(inner), innerClosure); |
| 74 | usleep(100000); |
| 75 | BOOST_CHECK_EQUAL(g_dc_i, 1); |
| 76 | |
| 77 | delete outerClosure; |
| 78 | delete innerClosure; |
| 79 | |
| 80 | } |
| 81 | |
| 82 | |
| 83 | BOOST_AUTO_TEST_SUITE_END() |