blob: b0ce1123321549d532df61139aa8f248807ad2c8 [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yukai Tuccdcdba2016-10-24 13:48:01 -07003 * Copyright (c) 2013-2017, Regents of the University of California.
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08004 *
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 Tuccdcdba2016-10-24 13:48:01 -070020
21#include "sync-state.pb.h"
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080022#include "sync-core.hpp"
Yukai Tuccdcdba2016-10-24 13:48:01 -070023
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080024#include <boost/iostreams/device/back_inserter.hpp>
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080025#include <boost/iostreams/filter/gzip.hpp>
26#include <boost/iostreams/filtering_stream.hpp>
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080027
Yukai Tuccdcdba2016-10-24 13:48:01 -070028#include "test-common.hpp"
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080029
Yukai Tuccdcdba2016-10-24 13:48:01 -070030namespace ndn {
31namespace chronoshare {
32namespace tests {
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080033
Yukai Tuccdcdba2016-10-24 13:48:01 -070034INIT_LOGGER("Test.protobuf")
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080035
Yukai Tuccdcdba2016-10-24 13:48:01 -070036BOOST_AUTO_TEST_SUITE(TestSyncStatePb)
37
38BOOST_AUTO_TEST_CASE(Serialize)
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080039{
Yukai Tuccdcdba2016-10-24 13:48:01 -070040 auto msg = make_shared<SyncStateMsg>();
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080041
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080042 SyncState* state = msg->add_state();
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080043 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
Yukai Tuccdcdba2016-10-24 13:48:01 -070049 ndn::ConstBufferPtr bb = serializeMsg<SyncStateMsg>(*msg);
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080050
Yukai Tuccdcdba2016-10-24 13:48:01 -070051 ndn::ConstBufferPtr cb = serializeGZipMsg<SyncStateMsg>(*msg);
52 BOOST_CHECK_LT(cb->size(), bb->size());
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080053
54 SyncStateMsgPtr msg1 = deserializeGZipMsg<SyncStateMsg>(*cb);
55
Yukai Tuccdcdba2016-10-24 13:48:01 -070056 BOOST_REQUIRE_EQUAL(msg1->state_size(), 1);
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080057
58 SyncState state1 = msg1->state(0);
59 BOOST_CHECK_EQUAL(state->seq(), state1.seq());
60 BOOST_CHECK_EQUAL(state->type(), state1.type());
Yukai Tuccdcdba2016-10-24 13:48:01 -070061
62 std::string sx(x, 100);
Zhenkai Zhu7c1cd8d2013-01-31 12:27:17 -080063 BOOST_CHECK_EQUAL(sx, state1.name());
64 BOOST_CHECK_EQUAL(sx, state1.locator());
65}
66
67BOOST_AUTO_TEST_SUITE_END()
Yukai Tuccdcdba2016-10-24 13:48:01 -070068
69} // namespace tests
70} // namespace chronoshare
71} // namespace ndn