blob: fc1214abefdcdf709aa86c1ee7889011572e4560 [file] [log] [blame]
Zhenkai Zhu0ccc9ec2013-01-04 19:24:09 -08001#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
10using namespace Ccnx;
11using namespace std;
12using namespace boost;
13
14BOOST_AUTO_TEST_SUITE(CcnxTunnelTests)
15
16class DummyTunnel : public CcnxTunnel
17{
18public:
19 DummyTunnel();
20 virtual ~DummyTunnel() {}
21
22 virtual Name
23 queryRoutableName(const Name &name);
24
25};
26
27DummyTunnel::DummyTunnel() : CcnxTunnel() {m_localPrefix = Name("/");}
28
29Name
30DummyTunnel::queryRoutableName (const Name &name)
31{
32 return Name("/local") + name;
33}
34
35CcnxWrapperPtr t1(new DummyTunnel());
36CcnxWrapperPtr t2(new DummyTunnel());
37CcnxWrapperPtr c1(new CcnxWrapper());
38
39// global data callback counter;
40int g_dc_i = 0;
41int g_dc_o = 0;
42
43void 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
50void outerCallback(const Name &name, const Bytes &content)
51{
52 g_dc_o ++;
53}
54
55
56
57BOOST_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
83BOOST_AUTO_TEST_SUITE_END()