blob: 7effeccd4b8658d34e17166f9a904c60e43d40e8 [file] [log] [blame]
Qiuhan Ding8c095fd2014-11-19 17:38:32 -08001#include "logic.hpp"
2
3#include "boost-test.hpp"
4
5namespace chronosync {
6namespace test {
7
8using std::vector;
9
10
11class Handler
12{
13public:
14 Handler(ndn::Face& face,
15 const Name& syncPrefix,
16 const Name& userPrefix)
17 : logic(face,
18 syncPrefix,
19 userPrefix,
20 bind(&Handler::onUpdate, this, _1))
21 {
22 }
23
24 void
25 onUpdate(const vector<MissingDataInfo>& v)
26 {
27
28 }
29
30 void
31 updateSeqNo(const SeqNo& seqNo)
32 {
33 logic.updateSeqNo(seqNo);
34 }
35
36 void
37 addUserNode(const Name& prefix)
38 {
39 logic.addUserNode(prefix);
40 }
41
42 void
43 removeUserNode(const Name& prefix)
44 {
45 logic.removeUserNode(prefix);
46 }
47
48
49 Logic logic;
50 std::map<Name, SeqNo> map;
51};
52
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -080053class MultiUserFixture
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080054{
55public:
56
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -080057 MultiUserFixture()
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080058 : syncPrefix("/ndn/broadcast/sync")
59 , scheduler(io)
60 {
61 syncPrefix.appendVersion();
62 userPrefix[0] = Name("/user0");
63 userPrefix[1] = Name("/user1");
64 userPrefix[2] = Name("/user2");
65
66 face = make_shared<ndn::Face>(ref(io));
67 }
68
69 Name syncPrefix;
70 Name userPrefix[3];
71
72 boost::asio::io_service io;
73 shared_ptr<ndn::Face> face;
74 ndn::Scheduler scheduler;
75 shared_ptr<Handler> handler;
76};
77
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -080078BOOST_FIXTURE_TEST_SUITE(MultiUserTests, MultiUserFixture)
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080079
80BOOST_AUTO_TEST_CASE(ThreeUserNode)
81{
82 handler = make_shared<Handler>(ref(*face), syncPrefix, userPrefix[0]);
83 handler->addUserNode(userPrefix[1]);
84 handler->addUserNode(userPrefix[2]);
85 handler->removeUserNode(userPrefix[0]);
86
87 handler->logic.setDefaultUserPrefix(userPrefix[1]);
88 handler->updateSeqNo(1);
89 BOOST_CHECK_EQUAL(handler->logic.getSeqNo(userPrefix[1]), 1);
90
91 handler->logic.updateSeqNo(2, userPrefix[2]);
92 handler->logic.setDefaultUserPrefix(userPrefix[2]);
93
94 BOOST_CHECK_EQUAL(handler->logic.getSeqNo(), 2);
95
96 BOOST_REQUIRE_THROW(handler->logic.getSeqNo(userPrefix[0]), Logic::Error);
97 BOOST_REQUIRE_THROW(handler->logic.getSessionName(userPrefix[0]), Logic::Error);
98
99}
100
101BOOST_AUTO_TEST_SUITE_END()
102
103} // namespace test
104} // namespace chronosync