Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014, Regents of the University of California. |
| 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 | |
| 20 | #include "../helpers/repo-command-response.hpp" |
| 21 | |
| 22 | #include <boost/test/unit_test.hpp> |
| 23 | |
| 24 | namespace repo { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 25 | namespace tests { |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 27 | BOOST_AUTO_TEST_SUITE(RepoCommandResponse) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 29 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 30 | { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 31 | repo::RepoCommandResponse response; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 32 | 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. |
| 43 | //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 44 | // 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 55 | BOOST_REQUIRE_NO_THROW(repo::RepoCommandResponse(wire)); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 56 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 57 | repo::RepoCommandResponse decoded(wire); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 58 | BOOST_CHECK_EQUAL(decoded.getStatusCode(), response.getStatusCode()); |
| 59 | BOOST_CHECK_EQUAL(decoded.getStartBlockId(), response.getStartBlockId()); |
| 60 | BOOST_CHECK_EQUAL(decoded.getEndBlockId(), response.getEndBlockId()); |
| 61 | BOOST_CHECK_EQUAL(decoded.getProcessId(), response.getProcessId()); |
| 62 | BOOST_CHECK_EQUAL(decoded.getInsertNum(), response.getInsertNum()); |
| 63 | BOOST_CHECK_EQUAL(decoded.getDeleteNum(), response.getDeleteNum()); |
| 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_SUITE_END() |
| 67 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 68 | } // namespace tests |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 69 | } // namespace repo |