test case for InterestLifetime selector
diff --git a/test/test-ccnx-wrapper.cc b/test/test-ccnx-wrapper.cc
index 583b587..8636a2d 100644
--- a/test/test-ccnx-wrapper.cc
+++ b/test/test-ccnx-wrapper.cc
@@ -15,6 +15,8 @@
CcnxWrapperPtr c1(new CcnxWrapper());
CcnxWrapperPtr c2(new CcnxWrapper());
+int g_timeout_counter = 0;
+int g_dataCallback_counter = 0;
void publish1(const Name &name)
{
@@ -31,12 +33,13 @@
void dataCallback(const Name &name, const Bytes &content)
{
string msg((const char*)&content[0], content.size());
+ g_dataCallback_counter ++;
BOOST_CHECK_EQUAL(name, msg);
}
Closure::TimeoutCallbackReturnValue timeout(const Name &name)
{
- cout << "Timeout: "<< name;
+ g_timeout_counter ++;
return Closure::RESULT_OK;
}
@@ -54,6 +57,41 @@
usleep(100000);
c2->sendInterest(Name("/c1/hi"), closure);
sleep(1);
+ BOOST_CHECK_EQUAL(g_dataCallback_counter, 2);
+ // reset
+ g_dataCallback_counter = 0;
+ g_timeout_counter = 0;
+ delete closure;
+}
+
+BOOST_AUTO_TEST_CASE (CcnxWrapperSelector)
+{
+
+ Closure *closure = new Closure(1, bind(dataCallback, _1, _2), bind(timeout, _1));
+
+ Selectors selectors;
+ selectors.interestLifetime(1);
+
+ string n1 = "/random/01";
+ c1->sendInterest(Name(n1), closure, selectors);
+ sleep(2);
+ c2->publishData(Name(n1), (const unsigned char *)n1.c_str(), n1.size(), 4);
+ usleep(100000);
+ BOOST_CHECK_EQUAL(g_timeout_counter, 1);
+ BOOST_CHECK_EQUAL(g_dataCallback_counter, 0);
+
+ string n2 = "/random/02";
+ selectors.interestLifetime(2);
+ c1->sendInterest(Name(n2), closure, selectors);
+ sleep(1);
+ c2->publishData(Name(n2), (const unsigned char *)n2.c_str(), n2.size(), 4);
+ usleep(100000);
+ BOOST_CHECK_EQUAL(g_timeout_counter, 1);
+ BOOST_CHECK_EQUAL(g_dataCallback_counter, 1);
+
+ // reset
+ g_dataCallback_counter = 0;
+ g_timeout_counter = 0;
delete closure;
}