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 | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
| 6 | * |
| 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. |
| 10 | * |
| 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. |
| 14 | * |
| 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. |
| 19 | */ |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 20 | |
| 21 | #include "sync-state.pb.h" |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 22 | #include "sync-core.hpp" |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 24 | #include <boost/iostreams/device/back_inserter.hpp> |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 25 | #include <boost/iostreams/filter/gzip.hpp> |
| 26 | #include <boost/iostreams/filtering_stream.hpp> |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 27 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 28 | #include "test-common.hpp" |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 29 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 30 | namespace ndn { |
| 31 | namespace chronoshare { |
| 32 | namespace tests { |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 33 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(TestSyncStatePb) |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Serialize) |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 37 | { |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 38 | auto msg = make_shared<SyncStateMsg>(); |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 40 | SyncState* state = msg->add_state(); |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 41 | state->set_type(SyncState::UPDATE); |
| 42 | state->set_seq(100); |
| 43 | char x[100] = {'a'}; |
| 44 | state->set_locator(&x[0], sizeof(x)); |
| 45 | state->set_name(&x[0], sizeof(x)); |
| 46 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 47 | ndn::ConstBufferPtr bb = serializeMsg<SyncStateMsg>(*msg); |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 48 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 49 | ndn::ConstBufferPtr cb = serializeGZipMsg<SyncStateMsg>(*msg); |
| 50 | BOOST_CHECK_LT(cb->size(), bb->size()); |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 51 | |
| 52 | SyncStateMsgPtr msg1 = deserializeGZipMsg<SyncStateMsg>(*cb); |
| 53 | |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 54 | BOOST_REQUIRE_EQUAL(msg1->state_size(), 1); |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 55 | |
| 56 | SyncState state1 = msg1->state(0); |
| 57 | BOOST_CHECK_EQUAL(state->seq(), state1.seq()); |
| 58 | BOOST_CHECK_EQUAL(state->type(), state1.type()); |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 59 | |
| 60 | std::string sx(x, 100); |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 61 | BOOST_CHECK_EQUAL(sx, state1.name()); |
| 62 | BOOST_CHECK_EQUAL(sx, state1.locator()); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_SUITE_END() |
Yukai Tu | ccdcdba | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 66 | |
| 67 | } // namespace tests |
| 68 | } // namespace chronoshare |
| 69 | } // namespace ndn |