Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "../helpers/repo-command-response.hpp" |
| 8 | |
| 9 | #include <boost/test/unit_test.hpp> |
| 10 | |
| 11 | namespace repo { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 12 | namespace tests { |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 13 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 14 | BOOST_AUTO_TEST_SUITE(RepoCommandResponse) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 15 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 16 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 17 | { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 18 | repo::RepoCommandResponse response; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 19 | response.setStatusCode(404); |
| 20 | response.setStartBlockId(1); |
| 21 | response.setEndBlockId(100); |
| 22 | response.setProcessId(1234567890); |
| 23 | response.setInsertNum(100); |
| 24 | response.setDeleteNum(100); |
| 25 | |
| 26 | ndn::Block wire = response.wireEncode(); |
| 27 | |
| 28 | // These octets are obtained by the snippet below. |
| 29 | // This check is intended to detect unexpected encoding change in the future. |
| 30 | //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 31 | // printf("0x%02x, ", *it); |
| 32 | //} |
| 33 | static const uint8_t expected[] = { |
| 34 | 0xcf, 0x16, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2, 0xd0, 0x02, |
| 35 | 0x01, 0x94, 0xcc, 0x01, 0x01, 0xcd, 0x01, 0x64, 0xd1, 0x01, |
| 36 | 0x64, 0xd2, 0x01, 0x64 |
| 37 | }; |
| 38 | |
| 39 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 40 | wire.begin(), wire.end()); |
| 41 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 42 | BOOST_REQUIRE_NO_THROW(repo::RepoCommandResponse(wire)); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 44 | repo::RepoCommandResponse decoded(wire); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(decoded.getStatusCode(), response.getStatusCode()); |
| 46 | BOOST_CHECK_EQUAL(decoded.getStartBlockId(), response.getStartBlockId()); |
| 47 | BOOST_CHECK_EQUAL(decoded.getEndBlockId(), response.getEndBlockId()); |
| 48 | BOOST_CHECK_EQUAL(decoded.getProcessId(), response.getProcessId()); |
| 49 | BOOST_CHECK_EQUAL(decoded.getInsertNum(), response.getInsertNum()); |
| 50 | BOOST_CHECK_EQUAL(decoded.getDeleteNum(), response.getDeleteNum()); |
| 51 | } |
| 52 | |
| 53 | BOOST_AUTO_TEST_SUITE_END() |
| 54 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 55 | } // namespace tests |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 56 | } // namespace repo |