fixes: Remove sync scheduler; Use ndn::time; Passed all the test cases
Change-Id: I50e8cd94f71f463793e4d19d5bf65e190cac6e59
diff --git a/tests/test_socket.cc b/tests/test_socket.cc
index cc6e56b..fd17c44 100644
--- a/tests/test_socket.cc
+++ b/tests/test_socket.cc
@@ -46,6 +46,10 @@
class TestSocketApp {
public:
+ TestSocketApp()
+ : sum(0)
+ {}
+
map<ndn::Name, string> data;
void set(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
// _LOG_FUNCTION (this << ", " << str1);
@@ -62,7 +66,7 @@
void setNum(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
int n = dataPacket->getContent().value_size() / 4;
- int *numbers = new int [n];
+ uint32_t *numbers = new uint32_t [n];
memcpy(numbers, dataPacket->getContent().value(), dataPacket->getContent().value_size());
for (int i = 0; i < n; i++) {
sum += numbers[i];
@@ -81,7 +85,7 @@
delete numbers;
}
- int sum;
+ uint32_t sum;
void fetchAll(const vector<MissingDataInfo> &v, SyncSocket *socket) {
int n = v.size();
@@ -101,9 +105,9 @@
PRINT
- std::cout << "In fetchNumbers. size of v is: " << n << std::endl;
+ // std::cout << "In fetchNumbers. size of v is: " << n << std::endl;
for (int i = 0; i < n; i++) {
- std::cout << "In fetchNumbers. v[i].low is (" <<v[i].low.getSession() <<", " << v[i].low.getSeq() << ") v[i].high is ("<<v[i].high.getSession() <<", " <<v[i].high.getSeq()<<")" << std::endl;
+ // std::cout << "In fetchNumbers. v[i].low is (" <<v[i].low.getSession() <<", " << v[i].low.getSeq() << ") v[i].high is ("<<v[i].high.getSession() <<", " <<v[i].high.getSeq()<<")" << std::endl;
for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
PRINT
socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::setNum, this, _1));
@@ -222,11 +226,17 @@
void
check(int round)
{
- cout << "++++++++++++++++++ " << round << " " << m_a1.toString() << endl;
BOOST_CHECK_EQUAL(m_a1.toString(), m_a2.toString());
BOOST_CHECK_EQUAL(m_a2.toString(), m_a3.toString());
}
+ void
+ done()
+ {
+ m_s1.reset();
+ m_s2.reset();
+ m_s3.reset();
+ }
TestSocketApp m_a1, m_a2, m_a3;
@@ -297,10 +307,19 @@
void
check(int num)
{
+ _LOG_DEBUG ("codnum " << num);
+ _LOG_DEBUG ("a1 sum " << m_a1.sum);
+ _LOG_DEBUG ("a2 sum " << m_a2.sum);
+
BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num);
}
-
+ void
+ done()
+ {
+ m_s1.reset();
+ m_s2.reset();
+ }
TestSocketApp m_a1, m_a2;
ndn::shared_ptr<ndn::ValidatorNull> m_validator;
@@ -335,21 +354,23 @@
string data3 = "You surf the Internet, I surf the real world";
string data4 = "I got a fortune cookie once that said 'You like Chinese food'";
string data5 = "Real men wear pink. Why? Because their wives make them";
- scheduler.scheduleEvent(ndn::time::seconds(2.18), ndn::bind(&TestSet1::publishSocket3, &testSet1, 0, data3));
- scheduler.scheduleEvent(ndn::time::seconds(2.20), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data4));
- scheduler.scheduleEvent(ndn::time::seconds(2.21), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data5));
- scheduler.scheduleEvent(ndn::time::seconds(3.21), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/0", data3));
- scheduler.scheduleEvent(ndn::time::seconds(3.22), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/0", data4));
- scheduler.scheduleEvent(ndn::time::seconds(3.23), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/1", data5));
+ scheduler.scheduleEvent(ndn::time::seconds(3.18), ndn::bind(&TestSet1::publishSocket3, &testSet1, 0, data3));
+ scheduler.scheduleEvent(ndn::time::seconds(3.20), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data4));
+ scheduler.scheduleEvent(ndn::time::seconds(3.21), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data5));
+ scheduler.scheduleEvent(ndn::time::seconds(4.21), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/0", data3));
+ scheduler.scheduleEvent(ndn::time::seconds(4.22), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/0", data4));
+ scheduler.scheduleEvent(ndn::time::seconds(4.23), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/1", data5));
+ scheduler.scheduleEvent(ndn::time::seconds(4.30), ndn::bind(&TestSet1::check, &testSet1, 3));
// not sure weither this is simultanous data generation from multiple sources
_LOG_DEBUG ("Simultaneous publishing");
string data6 = "Shakespeare says: 'Prose before hos.'";
string data7 = "Pick good people, talent never wears out";
- scheduler.scheduleEvent(ndn::time::seconds(3.30), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data6));
- scheduler.scheduleEvent(ndn::time::seconds(3.30), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data7));
- scheduler.scheduleEvent(ndn::time::seconds(4.80), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data6));
- scheduler.scheduleEvent(ndn::time::seconds(4.80), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data7));
- scheduler.scheduleEvent(ndn::time::seconds(4.90), ndn::bind(&TestSet1::check, &testSet1, 3));
+ scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data6));
+ scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data7));
+ scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data6));
+ scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data7));
+ scheduler.scheduleEvent(ndn::time::seconds(6.90), ndn::bind(&TestSet1::check, &testSet1, 4));
+ scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet1::done, &testSet1));
ioService->run();
}
@@ -362,16 +383,17 @@
scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet2::createSyncSocket1, &testSet2));
scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet2::createSyncSocket2, &testSet2));
- int num[5] = {0, 1, 2, 3, 4};
+ uint32_t num[5] = {0, 1, 2, 3, 4};
string data0((const char *) num, sizeof(num));
scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet2::publishSocket1, &testSet2, 0, data0));
scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num)));
scheduler.scheduleEvent(ndn::time::seconds(1.00), ndn::bind(&TestSet2::check, &testSet2, 10));
- int newNum[5] = {9, 7, 2, 1, 1};
+ uint32_t newNum[5] = {9, 7, 2, 1, 1};
string data1((const char *) newNum, sizeof(newNum));
scheduler.scheduleEvent(ndn::time::seconds(1.10), ndn::bind(&TestSet2::publishSocket2, &testSet2, 0, data1));
scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum)));
scheduler.scheduleEvent(ndn::time::seconds(2.00), ndn::bind(&TestSet2::check, &testSet2, 30));
+ scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet2::done, &testSet2));
ioService->run();
}