logic: allow manipulating multiple nodes in single logic

Change-Id: Iaa2a2b08e891d41c9aa71c13ffc531bef406b6d8
diff --git a/tests/unit-tests/test-multiple-user.cpp b/tests/unit-tests/test-multiple-user.cpp
new file mode 100644
index 0000000..44209e8
--- /dev/null
+++ b/tests/unit-tests/test-multiple-user.cpp
@@ -0,0 +1,104 @@
+#include "logic.hpp"
+
+#include "boost-test.hpp"
+
+namespace chronosync {
+namespace test {
+
+using std::vector;
+
+
+class Handler
+{
+public:
+  Handler(ndn::Face& face,
+          const Name& syncPrefix,
+          const Name& userPrefix)
+    : logic(face,
+            syncPrefix,
+            userPrefix,
+            bind(&Handler::onUpdate, this, _1))
+  {
+  }
+
+  void
+  onUpdate(const vector<MissingDataInfo>& v)
+  {
+
+  }
+
+  void
+  updateSeqNo(const SeqNo& seqNo)
+  {
+    logic.updateSeqNo(seqNo);
+  }
+
+  void
+  addUserNode(const Name& prefix)
+  {
+    logic.addUserNode(prefix);
+  }
+
+  void
+  removeUserNode(const Name& prefix)
+  {
+    logic.removeUserNode(prefix);
+  }
+
+
+  Logic logic;
+  std::map<Name, SeqNo> map;
+};
+
+class LogicFixture
+{
+public:
+
+  LogicFixture()
+    : syncPrefix("/ndn/broadcast/sync")
+    , scheduler(io)
+  {
+    syncPrefix.appendVersion();
+    userPrefix[0] = Name("/user0");
+    userPrefix[1] = Name("/user1");
+    userPrefix[2] = Name("/user2");
+
+    face = make_shared<ndn::Face>(ref(io));
+  }
+
+  Name syncPrefix;
+  Name userPrefix[3];
+
+  boost::asio::io_service io;
+  shared_ptr<ndn::Face> face;
+  ndn::Scheduler scheduler;
+  shared_ptr<Handler> handler;
+};
+
+BOOST_FIXTURE_TEST_SUITE(LogicTests, LogicFixture)
+
+BOOST_AUTO_TEST_CASE(ThreeUserNode)
+{
+  handler = make_shared<Handler>(ref(*face), syncPrefix, userPrefix[0]);
+  handler->addUserNode(userPrefix[1]);
+  handler->addUserNode(userPrefix[2]);
+  handler->removeUserNode(userPrefix[0]);
+
+  handler->logic.setDefaultUserPrefix(userPrefix[1]);
+  handler->updateSeqNo(1);
+  BOOST_CHECK_EQUAL(handler->logic.getSeqNo(userPrefix[1]), 1);
+
+  handler->logic.updateSeqNo(2, userPrefix[2]);
+  handler->logic.setDefaultUserPrefix(userPrefix[2]);
+
+  BOOST_CHECK_EQUAL(handler->logic.getSeqNo(), 2);
+
+  BOOST_REQUIRE_THROW(handler->logic.getSeqNo(userPrefix[0]), Logic::Error);
+  BOOST_REQUIRE_THROW(handler->logic.getSessionName(userPrefix[0]), Logic::Error);
+
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace test
+} // namespace chronosync