blob: ab0320781083dac97d3cd38d00466be7ae8eaf63 [file] [log] [blame]
Shuo Chenba793e92014-03-17 17:17:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento759214f2018-03-11 21:03:32 -04002/*
3 * Copyright (c) 2014-2018, Regents of the University of California.
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07004 *
5 * This file is part of NDN repo-ng (Next generation of NDN repository).
6 * See AUTHORS.md for complete list of repo-ng authors and contributors.
7 *
8 * repo-ng 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 * repo-ng 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 * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Shuo Chenba793e92014-03-17 17:17:16 -070018 */
19
Alexander Afanasyev39d98072014-05-04 12:46:29 -070020#include "repo-command-response.hpp"
Shuo Chenba793e92014-03-17 17:17:16 -070021
22#include <boost/test/unit_test.hpp>
23
24namespace repo {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070025namespace tests {
Shuo Chenba793e92014-03-17 17:17:16 -070026
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070027BOOST_AUTO_TEST_SUITE(RepoCommandResponse)
Shuo Chenba793e92014-03-17 17:17:16 -070028
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070029BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070030{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070031 repo::RepoCommandResponse response;
Shuo Chenba793e92014-03-17 17:17:16 -070032 response.setStatusCode(404);
33 response.setStartBlockId(1);
34 response.setEndBlockId(100);
35 response.setProcessId(1234567890);
36 response.setInsertNum(100);
37 response.setDeleteNum(100);
38
39 ndn::Block wire = response.wireEncode();
40
41 // These octets are obtained by the snippet below.
42 // This check is intended to detect unexpected encoding change in the future.
Davide Pesavento759214f2018-03-11 21:03:32 -040043 //for (auto it = wire.begin(); it != wire.end(); ++it) {
Shuo Chenba793e92014-03-17 17:17:16 -070044 // printf("0x%02x, ", *it);
45 //}
46 static const uint8_t expected[] = {
47 0xcf, 0x16, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2, 0xd0, 0x02,
48 0x01, 0x94, 0xcc, 0x01, 0x01, 0xcd, 0x01, 0x64, 0xd1, 0x01,
49 0x64, 0xd2, 0x01, 0x64
50 };
51
52 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
53 wire.begin(), wire.end());
54
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070055 repo::RepoCommandResponse decoded(wire);
Shuo Chenba793e92014-03-17 17:17:16 -070056 BOOST_CHECK_EQUAL(decoded.getStatusCode(), response.getStatusCode());
57 BOOST_CHECK_EQUAL(decoded.getStartBlockId(), response.getStartBlockId());
58 BOOST_CHECK_EQUAL(decoded.getEndBlockId(), response.getEndBlockId());
59 BOOST_CHECK_EQUAL(decoded.getProcessId(), response.getProcessId());
60 BOOST_CHECK_EQUAL(decoded.getInsertNum(), response.getInsertNum());
61 BOOST_CHECK_EQUAL(decoded.getDeleteNum(), response.getDeleteNum());
62}
63
64BOOST_AUTO_TEST_SUITE_END()
65
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070066} // namespace tests
Shuo Chenba793e92014-03-17 17:17:16 -070067} // namespace repo