Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 1 | #include "logic.hpp" |
| 2 | |
| 3 | #include "boost-test.hpp" |
| 4 | |
| 5 | namespace chronosync { |
| 6 | namespace test { |
| 7 | |
| 8 | using std::vector; |
| 9 | |
| 10 | |
| 11 | class Handler |
| 12 | { |
| 13 | public: |
| 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 Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 53 | class MultiUserFixture |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 54 | { |
| 55 | public: |
| 56 | |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 57 | MultiUserFixture() |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 58 | : 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 Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 78 | BOOST_FIXTURE_TEST_SUITE(MultiUserTests, MultiUserFixture) |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 79 | |
| 80 | BOOST_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 | |
| 101 | BOOST_AUTO_TEST_SUITE_END() |
| 102 | |
| 103 | } // namespace test |
| 104 | } // namespace chronosync |