blob: 0a815fd6f41344ebfa23a967a72031fc390aee5f [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2018, The University of Memphis
4 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20#include "detail/state.hpp"
21
22#include <boost/test/unit_test.hpp>
23#include <ndn-cxx/name.hpp>
24#include <ndn-cxx/data.hpp>
25
26namespace psync {
27
28using namespace ndn;
29
30BOOST_AUTO_TEST_SUITE(TestState)
31
Ashlesh Gawandeec43b362018-08-01 15:15:01 -050032BOOST_AUTO_TEST_CASE(EncodeDecode)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050033{
34 State state;
35 state.addContent(ndn::Name("test1"));
36 state.addContent(ndn::Name("test2"));
37
38 ndn::Data data;
39 data.setContent(state.wireEncode());
40 State rcvdState(data.getContent());
41
42 BOOST_CHECK(state.getContent() == rcvdState.getContent());
Ashlesh Gawandeec43b362018-08-01 15:15:01 -050043
44 // Simulate getting buffer content from segment fetcher
45 ndn::Buffer buffer(data.getContent().value_size());
46 std::copy(data.getContent().value_begin(),
47 data.getContent().value_end(),
48 buffer.begin());
49
50 ndn::ConstBufferPtr buffer2 = make_shared<ndn::Buffer>(buffer);
51
52 ndn::Block block(std::move(buffer2));
53
54 State state2;
55 state2.wireDecode(block);
56
57 BOOST_CHECK(state.getContent() == state2.getContent());
58}
59
60BOOST_AUTO_TEST_CASE(EmptyContent)
61{
62 ndn::Data data;
63 BOOST_CHECK_NO_THROW(State state(data.getContent()));
64
65 State state(data.getContent());
66 BOOST_CHECK_EQUAL(state.getContent().size(), 0);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050067}
68
69BOOST_AUTO_TEST_SUITE_END()
70
71} // namespace psync