blob: 1fc9f5de15ea8a49a91fb1ac5c02ff77df6a1eb1 [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/*
Davide Pesavento11904062022-04-14 22:33:28 -04003 * Copyright (c) 2018-2022, 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
weijia yuan3aa8d2b2018-03-06 15:35:57 -080022#include "common.hpp"
23
Shuo Chenba793e92014-03-17 17:17:16 -070024#include <boost/test/unit_test.hpp>
25
Davide Pesavento11904062022-04-14 22:33:28 -040026namespace repo::tests {
Shuo Chenba793e92014-03-17 17:17:16 -070027
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070028BOOST_AUTO_TEST_SUITE(RepoCommandResponse)
Shuo Chenba793e92014-03-17 17:17:16 -070029
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070030BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070031{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070032 repo::RepoCommandResponse response;
weijia yuan82cf9142018-10-21 12:25:02 -070033 response.setCode(404);
Shuo Chenba793e92014-03-17 17:17:16 -070034 response.setStartBlockId(1);
35 response.setEndBlockId(100);
36 response.setProcessId(1234567890);
37 response.setInsertNum(100);
38 response.setDeleteNum(100);
39
weijia yuan3aa8d2b2018-03-06 15:35:57 -080040 Block wire = response.wireEncode();
Shuo Chenba793e92014-03-17 17:17:16 -070041
42 // These octets are obtained by the snippet below.
43 // This check is intended to detect unexpected encoding change in the future.
weijia yuan3aa8d2b2018-03-06 15:35:57 -080044 // Construct a \c Block from hexadecimal \p input.
Shuo Chenba793e92014-03-17 17:17:16 -070045
weijia yuan3aa8d2b2018-03-06 15:35:57 -080046 Block expected = "CF16 CE04499602D2D0020194CC0101CD0164D10164D20164"_block;
47
48 BOOST_CHECK_EQUAL(wire, expected);
Shuo Chenba793e92014-03-17 17:17:16 -070049
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070050 repo::RepoCommandResponse decoded(wire);
weijia yuan82cf9142018-10-21 12:25:02 -070051 BOOST_CHECK_EQUAL(decoded.getCode(), response.getCode());
Shuo Chenba793e92014-03-17 17:17:16 -070052 BOOST_CHECK_EQUAL(decoded.getStartBlockId(), response.getStartBlockId());
53 BOOST_CHECK_EQUAL(decoded.getEndBlockId(), response.getEndBlockId());
54 BOOST_CHECK_EQUAL(decoded.getProcessId(), response.getProcessId());
55 BOOST_CHECK_EQUAL(decoded.getInsertNum(), response.getInsertNum());
56 BOOST_CHECK_EQUAL(decoded.getDeleteNum(), response.getDeleteNum());
57}
58
59BOOST_AUTO_TEST_SUITE_END()
60
Davide Pesavento11904062022-04-14 22:33:28 -040061} // namespace repo::tests