blob: 6bf6f2366c1237afd4363d871a811ee6ca55db6c [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- 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 Afanasyevf4cde4e2016-12-25 13:42:57 -080020#include "ccnx-common.hpp"
21#include "sync-core.hpp"
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080022#include <boost/iostreams/device/back_inserter.hpp>
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080023#include <boost/iostreams/filter/gzip.hpp>
24#include <boost/iostreams/filtering_stream.hpp>
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080025#include <boost/make_shared.hpp>
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080026#include <boost/make_shared.hpp>
27#include <boost/range/iterator_range.hpp>
28#include <boost/test/unit_test.hpp>
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080029
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070030using namespace Ndnx;
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080031using namespace std;
32using namespace boost;
33
34BOOST_AUTO_TEST_SUITE(ProtobufTests)
35
36
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080037BOOST_AUTO_TEST_CASE(TestGzipProtobuf)
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080038{
39 SyncStateMsgPtr msg = make_shared<SyncStateMsg>();
40
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080041 SyncState* state = msg->add_state();
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080042 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 Afanasyeveda3b7a2016-12-25 11:26:40 -080052 cout << cb->size() << ", " << bb->size() << endl;
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080053
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
66BOOST_AUTO_TEST_SUITE_END()