Browse Source

meta-info: Add support for application-defined meta information blocks

Change-Id: If9cdef10728d2c285f3f1021cec57d90d0c04e9b
Refs: #2021
pull/1/head
Shock Jiang 11 years ago committed by Alexander Afanasyev
parent
commit
ca7ea70202
  1. 1
      AUTHORS.md
  2. 133
      src/meta-info.cpp
  3. 101
      src/meta-info.hpp
  4. 78
      tests/unit-tests/test-data.cpp
  5. 200
      tests/unit-tests/test-meta-info.cpp

1
AUTHORS.md

@ -25,3 +25,4 @@ in the library:
* Michael Sweatt <https://www.linkedin.com/in/michaelsweatt>
* Lixia Zhang <http://www.cs.ucla.edu/~lixia/home.html>
* Jeff Burke <http://remap.ucla.edu/jburke/>
* Xiaoke Jiang <http://netarchlab.tsinghua.edu.cn/~shock/>

133
src/meta-info.cpp

@ -22,10 +22,15 @@
#include "meta-info.hpp"
#include "encoding/block-helpers.hpp"
#include "encoding/encoding-buffer.hpp"
#include "util/time.hpp"
#include <boost/concept_check.hpp>
#include <boost/type_traits.hpp>
namespace ndn {
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<MetaInfo>));
BOOST_STATIC_ASSERT((boost::is_base_of<tlv::Error, MetaInfo::Error>::value));
MetaInfo::MetaInfo()
: m_type(TYPE_DEFAULT)
, m_freshnessPeriod(-1)
@ -61,6 +66,62 @@ MetaInfo::setFinalBlockId(const name::Component& finalBlockId)
return *this;
}
const std::list<Block>&
MetaInfo::getAppMetaInfo() const
{
return m_appMetaInfo;
}
MetaInfo&
MetaInfo::setAppMetaInfo(const std::list<Block>& info)
{
for (std::list<Block>::const_iterator i = info.begin(); i != info.end(); ++i) {
if (!(128 <= i->type() && i->type() <= 252))
throw Error("AppMetaInfo block has type outside the application range [128, 252]");
}
m_wire.reset();
m_appMetaInfo = info;
return *this;
}
MetaInfo&
MetaInfo::addAppMetaInfo(const Block& block)
{
if (!(128 <= block.type() && block.type() <= 252))
throw Error("AppMetaInfo block has type outside the application range [128, 252]");
m_wire.reset();
m_appMetaInfo.push_back(block);
return *this;
}
bool
MetaInfo::removeAppMetaInfo(uint32_t tlvType)
{
for (std::list<Block>::iterator iter = m_appMetaInfo.begin();
iter != m_appMetaInfo.end(); ++iter) {
if (iter->type() == tlvType) {
m_wire.reset();
m_appMetaInfo.erase(iter);
return true;
}
}
return false;
}
const Block*
MetaInfo::findAppMetaInfo(uint32_t tlvType) const
{
for (std::list<Block>::const_iterator iter = m_appMetaInfo.begin();
iter != m_appMetaInfo.end(); ++iter) {
if (iter->type() == tlvType) {
return &*iter;
}
}
return 0;
}
template<bool T>
size_t
MetaInfo::wireEncode(EncodingImpl<T>& blk) const
@ -69,9 +130,15 @@ MetaInfo::wireEncode(EncodingImpl<T>& blk) const
// ContentType?
// FreshnessPeriod?
// FinalBlockId?
// AppMetaInfo*
size_t totalLength = 0;
for (std::list<Block>::const_reverse_iterator appMetaInfoItem = m_appMetaInfo.rbegin();
appMetaInfoItem != m_appMetaInfo.rend(); ++appMetaInfoItem) {
totalLength += prependBlock(blk, *appMetaInfoItem);
}
// FinalBlockId
if (!m_finalBlockId.empty())
{
@ -127,38 +194,48 @@ MetaInfo::wireDecode(const Block& wire)
// MetaInfo ::= META-INFO-TYPE TLV-LENGTH
// ContentType?
// FreshnessPeriod?
// FinalBlockId?
// AppMetaInfo*
Block::element_const_iterator val = m_wire.elements_begin();
// ContentType
Block::element_const_iterator val = m_wire.find(tlv::ContentType);
if (val != m_wire.elements().end())
{
m_type = readNonNegativeInteger(*val);
}
else
if (val != m_wire.elements_end() && val->type() == tlv::ContentType) {
m_type = readNonNegativeInteger(*val);
++val;
}
else {
m_type = TYPE_DEFAULT;
}
// FreshnessPeriod
val = m_wire.find(tlv::FreshnessPeriod);
if (val != m_wire.elements().end())
{
m_freshnessPeriod = time::milliseconds(readNonNegativeInteger(*val));
}
else
if (val != m_wire.elements_end() && val->type() == tlv::FreshnessPeriod) {
m_freshnessPeriod = time::milliseconds(readNonNegativeInteger(*val));
++val;
}
else {
m_freshnessPeriod = time::milliseconds::min();
}
// FinalBlockId
val = m_wire.find(tlv::FinalBlockId);
if (val != m_wire.elements().end())
{
m_finalBlockId = val->blockFromValue();
if (m_finalBlockId.type() != tlv::NameComponent)
{
/// @todo May or may not throw exception later...
m_finalBlockId.reset();
}
}
else
if (val != m_wire.elements_end() && val->type() == tlv::FinalBlockId) {
m_finalBlockId = val->blockFromValue();
if (m_finalBlockId.type() != tlv::NameComponent)
{
/// @todo May or may not throw exception later...
m_finalBlockId.reset();
}
++val;
}
else {
m_finalBlockId.reset();
}
// AppMetaInfo (if any)
for (; val != m_wire.elements().end(); ++val) {
m_appMetaInfo.push_back(*val);
}
}
std::ostream&
@ -172,10 +249,18 @@ operator<<(std::ostream& os, const MetaInfo& info)
os << ", FreshnessPeriod: " << info.getFreshnessPeriod();
}
// FinalBlockId
if (!info.getFinalBlockId().empty()) {
os << ", FinalBlockId: ";
info.getFinalBlockId().toUri(os);
}
// App-defined MetaInfo items
for (std::list<Block>::const_iterator iter = info.getAppMetaInfo().begin();
iter != info.getAppMetaInfo().end(); ++iter) {
os << ", AppMetaInfoTlvType: " << iter->type();
}
return os;
}

