Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 759214f | 2018-03-11 21:03:32 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 3 | * Copyright (c) 2018-2022, Regents of the University of California. |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 4 | * |
| 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 Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 20 | #include "repo-command-response.hpp" |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 21 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 22 | #include "common.hpp" |
| 23 | |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 24 | #include <boost/test/unit_test.hpp> |
| 25 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 26 | namespace repo::tests { |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 28 | BOOST_AUTO_TEST_SUITE(RepoCommandResponse) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 30 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 31 | { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 32 | repo::RepoCommandResponse response; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 33 | response.setCode(404); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 34 | response.setStartBlockId(1); |
| 35 | response.setEndBlockId(100); |
| 36 | response.setProcessId(1234567890); |
| 37 | response.setInsertNum(100); |
| 38 | response.setDeleteNum(100); |
| 39 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 40 | Block wire = response.wireEncode(); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 41 | |
| 42 | // These octets are obtained by the snippet below. |
| 43 | // This check is intended to detect unexpected encoding change in the future. |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 44 | // Construct a \c Block from hexadecimal \p input. |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 45 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 46 | Block expected = "CF16 CE04499602D2D0020194CC0101CD0164D10164D20164"_block; |
| 47 | |
| 48 | BOOST_CHECK_EQUAL(wire, expected); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 50 | repo::RepoCommandResponse decoded(wire); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(decoded.getCode(), response.getCode()); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 52 | 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 | |
| 59 | BOOST_AUTO_TEST_SUITE_END() |
| 60 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 61 | } // namespace repo::tests |