blob: f9d5226950994e1c175bf996368fd87b4ee0d0b3 [file] [log] [blame]
Shuo Chenba793e92014-03-17 17:17:16 -07001/* -*- 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
11namespace repo {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070012namespace tests {
Shuo Chenba793e92014-03-17 17:17:16 -070013
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070014BOOST_AUTO_TEST_SUITE(RepoCommandResponse)
Shuo Chenba793e92014-03-17 17:17:16 -070015
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070016BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070017{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070018 repo::RepoCommandResponse response;
Shuo Chenba793e92014-03-17 17:17:16 -070019 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 Afanasyevb0c78ea2014-04-15 18:12:04 -070042 BOOST_REQUIRE_NO_THROW(repo::RepoCommandResponse(wire));
Shuo Chenba793e92014-03-17 17:17:16 -070043
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070044 repo::RepoCommandResponse decoded(wire);
Shuo Chenba793e92014-03-17 17:17:16 -070045 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
53BOOST_AUTO_TEST_SUITE_END()
54
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070055} // namespace tests
Shuo Chenba793e92014-03-17 17:17:16 -070056} // namespace repo