101
src/meta-info.hpp

@ -27,15 +27,45 @@
#include "encoding/encoding-buffer.hpp"
#include "util/time.hpp"
#include "name-component.hpp"
#include <list>
namespace ndn {
/**
* An MetaInfo holds the meta info which is signed inside the data packet.
*
* The class allows experimentation with application-defined meta information blocks,
* which slightly violates NDN-TLV specification. When using the application-defined
* meta information blocks be aware that this may result in packet drop (NFD and
* previous versions of ndn-cxx will gracefully accept such packet).
*
* The following definition of MetaInfo block is assumed in this implementation (compared
* to the NDN-TLV spec, definition extended to allow optional AppMetaInfo TLV blocks):
*
* MetaInfo ::= META-INFO-TYPE TLV-LENGTH
* ContentType?
* FreshnessPeriod?
* FinalBlockId?
* AppMetaInfo*
*
* AppMetaInfo ::= any TLV block with type in the restricted application range [128, 252]
*
* Note that AppMetaInfo blocks are application-defined and must have TLV type from
* the restricted application range [128, 252].
*/
class MetaInfo
{
public:
class Error : public tlv::Error
{
public:
explicit
Error(const std::string& what)
: tlv::Error(what)
{
}
};
enum {
TYPE_DEFAULT = 0,
TYPE_LINK = 1,
@ -81,6 +111,76 @@ public:
MetaInfo&
setFinalBlockId(const name::Component& finalBlockId);
/**
* @brief Get all app-defined MetaInfo items
*
* @note Warning: Experimental API, which may change or disappear in the future
*
* @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
* is called before *AppMetaInfo, all app-defined blocks will be lost
*/
const std::list<Block>&
getAppMetaInfo() const;
/**
* @brief Set app-defined MetaInfo items
*
* This method will replace all existing app-defined MetaInfo items, if they existed.
*
* @throw Error if some block in @p info has type not in the application range
* (http://named-data.net/doc/ndn-tlv/types.html)
*
* @note Warning: Experimental API, which may change or disappear in the future
*
* @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
* is called before *AppMetaInfo, all app-defined blocks will be lost
*/
MetaInfo&
setAppMetaInfo(const std::list<Block>& info);
/**
* @brief Add an app-defined MetaInfo item
*
* @throw Error if @p block has type not in the application range
* (http://named-data.net/doc/ndn-tlv/types.html)
*
* @note Warning: Experimental API, which may change or disappear in the future
*
* @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
* is called before *AppMetaInfo, all app-defined blocks will be lost
*/
MetaInfo&
addAppMetaInfo(const Block& block);
/**
* @brief Remove a first app-defined MetaInfo item with type @p tlvType
*
* @return true if an item was deleted
*
* @note Warning: Experimental API, which may change or disappear in the future
*
* @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
* is called before *AppMetaInfo, all app-defined blocks will be lost
*/
bool
removeAppMetaInfo(uint32_t tlvType);
/**
* @brief Find a first app-defined MetaInfo item of type @p tlvType
*
* @return NULL if an item is not found, otherwise const pointer to the item
*
* @throw Error if @p tlvType is not in the application range
* (http://named-data.net/doc/ndn-tlv/types.html)
*
* @note Warning: Experimental API, which may change or disappear in the future
*
* @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
* is called before *AppMetaInfo, all app-defined blocks will be lost
*/
const Block*
findAppMetaInfo(uint32_t tlvType) const;
public: // EqualityComparable concept
bool
operator==(const MetaInfo& other) const;
@ -92,6 +192,7 @@ private:
uint32_t m_type;
time::milliseconds m_freshnessPeriod;
name::Component m_finalBlockId;
std::list<Block> m_appMetaInfo;
mutable Block m_wire;
};

78
tests/unit-tests/test-data.cpp

@ -32,7 +32,6 @@ namespace ndn {
BOOST_AUTO_TEST_SUITE(TestData)
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Data>));
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<MetaInfo>));
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Signature>));
const uint8_t Content1[] = {0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x21};
@ -124,14 +123,6 @@ const unsigned char DEFAULT_PRIVATE_KEY_DER[] = {
0x0a, 0xb6
};
const uint8_t MetaInfo1[] = {0x14, 0x04, 0x19, 0x02, 0x27, 0x10};
const uint8_t MetaInfo2[] = {0x14, 0x14, 0x19, 0x02, 0x27, 0x10, 0x1a, 0x0e, 0x08, 0x0c,
0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x77, 0x6f, 0x72, 0x6c,
0x64, 0x21};
const uint8_t MetaInfo3[] = {0x14, 0x17, 0x18, 0x01, 0x01, 0x19, 0x02, 0x27, 0x10, 0x1a,
0x0e, 0x08, 0x0c, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x77,
0x6f, 0x72, 0x6c, 0x64, 0x21};
BOOST_AUTO_TEST_CASE(DataEqualityChecks)
{
using namespace time;
@ -179,36 +170,6 @@ BOOST_AUTO_TEST_CASE(DataEqualityChecks)
BOOST_CHECK_EQUAL(a != b, false);
}
BOOST_AUTO_TEST_CASE(MetaInfoEqualityChecks)
{
using namespace time;
MetaInfo a;
MetaInfo b;
BOOST_CHECK_EQUAL(a == b, true);
BOOST_CHECK_EQUAL(a != b, false);
a.setFreshnessPeriod(seconds(10));
BOOST_CHECK_EQUAL(a == b, false);
BOOST_CHECK_EQUAL(a != b, true);
b.setFreshnessPeriod(milliseconds(90000));
BOOST_CHECK_EQUAL(a == b, false);
BOOST_CHECK_EQUAL(a != b, true);
b.setFreshnessPeriod(milliseconds(10000));
BOOST_CHECK_EQUAL(a == b, true);
BOOST_CHECK_EQUAL(a != b, false);
a.setType(10);
BOOST_CHECK_EQUAL(a == b, false);
BOOST_CHECK_EQUAL(a != b, true);
b.setType(10);
BOOST_CHECK_EQUAL(a == b, true);
BOOST_CHECK_EQUAL(a != b, false);
}
BOOST_AUTO_TEST_CASE(SignatureEqualityChecks)
{
Signature a;
@ -423,45 +384,6 @@ BOOST_FIXTURE_TEST_CASE(FullName, DataIdentityFixture)
"%28%BA%D4%B5%27%5B%D3%92%DB%B6p%C7%5C%F0%B6o%13%F7%94+%21%E8%0FU%C0%E8k7GS%A5H");
}
BOOST_AUTO_TEST_CASE(EncodeMetaInfo)
{
MetaInfo meta;
meta.setType(MetaInfo::TYPE_DEFAULT);
meta.setFreshnessPeriod(time::seconds(10));
BOOST_REQUIRE_NO_THROW(meta.wireEncode());
BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo1, MetaInfo1+sizeof(MetaInfo1),
meta.wireEncode().begin(), meta.wireEncode().end());
meta.setFinalBlockId(name::Component("hello,world!"));
BOOST_REQUIRE_NO_THROW(meta.wireEncode());
BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo2, MetaInfo2+sizeof(MetaInfo2),
meta.wireEncode().begin(), meta.wireEncode().end());
meta.setType(MetaInfo::TYPE_LINK);
BOOST_REQUIRE_NO_THROW(meta.wireEncode());
BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo3, MetaInfo3+sizeof(MetaInfo3),
meta.wireEncode().begin(), meta.wireEncode().end());
}
BOOST_AUTO_TEST_CASE(DecodeMetaInfo)
{
MetaInfo meta(Block(MetaInfo1, sizeof(MetaInfo1)));
BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(MetaInfo::TYPE_DEFAULT));
BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), time::seconds(10));
BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component());
meta.wireDecode(Block(MetaInfo2, sizeof(MetaInfo2)));
BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(MetaInfo::TYPE_DEFAULT));
BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), time::seconds(10));
BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component("hello,world!"));
meta.wireDecode(Block(MetaInfo3, sizeof(MetaInfo3)));
BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(MetaInfo::TYPE_LINK));
BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), time::seconds(10));
BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component("hello,world!"));
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn

