socket: allow applications to set seq numbers

refs: #4032

Change-Id: I4ed379baaebc1643abf5864f7b674724f901e0e6
diff --git a/tests/unit-tests/test-socket.cpp b/tests/unit-tests/test-socket.cpp
index 9ba1294..0c478ec 100644
--- a/tests/unit-tests/test-socket.cpp
+++ b/tests/unit-tests/test-socket.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2016 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -107,7 +107,7 @@
   }
 
   void
-  fetchNumbers(const vector<MissingDataInfo> &v)
+  fetchNumbers(const vector<MissingDataInfo>& v)
   {
     // std::cerr << "fetchNumbers" << std::endl;
     for (size_t i = 0; i < v.size(); i++) {
@@ -203,6 +203,13 @@
   }
 
   void
+  publishAppData(size_t idx, const string& data, SeqNo seqNo)
+  {
+    app[idx]->socket.publishData(reinterpret_cast<const uint8_t*>(data.c_str()), data.size(),
+                                 ndn::time::milliseconds(1000), seqNo);
+  }
+
+  void
   setAppData(size_t idx, SeqNo seqNo, const string& data)
   {
     Name dataName = sessionName[idx];
@@ -354,6 +361,85 @@
   BOOST_CHECK_EQUAL(app[1]->sum, 30);
 }
 
+BOOST_AUTO_TEST_CASE(BasicDataWithAppSeq)
+{
+  createSocket(0, false);
+  advanceClocks(ndn::time::milliseconds(10), 5);
+  createSocket(1, false);
+  advanceClocks(ndn::time::milliseconds(10), 5);
+  createSocket(2, false);
+  advanceClocks(ndn::time::milliseconds(10), 5);
+
+  string data0 = "Very funny Scotty, now beam down my clothes";
+  publishAppData(0, data0, 100);
+
+  for (int i = 0; i < 50; i++) {
+    advanceClocks(ndn::time::milliseconds(2), 10);
+    passPacket();
+  }
+  setAppData(0, 100, data0);
+
+  advanceClocks(ndn::time::milliseconds(10), 1);
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[1]->toString());
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[2]->toString());
+
+  string data1 = "Yes, give me that ketchup";
+  string data2 = "Don't look conspicuous, it draws fire";
+  publishAppData(0, data1, 200);
+  advanceClocks(ndn::time::milliseconds(10), 1);
+  publishAppData(0, data2, 300);
+
+  for (int i = 0; i < 50; i++) {
+    advanceClocks(ndn::time::milliseconds(2), 10);
+    passPacket();
+  }
+  setAppData(0, 200, data1);
+  advanceClocks(ndn::time::milliseconds(10), 1);
+  setAppData(0, 300, data2);
+
+  advanceClocks(ndn::time::milliseconds(10), 1);
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[1]->toString());
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[2]->toString());
+
+  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";
+  publishAppData(2, data3, 100);
+  advanceClocks(ndn::time::milliseconds(10), 2);
+  publishAppData(1, data4, 100);
+  advanceClocks(ndn::time::milliseconds(10), 1);
+  publishAppData(1, data5, 200);
+
+  for (int i = 0; i < 100; i++) {
+    advanceClocks(ndn::time::milliseconds(2), 10);
+    passPacket();
+  }
+  setAppData(2, 100, data3);
+  advanceClocks(ndn::time::milliseconds(10), 1);
+  setAppData(1, 100, data4);
+  advanceClocks(ndn::time::milliseconds(10), 1);
+  setAppData(1, 200, data5);
+
+  advanceClocks(ndn::time::milliseconds(10), 7);
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[1]->toString());
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[2]->toString());
+
+  string data6 = "Shakespeare says: 'Prose before hos.'";
+  string data7 = "Pick good people, talent never wears out";
+  publishAppData(0, data6, 500);
+  publishAppData(1, data7, 300);
+
+  for (int i = 0; i < 100; i++) {
+    advanceClocks(ndn::time::milliseconds(2), 10);
+    passPacket();
+  }
+  setAppData(0, 500, data6);
+  setAppData(1, 300, data7);
+
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[1]->toString());
+  BOOST_CHECK_EQUAL(app[0]->toString(), app[2]->toString());
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace test