Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, Regents of the University of California. |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 11 | * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 21 | #include "sync-log.hpp" |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 22 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 23 | #include "test-common.hpp" |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 24 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 25 | namespace ndn { |
| 26 | namespace chronoshare { |
| 27 | namespace tests { |
| 28 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 29 | namespace fs = boost::filesystem; |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 30 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 31 | BOOST_FIXTURE_TEST_SUITE(TestSyncLog, IdentityManagementTimeFixture) |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 33 | BOOST_AUTO_TEST_CASE(BasicDatabaseTest) |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 34 | { |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 35 | fs::path tmpdir = fs::unique_path(UNIT_TEST_CONFIG_PATH); |
| 36 | if (exists(tmpdir)) { |
| 37 | remove_all(tmpdir); |
| 38 | } |
Alexander Afanasyev | 8e2104a | 2013-01-22 10:56:18 -0800 | [diff] [blame] | 39 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 40 | SyncLog db(tmpdir, Name("/lijing")); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 41 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 42 | ndn::ConstBufferPtr hash = db.RememberStateInStateLog(); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 43 | // should be empty |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 44 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 46 | "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26"); |
| 47 | |
| 48 | db.UpdateDeviceSeqNo(Name("/lijing"), 1); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 49 | hash = db.RememberStateInStateLog(); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 50 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 52 | "91A849EEDE75ACD56AE1BCB99E92D8FB28757683BC387DBB0E59C3108FCF4F18"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 53 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 54 | db.UpdateDeviceSeqNo(Name("/lijing"), 2); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 55 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 57 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 58 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 59 | db.UpdateDeviceSeqNo(Name("/lijing"), 2); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 60 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 61 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 62 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 63 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 64 | db.UpdateDeviceSeqNo(Name("/lijing"), 1); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 65 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 66 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 67 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 68 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 69 | db.UpdateLocator(Name("/lijing"), Name("/hawaii")); |
Zhenkai Zhu | 6e7d4d2 | 2013-01-15 18:18:18 -0800 | [diff] [blame] | 70 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 71 | BOOST_CHECK_EQUAL(db.LookupLocator(Name("/lijing")), Name("/hawaii")); |
Zhenkai Zhu | 6e7d4d2 | 2013-01-15 18:18:18 -0800 | [diff] [blame] | 72 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 73 | SyncStateMsgPtr msg = db.FindStateDifferences("00", "95284D3132A7A88B85C5141CA63EFA68B7A7DAF37315DEF69E296A0C24692833"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(msg->state_size(), 0); |
Alexander Afanasyev | 5ec5a8f | 2013-01-17 17:30:33 -0800 | [diff] [blame] | 75 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 76 | msg = db.FindStateDifferences("00", |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 77 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 78 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 79 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 80 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 2); |
Alexander Afanasyev | 8e2104a | 2013-01-22 10:56:18 -0800 | [diff] [blame] | 81 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 82 | msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282", |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 83 | "00"); |
| 84 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 85 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::DELETE); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 86 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 87 | msg = db.FindStateDifferences("94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26", |
| 88 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 90 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 91 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 2); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 92 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 93 | msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282", |
| 94 | "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 95 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 96 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 97 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 0); |
Alexander Afanasyev | 8e2104a | 2013-01-22 10:56:18 -0800 | [diff] [blame] | 98 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 99 | db.UpdateDeviceSeqNo(Name("/shuai"), 1); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 100 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 102 | "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C"); |
Alexander Afanasyev | 5ec5a8f | 2013-01-17 17:30:33 -0800 | [diff] [blame] | 103 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 104 | msg = db.FindStateDifferences("00", |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 105 | "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 106 | BOOST_CHECK_EQUAL(msg->state_size(), 2); |
| 107 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 108 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 2); |
Alexander Afanasyev | 5ec5a8f | 2013-01-17 17:30:33 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 110 | BOOST_CHECK_EQUAL(msg->state(1).type(), SyncState::UPDATE); |
| 111 | BOOST_CHECK_EQUAL(msg->state(1).seq(), 1); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_SUITE_END() |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 115 | |
| 116 | } // namespace tests |
| 117 | } // namespace chronoshare |
| 118 | } // namespace ndn |