200
tests/unit-tests/test-meta-info.cpp

@ -0,0 +1,200 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2013-2014 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received copies of the GNU General Public License and GNU Lesser
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
* <http://www.gnu.org/licenses/>.
*
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
#include "meta-info.hpp"
#include "data.hpp"
#include "security/key-chain.hpp"
#include "security/cryptopp.hpp"
#include "encoding/buffer-stream.hpp"
#include "boost-test.hpp"
namespace ndn {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestMetaInfo)
const uint8_t MetaInfo1[] = {0x14, 0x04, 0x19, 0x02, 0x27, 0x10};
const uint8_t MetaInfo2[] = {0x14, 0x14, 0x19, 0x02, 0x27, 0x10, 0x1a, 0x0e, 0x08, 0x0c,
0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x77, 0x6f, 0x72, 0x6c,
0x64, 0x21};
const uint8_t MetaInfo3[] = {0x14, 0x17, 0x18, 0x01, 0x01, 0x19, 0x02, 0x27, 0x10, 0x1a,
0x0e, 0x08, 0x0c, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x77,
0x6f, 0x72, 0x6c, 0x64, 0x21};
BOOST_AUTO_TEST_CASE(Encode)
{
MetaInfo meta;
meta.setType(MetaInfo::TYPE_DEFAULT);
meta.setFreshnessPeriod(time::seconds(10));
BOOST_REQUIRE_NO_THROW(meta.wireEncode());
BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo1, MetaInfo1+sizeof(MetaInfo1),
meta.wireEncode().begin(), meta.wireEncode().end());
meta.setFinalBlockId(name::Component("hello,world!"));
BOOST_REQUIRE_NO_THROW(meta.wireEncode());
BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo2, MetaInfo2+sizeof(MetaInfo2),
meta.wireEncode().begin(), meta.wireEncode().end());
meta.setType(MetaInfo::TYPE_LINK);
BOOST_REQUIRE_NO_THROW(meta.wireEncode());
BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo3, MetaInfo3+sizeof(MetaInfo3),
meta.wireEncode().begin(), meta.wireEncode().end());
}
BOOST_AUTO_TEST_CASE(Decode)
{
MetaInfo meta(Block(MetaInfo1, sizeof(MetaInfo1)));
BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(MetaInfo::TYPE_DEFAULT));
BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), time::seconds(10));
BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component());
meta.wireDecode(Block(MetaInfo2, sizeof(MetaInfo2)));
BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(MetaInfo::TYPE_DEFAULT));
BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), time::seconds(10));
BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component("hello,world!"));
meta.wireDecode(Block(MetaInfo3, sizeof(MetaInfo3)));
BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(MetaInfo::TYPE_LINK));
BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), time::seconds(10));
BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component("hello,world!"));
}
BOOST_AUTO_TEST_CASE(EqualityChecks)
{
using namespace time;
MetaInfo a;
MetaInfo b;
BOOST_CHECK_EQUAL(a == b, true);
BOOST_CHECK_EQUAL(a != b, false);
a.setFreshnessPeriod(seconds(10));
BOOST_CHECK_EQUAL(a == b, false);
BOOST_CHECK_EQUAL(a != b, true);
b.setFreshnessPeriod(milliseconds(90000));
BOOST_CHECK_EQUAL(a == b, false);
BOOST_CHECK_EQUAL(a != b, true);
b.setFreshnessPeriod(milliseconds(10000));
BOOST_CHECK_EQUAL(a == b, true);
BOOST_CHECK_EQUAL(a != b, false);
a.setType(10);
BOOST_CHECK_EQUAL(a == b, false);
BOOST_CHECK_EQUAL(a != b, true);
b.setType(10);
BOOST_CHECK_EQUAL(a == b, true);
BOOST_CHECK_EQUAL(a != b, false);
}
BOOST_AUTO_TEST_CASE(AppMetaInfo)
{
MetaInfo info1;
info1.setType(196);
info1.setFreshnessPeriod(time::milliseconds(3600));
info1.setFinalBlockId(name::Component("/att/final"));
uint32_t ints[5] = {128, 129, 130, 131, 132};
std::string ss[5] = {"h", "hello", "hello, world", "hello, world, alex",
"hello, world, alex, I am Xiaoke Jiang"};
for (int i = 0; i < 5; i++) {
uint32_t type = 128 + i * 10;
info1.addAppMetaInfo(nonNegativeIntegerBlock(type, ints[i]));
const std::string& s = ss[i];
type += 5;
info1.addAppMetaInfo(dataBlock(type, s.c_str(), s.size()));
}
BOOST_CHECK(info1.findAppMetaInfo(252) == 0);
info1.addAppMetaInfo(nonNegativeIntegerBlock(252, 1000));
BOOST_CHECK(info1.findAppMetaInfo(252) != 0);
info1.addAppMetaInfo(nonNegativeIntegerBlock(252, 1000));
BOOST_CHECK(info1.findAppMetaInfo(252) != 0);
info1.removeAppMetaInfo(252);
BOOST_CHECK(info1.findAppMetaInfo(252) != 0);
info1.removeAppMetaInfo(252);
BOOST_CHECK(info1.findAppMetaInfo(252) == 0);
// // These octets are obtained by the snippet below.
// // This check is intended to detect unexpected encoding change in the future.
// const Block& wire = info1.wireEncode();
// for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
// printf("0x%02x, ", *it);
// }
const uint8_t METAINFO[] = {0x14, 0x77, 0x18, 0x01, 0xc4, 0x19, 0x02, 0x0e, 0x10, 0x1a, 0x0c,
0x08, 0x0a, 0x2f, 0x61, 0x74, 0x74, 0x2f, 0x66, 0x69, 0x6e, 0x61,
0x6c, 0x80, 0x01, 0x80, 0x85, 0x01, 0x68, 0x8a, 0x01, 0x81, 0x8f,
0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x94, 0x01, 0x82, 0x99, 0x0c,
0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c,
0x64, 0x9e, 0x01, 0x83, 0xa3, 0x12, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2c, 0x20, 0x61, 0x6c,
0x65, 0x78, 0xa8, 0x01, 0x84, 0xad, 0x25, 0x68, 0x65, 0x6c, 0x6c,
0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2c, 0x20, 0x61,
0x6c, 0x65, 0x78, 0x2c, 0x20, 0x49, 0x20, 0x61, 0x6d, 0x20, 0x58,
0x69, 0x61, 0x6f, 0x6b, 0x65, 0x20, 0x4a, 0x69, 0x61, 0x6e, 0x67};
BOOST_REQUIRE_EQUAL_COLLECTIONS(info1.wireEncode().begin(), info1.wireEncode().end(),
METAINFO, METAINFO + sizeof(METAINFO));
MetaInfo info2;
info2.wireDecode(Block(METAINFO, sizeof(METAINFO)));
for (int i = 0; i < 5; i++) {
uint32_t tlvType = 128 + i * 10;
const Block* block = info2.findAppMetaInfo(tlvType);
BOOST_REQUIRE(block != 0);
BOOST_CHECK_EQUAL(readNonNegativeInteger(*block), ints[i]);
tlvType += 5;
block = info2.findAppMetaInfo(tlvType);
BOOST_REQUIRE(block != 0);
std::string s3 = std::string(reinterpret_cast<const char*>(block->value()),
block->value_size());
BOOST_CHECK_EQUAL(s3, ss[i]);
}
}
BOOST_AUTO_TEST_CASE(AppMetaInfoTypeRange)
{
MetaInfo info;
BOOST_CHECK_NO_THROW(info.addAppMetaInfo(nonNegativeIntegerBlock(128, 1000)));
BOOST_CHECK_NO_THROW(info.addAppMetaInfo(nonNegativeIntegerBlock(252, 1000)));
BOOST_CHECK_THROW(info.addAppMetaInfo(nonNegativeIntegerBlock(127, 1000)), MetaInfo::Error);
BOOST_CHECK_THROW(info.addAppMetaInfo(nonNegativeIntegerBlock(253, 1000)), MetaInfo::Error);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
} // namespace ndn
Loading…
Cancel
Save