blob: 5bd0f1b71f654721b9ba7c358849c4f7b8347776 [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 */
20
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080021#include "ccnx-common.hpp"
22#include "sync-core.hpp"
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080023#include <boost/make_shared.hpp>
24#include <boost/test/unit_test.hpp>
25#include <boost/iostreams/filter/gzip.hpp>
26#include <boost/iostreams/filtering_stream.hpp>
27#include <boost/iostreams/device/back_inserter.hpp>
28#include <boost/range/iterator_range.hpp>
29#include <boost/make_shared.hpp>
30
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070031using namespace Ndnx;
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080032using namespace std;
33using namespace boost;
34
35BOOST_AUTO_TEST_SUITE(ProtobufTests)
36
37
38BOOST_AUTO_TEST_CASE (TestGzipProtobuf)
39{
40 SyncStateMsgPtr msg = make_shared<SyncStateMsg>();
41
42 SyncState *state = msg->add_state();
43 state->set_type(SyncState::UPDATE);
44 state->set_seq(100);
45 char x[100] = {'a'};
46 state->set_locator(&x[0], sizeof(x));
47 state->set_name(&x[0], sizeof(x));
48
49 BytesPtr bb = serializeMsg<SyncStateMsg>(*msg);
50
51 BytesPtr cb = serializeGZipMsg<SyncStateMsg>(*msg);
52 BOOST_CHECK(cb->size() < bb->size());
53 cout << cb->size() <<", " << bb->size() << endl;
54
55 SyncStateMsgPtr msg1 = deserializeGZipMsg<SyncStateMsg>(*cb);
56
57 BOOST_REQUIRE(msg1->state_size() == 1);
58
59 SyncState state1 = msg1->state(0);
60 BOOST_CHECK_EQUAL(state->seq(), state1.seq());
61 BOOST_CHECK_EQUAL(state->type(), state1.type());
62 string sx(x, 100);
63 BOOST_CHECK_EQUAL(sx, state1.name());
64 BOOST_CHECK_EQUAL(sx, state1.locator());
65}
66
67BOOST_AUTO_TEST_SUITE_END()