Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
| 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 | */ |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 20 | #include "ccnx-common.hpp" |
| 21 | #include "sync-core.hpp" |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 22 | #include <boost/iostreams/device/back_inserter.hpp> |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 23 | #include <boost/iostreams/filter/gzip.hpp> |
| 24 | #include <boost/iostreams/filtering_stream.hpp> |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 25 | #include <boost/make_shared.hpp> |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 26 | #include <boost/make_shared.hpp> |
| 27 | #include <boost/range/iterator_range.hpp> |
| 28 | #include <boost/test/unit_test.hpp> |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 30 | using namespace Ndnx; |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 31 | using namespace std; |
| 32 | using namespace boost; |
| 33 | |
| 34 | BOOST_AUTO_TEST_SUITE(ProtobufTests) |
| 35 | |
| 36 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 37 | BOOST_AUTO_TEST_CASE(TestGzipProtobuf) |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 38 | { |
| 39 | SyncStateMsgPtr msg = make_shared<SyncStateMsg>(); |
| 40 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 41 | SyncState* state = msg->add_state(); |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 42 | state->set_type(SyncState::UPDATE); |
| 43 | state->set_seq(100); |
| 44 | char x[100] = {'a'}; |
| 45 | state->set_locator(&x[0], sizeof(x)); |
| 46 | state->set_name(&x[0], sizeof(x)); |
| 47 | |
| 48 | BytesPtr bb = serializeMsg<SyncStateMsg>(*msg); |
| 49 | |
| 50 | BytesPtr cb = serializeGZipMsg<SyncStateMsg>(*msg); |
| 51 | BOOST_CHECK(cb->size() < bb->size()); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame^] | 52 | cout << cb->size() << ", " << bb->size() << endl; |
Zhenkai Zhu | 7c1cd8d | 2013-01-31 12:27:17 -0800 | [diff] [blame] | 53 | |
| 54 | SyncStateMsgPtr msg1 = deserializeGZipMsg<SyncStateMsg>(*cb); |
| 55 | |
| 56 | BOOST_REQUIRE(msg1->state_size() == 1); |
| 57 | |
| 58 | SyncState state1 = msg1->state(0); |
| 59 | BOOST_CHECK_EQUAL(state->seq(), state1.seq()); |
| 60 | BOOST_CHECK_EQUAL(state->type(), state1.type()); |
| 61 | string sx(x, 100); |
| 62 | BOOST_CHECK_EQUAL(sx, state1.name()); |
| 63 | BOOST_CHECK_EQUAL(sx, state1.locator()); |
| 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_SUITE_END() |