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 | INIT_LOGGER("Test.SyncLog") |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 32 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 33 | BOOST_FIXTURE_TEST_SUITE(TestSyncLog, IdentityManagementTimeFixture) |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 34 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 35 | BOOST_AUTO_TEST_CASE(BasicDatabaseTest) |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 36 | { |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 37 | fs::path tmpdir = fs::unique_path(UNIT_TEST_CONFIG_PATH); |
| 38 | if (exists(tmpdir)) { |
| 39 | remove_all(tmpdir); |
| 40 | } |
Alexander Afanasyev | 8e2104a | 2013-01-22 10:56:18 -0800 | [diff] [blame] | 41 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 42 | SyncLog db(tmpdir, Name("/lijing")); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 43 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 44 | ndn::ConstBufferPtr hash = db.RememberStateInStateLog(); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 45 | // should be empty |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 46 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 47 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 48 | "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26"); |
| 49 | |
| 50 | db.UpdateDeviceSeqNo(Name("/lijing"), 1); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 51 | hash = db.RememberStateInStateLog(); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 52 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 53 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 54 | "91A849EEDE75ACD56AE1BCB99E92D8FB28757683BC387DBB0E59C3108FCF4F18"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 55 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 56 | db.UpdateDeviceSeqNo(Name("/lijing"), 2); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 57 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 58 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 59 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 60 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 61 | db.UpdateDeviceSeqNo(Name("/lijing"), 2); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 62 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 63 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 64 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 65 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 66 | db.UpdateDeviceSeqNo(Name("/lijing"), 1); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 67 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 68 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 69 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 70 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 71 | db.UpdateLocator(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 | BOOST_CHECK_EQUAL(db.LookupLocator(Name("/lijing")), Name("/hawaii")); |
Zhenkai Zhu | 6e7d4d2 | 2013-01-15 18:18:18 -0800 | [diff] [blame] | 74 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 75 | SyncStateMsgPtr msg = db.FindStateDifferences("00", "95284D3132A7A88B85C5141CA63EFA68B7A7DAF37315DEF69E296A0C24692833"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(msg->state_size(), 0); |
Alexander Afanasyev | 5ec5a8f | 2013-01-17 17:30:33 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 78 | msg = db.FindStateDifferences("00", |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 79 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 81 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 82 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 2); |
Alexander Afanasyev | 8e2104a | 2013-01-22 10:56:18 -0800 | [diff] [blame] | 83 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 84 | msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282", |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 85 | "00"); |
| 86 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 87 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::DELETE); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 88 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 89 | msg = db.FindStateDifferences("94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26", |
| 90 | "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 91 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 92 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 93 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 2); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 94 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 95 | msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282", |
| 96 | "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(msg->state_size(), 1); |
| 98 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 99 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 0); |
Alexander Afanasyev | 8e2104a | 2013-01-22 10:56:18 -0800 | [diff] [blame] | 100 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 101 | db.UpdateDeviceSeqNo(Name("/shuai"), 1); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 102 | hash = db.RememberStateInStateLog(); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 103 | BOOST_CHECK_EQUAL(toHex(*hash), |
| 104 | "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C"); |
Alexander Afanasyev | 5ec5a8f | 2013-01-17 17:30:33 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 106 | msg = db.FindStateDifferences("00", |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 107 | "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 108 | BOOST_CHECK_EQUAL(msg->state_size(), 2); |
| 109 | BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE); |
| 110 | BOOST_CHECK_EQUAL(msg->state(0).seq(), 2); |
Alexander Afanasyev | 5ec5a8f | 2013-01-17 17:30:33 -0800 | [diff] [blame] | 111 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 112 | BOOST_CHECK_EQUAL(msg->state(1).type(), SyncState::UPDATE); |
| 113 | BOOST_CHECK_EQUAL(msg->state(1).seq(), 1); |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | BOOST_AUTO_TEST_SUITE_END() |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame^] | 117 | |
| 118 | } // namespace tests |
| 119 | } // namespace chronoshare |
| 120 | } // namespace ndn |