encoding: make Block convertible to span
Change-Id: Idb501467d1c56b95e7fdb76acda63b919fe98f85
diff --git a/tests/unit/data.t.cpp b/tests/unit/data.t.cpp
index 0a4c9b7..6ee1708 100644
--- a/tests/unit/data.t.cpp
+++ b/tests/unit/data.t.cpp
@@ -196,10 +196,10 @@
tr::StepSource input;
input >> tr::signerFilter(DigestAlgorithm::SHA256, m_privKey) >> tr::streamSink(sig);
- input.write({d.getName(). wireEncode().wire(), d.getName(). wireEncode().size()});
- input.write({d.getMetaInfo().wireEncode().wire(), d.getMetaInfo().wireEncode().size()});
- input.write({d.getContent(). wire(), d.getContent(). size()});
- input.write({signatureInfo. wireEncode().wire(), signatureInfo. wireEncode().size()});
+ input.write(d.getName().wireEncode());
+ input.write(d.getMetaInfo().wireEncode());
+ input.write(d.getContent());
+ input.write(signatureInfo.wireEncode());
input.end();
}
d.setSignatureValue(sig.buf());
@@ -288,8 +288,7 @@
BOOST_CHECK_EQUAL(d.getFreshnessPeriod(), 10_s);
BOOST_CHECK_EQUAL(d.getFinalBlock().has_value(), false);
BOOST_CHECK_EQUAL(d.hasContent(), true);
- BOOST_CHECK_EQUAL(std::string(reinterpret_cast<const char*>(d.getContent().value()),
- d.getContent().value_size()), "SUCCESS!");
+ BOOST_CHECK_EQUAL(readString(d.getContent()), "SUCCESS!");
BOOST_CHECK_EQUAL(d.getSignatureType(), tlv::SignatureSha256WithRsa);
BOOST_REQUIRE(d.getKeyLocator().has_value());
BOOST_CHECK_EQUAL(d.getKeyLocator()->getName(), "/test/key/locator");
diff --git a/tests/unit/encoding/block.t.cpp b/tests/unit/encoding/block.t.cpp
index e7c8bac..2c75944 100644
--- a/tests/unit/encoding/block.t.cpp
+++ b/tests/unit/encoding/block.t.cpp
@@ -53,12 +53,13 @@
BOOST_CHECK_EQUAL(b.type(), tlv::Invalid);
BOOST_CHECK_EQUAL(b.hasValue(), false);
BOOST_CHECK_EQUAL(b.value_size(), 0);
+ BOOST_CHECK_EQUAL(b.value_bytes().empty(), true);
BOOST_CHECK(b.value() == nullptr);
- BOOST_CHECK_THROW(b.size(), Block::Error);
BOOST_CHECK_THROW(b.begin(), Block::Error);
BOOST_CHECK_THROW(b.end(), Block::Error);
- BOOST_CHECK_THROW(b.wire(), Block::Error);
+ BOOST_CHECK_THROW(b.data(), Block::Error);
+ BOOST_CHECK_THROW(b.size(), Block::Error);
BOOST_CHECK_THROW(b.blockFromValue(), Block::Error);
}
@@ -91,7 +92,7 @@
Block block(buf);
Block derivedBlock(block, block.begin(), block.end());
- BOOST_CHECK_EQUAL(derivedBlock.wire(), block.wire()); // pointers should match
+ BOOST_CHECK_EQUAL(derivedBlock.data(), block.data()); // pointers should match
BOOST_CHECK_EQUAL(derivedBlock, block); // blocks should match
derivedBlock = Block(block, block.begin() + 2, block.begin() + 5);
@@ -150,6 +151,7 @@
BOOST_CHECK_EQUAL(b1.size(), 2); // 1-octet TLV-TYPE and 1-octet TLV-LENGTH
BOOST_CHECK_EQUAL(b1.hasValue(), false);
BOOST_CHECK_EQUAL(b1.value_size(), 0);
+ BOOST_CHECK_EQUAL(b1.value_bytes().empty(), true);
BOOST_CHECK(b1.value() == nullptr);
Block b2(258);
@@ -158,6 +160,7 @@
BOOST_CHECK_EQUAL(b2.size(), 4); // 3-octet TLV-TYPE and 1-octet TLV-LENGTH
BOOST_CHECK_EQUAL(b2.hasValue(), false);
BOOST_CHECK_EQUAL(b2.value_size(), 0);
+ BOOST_CHECK_EQUAL(b2.value_bytes().empty(), true);
BOOST_CHECK(b2.value() == nullptr);
Block b3(tlv::Invalid);
@@ -168,6 +171,7 @@
});
BOOST_CHECK_EQUAL(b3.hasValue(), false);
BOOST_CHECK_EQUAL(b3.value_size(), 0);
+ BOOST_CHECK_EQUAL(b3.value_bytes().empty(), true);
BOOST_CHECK(b3.value() == nullptr);
}
@@ -182,6 +186,8 @@
BOOST_CHECK_EQUAL(b1.size(), 6);
BOOST_CHECK_EQUAL(b1.hasValue(), true);
BOOST_CHECK_EQUAL(b1.value_size(), sizeof(VALUE));
+ BOOST_CHECK_EQUAL(b1.value_bytes().size(), sizeof(VALUE));
+ BOOST_CHECK_EQUAL(b1.value_bytes().front(), 0x11);
BOOST_CHECK(b1.value() != nullptr);
// empty buffer as TLV-VALUE
@@ -191,6 +197,7 @@
BOOST_CHECK_EQUAL(b2.size(), 2);
BOOST_CHECK_EQUAL(b2.hasValue(), true);
BOOST_CHECK_EQUAL(b2.value_size(), 0);
+ BOOST_CHECK_EQUAL(b2.value_bytes().empty(), true);
BOOST_CHECK(b2.value() == nullptr);
}
@@ -205,6 +212,8 @@
BOOST_CHECK_EQUAL(b.size(), 10);
BOOST_CHECK_EQUAL(b.hasValue(), true);
BOOST_CHECK_EQUAL(b.value_size(), sizeof(buf));
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), sizeof(buf));
+ BOOST_CHECK_EQUAL(b.value_bytes().front(), 0x80);
BOOST_CHECK(b.value() != nullptr);
}
@@ -218,21 +227,26 @@
BOOST_CHECK_EQUAL(b.type(), 66);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
- BOOST_CHECK_EQUAL(*b.wire(), 0x42);
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), 1);
+ BOOST_CHECK_EQUAL(*b.data(), 0x42);
BOOST_CHECK_EQUAL(*b.value(), 0xfa);
+ BOOST_CHECK_EQUAL(b.value_bytes().front(), 0xfa);
b = Block::fromStream(stream);
BOOST_CHECK_EQUAL(b.type(), 1);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
- BOOST_CHECK_EQUAL(*b.wire(), 0x01);
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), 1);
+ BOOST_CHECK_EQUAL(*b.data(), 0x01);
BOOST_CHECK_EQUAL(*b.value(), 0xfb);
+ BOOST_CHECK_EQUAL(b.value_bytes().front(), 0xfb);
b = Block::fromStream(stream);
BOOST_CHECK_EQUAL(b.type(), 0xffffffff);
BOOST_CHECK_EQUAL(b.size(), 6);
BOOST_CHECK_EQUAL(b.value_size(), 0);
- BOOST_CHECK_EQUAL(*b.wire(), 0xfe);
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), 0);
+ BOOST_CHECK_EQUAL(*b.data(), 0xfe);
BOOST_CHECK(b.value() == nullptr);
BOOST_CHECK(stream.eof());
@@ -282,18 +296,20 @@
Block b1 = Block::fromStream(stream);
BOOST_CHECK_EQUAL(b1.type(), 0x70);
BOOST_CHECK_EQUAL(b1.value_size(), 0);
+ BOOST_CHECK_EQUAL(b1.value_bytes().size(), 0);
BOOST_CHECK(b1.value() == nullptr);
Block b2 = Block::fromStream(stream);
BOOST_CHECK_EQUAL(b2.type(), 0x71);
BOOST_CHECK_EQUAL(b2.value_size(), 3);
+ BOOST_CHECK_EQUAL(b2.value_bytes().size(), 3);
const uint8_t EXPECTED_VALUE2[] = {0x86, 0x11, 0x24};
- BOOST_CHECK_EQUAL_COLLECTIONS(b2.value_begin(), b2.value_end(),
- EXPECTED_VALUE2, EXPECTED_VALUE2 + sizeof(EXPECTED_VALUE2));
+ BOOST_TEST(b2.value_bytes() == EXPECTED_VALUE2, boost::test_tools::per_element());
Block b3 = Block::fromStream(stream);
BOOST_CHECK_EQUAL(b3.type(), 0x72);
BOOST_CHECK_EQUAL(b3.value_size(), 0);
+ BOOST_CHECK_EQUAL(b3.value_bytes().size(), 0);
BOOST_CHECK(b3.value() == nullptr);
BOOST_CHECK_EXCEPTION(Block::fromStream(stream), tlv::Error, [] (const auto& e) {
@@ -328,8 +344,10 @@
BOOST_CHECK_EQUAL(b.type(), 66);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
- BOOST_CHECK_EQUAL(*b.wire(), 0x42);
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), 1);
+ BOOST_CHECK_EQUAL(*b.data(), 0x42);
BOOST_CHECK_EQUAL(*b.value(), 0xfa);
+ BOOST_CHECK_EQUAL(b.value_bytes().front(), 0xfa);
size_t offset = b.size();
std::tie(isOk, b) = Block::fromBuffer(buffer, offset);
@@ -337,8 +355,10 @@
BOOST_CHECK_EQUAL(b.type(), 1);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
- BOOST_CHECK_EQUAL(*b.wire(), 0x01);
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), 1);
+ BOOST_CHECK_EQUAL(*b.data(), 0x01);
BOOST_CHECK_EQUAL(*b.value(), 0xfb);
+ BOOST_CHECK_EQUAL(b.value_bytes().front(), 0xfb);
offset += b.size();
std::tie(isOk, b) = Block::fromBuffer(buffer, offset);
@@ -346,7 +366,8 @@
BOOST_CHECK_EQUAL(b.type(), 0xffffffff);
BOOST_CHECK_EQUAL(b.size(), 6);
BOOST_CHECK_EQUAL(b.value_size(), 0);
- BOOST_CHECK_EQUAL(*b.wire(), 0xfe);
+ BOOST_CHECK_EQUAL(b.value_bytes().empty(), true);
+ BOOST_CHECK_EQUAL(*b.data(), 0xfe);
BOOST_CHECK(b.value() == nullptr);
}
@@ -359,8 +380,10 @@
BOOST_CHECK_EQUAL(b.type(), 66);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
- BOOST_CHECK_EQUAL(*b.wire(), 0x42);
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), 1);
+ BOOST_CHECK_EQUAL(*b.data(), 0x42);
BOOST_CHECK_EQUAL(*b.value(), 0xfa);
+ BOOST_CHECK_EQUAL(b.value_bytes().front(), 0xfa);
auto offset = b.size();
std::tie(isOk, b) = Block::fromBuffer(make_span(TEST_BUFFER).subspan(offset));
@@ -368,8 +391,10 @@
BOOST_CHECK_EQUAL(b.type(), 1);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
- BOOST_CHECK_EQUAL(*b.wire(), 0x01);
+ BOOST_CHECK_EQUAL(b.value_bytes().size(), 1);
+ BOOST_CHECK_EQUAL(*b.data(), 0x01);
BOOST_CHECK_EQUAL(*b.value(), 0xfb);
+ BOOST_CHECK_EQUAL(b.value_bytes().front(), 0xfb);
offset += b.size();
std::tie(isOk, b) = Block::fromBuffer(make_span(TEST_BUFFER).subspan(offset));
@@ -377,7 +402,8 @@
BOOST_CHECK_EQUAL(b.type(), 0xffffffff);
BOOST_CHECK_EQUAL(b.size(), 6);
BOOST_CHECK_EQUAL(b.value_size(), 0);
- BOOST_CHECK_EQUAL(*b.wire(), 0xfe);
+ BOOST_CHECK_EQUAL(b.value_bytes().empty(), true);
+ BOOST_CHECK_EQUAL(*b.data(), 0xfe);
BOOST_CHECK(b.value() == nullptr);
}
@@ -622,7 +648,7 @@
{
Block block = "0101A0"_block;
boost::asio::const_buffer buffer(block);
- BOOST_CHECK_EQUAL(boost::asio::buffer_cast<const uint8_t*>(buffer), block.wire());
+ BOOST_CHECK_EQUAL(boost::asio::buffer_cast<const uint8_t*>(buffer), block.data());
BOOST_CHECK_EQUAL(boost::asio::buffer_size(buffer), block.size());
}
diff --git a/tests/unit/ims/in-memory-storage.t.cpp b/tests/unit/ims/in-memory-storage.t.cpp
index 3d9ff1e..f6c2a40 100644
--- a/tests/unit/ims/in-memory-storage.t.cpp
+++ b/tests/unit/ims/in-memory-storage.t.cpp
@@ -270,12 +270,11 @@
{
shared_ptr<Data> data = makeData("/digest/compute");
- auto digest1 = util::Sha256::computeDigest({data->wireEncode().wire(), data->wireEncode().size()});
+ auto digest1 = util::Sha256::computeDigest(data->wireEncode());
BOOST_CHECK_EQUAL(digest1->size(), 32);
InMemoryStorageEntry entry;
entry.setData(*data);
-
BOOST_CHECK_EQUAL_COLLECTIONS(digest1->begin(), digest1->end(),
entry.getFullName()[-1].value_begin(),
entry.getFullName()[-1].value_end());
@@ -368,7 +367,7 @@
shared_ptr<Data> data7 = makeData("/c/c/1");
ims.insert(*data7);
- auto digest1 = util::Sha256::computeDigest({data->wireEncode().wire(), data->wireEncode().size()});
+ auto digest1 = util::Sha256::computeDigest(data->wireEncode());
Name name("/a");
ims.erase(name);
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index 495d036..95193ac 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -265,7 +265,7 @@
i2.setNonce(0x4c1ecb4a);
i2.setApplicationParameters("2404C0C1C2C3"_block);
i2.setSignatureInfo(si);
- i2.setSignatureValue(make_shared<Buffer>(sv.value(), sv.value_size()));
+ i2.setSignatureValue(make_shared<Buffer>(sv.value_begin(), sv.value_end()));
BOOST_CHECK_EQUAL(i2.isParametersDigestValid(), true);
BOOST_TEST(i2.wireEncode() == WIRE, boost::test_tools::per_element());
@@ -906,7 +906,7 @@
// Throws because attempting to set InterestSignatureValue without set InterestSignatureInfo
Block sv1("2E04 01020304"_block);
- auto svBuffer1 = make_shared<Buffer>(sv1.value(), sv1.value_size());
+ auto svBuffer1 = make_shared<Buffer>(sv1.value_begin(), sv1.value_end());
BOOST_CHECK_THROW(i.setSignatureValue(svBuffer1), tlv::Error);
// Simple set/get case for InterestSignatureInfo (no prior set)
@@ -958,7 +958,7 @@
i.wireEncode();
BOOST_CHECK_EQUAL(i.hasWire(), true);
Block sv2("2E04 99887766"_block);
- auto svBuffer2 = make_shared<Buffer>(sv2.value(), sv2.value_size());
+ auto svBuffer2 = make_shared<Buffer>(sv2.value_begin(), sv2.value_end());
i.setSignatureValue(svBuffer2);
BOOST_CHECK_EQUAL(i.hasWire(), false);
BOOST_CHECK(i.getSignatureInfo() == si2);
@@ -1027,7 +1027,8 @@
BOOST_CHECK(i.getSignatureInfo() == si);
Block sv("2E04 01020304"_block);
- i.setSignatureValue(make_shared<Buffer>(sv.value(), sv.value_size())); // updates ParametersDigestSha256Component
+ i.setSignatureValue(make_shared<Buffer>(sv.value_begin(),
+ sv.value_end())); // updates ParametersDigestSha256Component
BOOST_CHECK_EQUAL(i.getName(),
"/A/B/C/params-sha256=f649845ef944638390d1c689e2f0618ea02e471eff236110cbeb822d5932d342");
BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
diff --git a/tests/unit/lp/packet.t.cpp b/tests/unit/lp/packet.t.cpp
index 7763f06..588dedf 100644
--- a/tests/unit/lp/packet.t.cpp
+++ b/tests/unit/lp/packet.t.cpp
@@ -95,7 +95,7 @@
buf[1] = 0xe8;
Packet packet;
- packet.add<FragmentField>(std::make_pair(buf.begin(), buf.end()));
+ packet.add<FragmentField>({buf.begin(), buf.end()});
packet.add<SequenceField>(1000);
Block wire = packet.wireEncode();
BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
@@ -164,7 +164,7 @@
frag[1] = 0xe8;
Packet packet;
- packet.add<FragmentField>(std::make_pair(frag.begin(), frag.end()));
+ packet.add<FragmentField>({frag.begin(), frag.end()});
packet.add<FragIndexField>(0);
packet.add<AckField>(2);
packet.wireEncode();
diff --git a/tests/unit/meta-info.t.cpp b/tests/unit/meta-info.t.cpp
index 56ad239..af8416a 100644
--- a/tests/unit/meta-info.t.cpp
+++ b/tests/unit/meta-info.t.cpp
@@ -139,9 +139,7 @@
block = info2.findAppMetaInfo(tlvType);
BOOST_REQUIRE(block != nullptr);
-
- std::string s3(reinterpret_cast<const char*>(block->value()), block->value_size());
- BOOST_CHECK_EQUAL(s3, ss[i]);
+ BOOST_CHECK_EQUAL(readString(*block), ss[i]);
}
}
diff --git a/tests/unit/mgmt/dispatcher.t.cpp b/tests/unit/mgmt/dispatcher.t.cpp
index 30b5853..a4897a9 100644
--- a/tests/unit/mgmt/dispatcher.t.cpp
+++ b/tests/unit/mgmt/dispatcher.t.cpp
@@ -398,10 +398,8 @@
content = [&dataInStorage] () -> Block {
EncodingBuffer encoder;
- size_t valueLength = encoder.prependBytes({dataInStorage[1].getContent().value(),
- dataInStorage[1].getContent().value_size()});
- valueLength += encoder.prependBytes({dataInStorage[0].getContent().value(),
- dataInStorage[0].getContent().value_size()});
+ size_t valueLength = encoder.prependBytes(dataInStorage[1].getContent().value_bytes());
+ valueLength += encoder.prependBytes(dataInStorage[0].getContent().value_bytes());
encoder.prependVarNumber(valueLength);
encoder.prependVarNumber(tlv::Content);
return encoder.block();
diff --git a/tests/unit/mgmt/status-dataset-context.t.cpp b/tests/unit/mgmt/status-dataset-context.t.cpp
index 4192337..69b2694 100644
--- a/tests/unit/mgmt/status-dataset-context.t.cpp
+++ b/tests/unit/mgmt/status-dataset-context.t.cpp
@@ -42,7 +42,6 @@
protected:
StatusDatasetContextFixture()
: interest(makeInterest("/test/context/interest"))
- , contentBlock(makeStringBlock(tlv::Content, "/test/data/content"))
, context(*interest,
[this] (auto&&... args) {
sendDataHistory.push_back({std::forward<decltype(args)>(args)...});
@@ -60,23 +59,18 @@
return name.appendSegment(segmentNo);
}
- Block
+ ConstBufferPtr
concatenateDataContent() const
{
- EncodingBuffer encoder;
- size_t valueLength = 0;
+ auto buf = std::make_shared<Buffer>();
for (const auto& args : sendDataHistory) {
- const auto& content = args.content;
- valueLength += encoder.appendBytes({content.value(), content.value_size()});
+ buf->insert(buf->end(), args.content.value_begin(), args.content.value_end());
}
- encoder.prependVarNumber(valueLength);
- encoder.prependVarNumber(tlv::Content);
- return encoder.block();
+ return buf;
}
protected:
shared_ptr<Interest> interest;
- Block contentBlock;
StatusDatasetContext context;
std::vector<SendDataArgs> sendDataHistory;
std::vector<ControlResponse> sendNackHistory;
@@ -125,7 +119,7 @@
BOOST_AUTO_TEST_CASE(SetValidAfterAppend)
{
Name validPrefix = Name(interest->getName()).append("/valid");
- context.append(contentBlock);
+ context.append({0x12, 0x34});
BOOST_CHECK_EXCEPTION(context.setPrefix(validPrefix), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call setPrefix() after append/end/reject"s;
});
@@ -155,7 +149,8 @@
BOOST_AUTO_TEST_CASE(Basic)
{
- context.append(contentBlock);
+ const auto testBlock = makeStringBlock(tlv::Content, "TEST");
+ context.append(testBlock);
BOOST_CHECK(sendDataHistory.empty()); // end() not called yet
context.end();
@@ -163,19 +158,28 @@
const auto& args = sendDataHistory[0];
BOOST_CHECK_EQUAL(args.dataName, makeSegmentName(0));
- BOOST_CHECK_EQUAL(args.content.blockFromValue(), contentBlock);
+ BOOST_CHECK_EQUAL(args.content.blockFromValue(), testBlock);
BOOST_CHECK_EQUAL(args.isFinalBlock, true);
}
+BOOST_AUTO_TEST_CASE(Empty)
+{
+ context.append({});
+ BOOST_TEST(sendDataHistory.empty()); // end() not called yet
+
+ context.end();
+ BOOST_TEST_REQUIRE(sendDataHistory.size() == 1);
+
+ const auto& args = sendDataHistory[0];
+ BOOST_TEST(args.dataName == makeSegmentName(0));
+ BOOST_TEST(args.content.value_size() == 0);
+ BOOST_TEST(args.isFinalBlock);
+}
+
BOOST_AUTO_TEST_CASE(Large)
{
- const Block largeBlock = [] {
- Block b(tlv::Content, std::make_shared<const Buffer>(10000));
- b.encode();
- return b;
- }();
-
- context.append(largeBlock);
+ const std::vector<uint8_t> big(10000, 'A');
+ context.append(big);
BOOST_CHECK_EQUAL(sendDataHistory.size(), 1);
context.end();
@@ -190,30 +194,31 @@
BOOST_CHECK_EQUAL(sendDataHistory[1].isFinalBlock, true);
// check data content
- auto contentLargeBlock = concatenateDataContent();
- BOOST_CHECK_NO_THROW(contentLargeBlock.parse());
- BOOST_REQUIRE_EQUAL(contentLargeBlock.elements().size(), 1);
- BOOST_CHECK_EQUAL(contentLargeBlock.elements()[0], largeBlock);
+ BOOST_TEST(*concatenateDataContent() == big, boost::test_tools::per_element());
}
BOOST_AUTO_TEST_CASE(MultipleSmall)
{
- const size_t nBlocks = 100;
+ const size_t nBlocks = 1000;
+ const auto contentBlock = makeStringBlock(0xFFFF, "Test Data Content");
for (size_t i = 0 ; i < nBlocks ; i ++) {
context.append(contentBlock);
}
context.end();
- // check data to in-memory storage
- BOOST_REQUIRE_EQUAL(sendDataHistory.size(), 1);
- BOOST_CHECK_EQUAL(sendDataHistory[0].dataName, makeSegmentName(0));
- BOOST_CHECK_EQUAL(sendDataHistory[0].isFinalBlock, true);
+ BOOST_TEST_REQUIRE(sendDataHistory.size() == 3);
+ BOOST_TEST(sendDataHistory[0].dataName == makeSegmentName(0));
+ BOOST_TEST(!sendDataHistory[0].isFinalBlock);
+ BOOST_TEST(sendDataHistory[1].dataName == makeSegmentName(1));
+ BOOST_TEST(!sendDataHistory[1].isFinalBlock);
+ BOOST_TEST(sendDataHistory[2].dataName == makeSegmentName(2));
+ BOOST_TEST(sendDataHistory[2].isFinalBlock);
- auto contentMultiBlocks = concatenateDataContent();
+ Block contentMultiBlocks(tlv::Content, concatenateDataContent());
contentMultiBlocks.parse();
- BOOST_CHECK_EQUAL(contentMultiBlocks.elements().size(), nBlocks);
+ BOOST_TEST(contentMultiBlocks.elements().size() == nBlocks);
for (const auto& element : contentMultiBlocks.elements()) {
- BOOST_CHECK_EQUAL(element, contentBlock);
+ BOOST_TEST(element == contentBlock, boost::test_tools::per_element());
}
}
@@ -236,8 +241,7 @@
BOOST_AUTO_TEST_CASE(AppendReject)
{
- const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_NO_THROW(context.append(Block(buf)));
+ BOOST_CHECK_NO_THROW(context.append({0x82, 0x01, 0x02}));
BOOST_CHECK_EXCEPTION(context.reject(), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call reject() after append/end"s;
});
@@ -245,8 +249,7 @@
BOOST_AUTO_TEST_CASE(AppendEndReject)
{
- const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_NO_THROW(context.append(Block(buf)));
+ BOOST_CHECK_NO_THROW(context.append({0x82, 0x01, 0x02}));
BOOST_CHECK_NO_THROW(context.end());
BOOST_CHECK_EXCEPTION(context.reject(), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call reject() after append/end"s;
@@ -256,8 +259,7 @@
BOOST_AUTO_TEST_CASE(EndAppend)
{
BOOST_CHECK_NO_THROW(context.end());
- const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_EXCEPTION(context.append(Block(buf)), std::logic_error, [] (const auto& e) {
+ BOOST_CHECK_EXCEPTION(context.append({0x82, 0x01, 0x02}), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call append() on a finalized context"s;
});
}
@@ -281,8 +283,7 @@
BOOST_AUTO_TEST_CASE(RejectAppend)
{
BOOST_CHECK_NO_THROW(context.reject());
- const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_EXCEPTION(context.append(Block(buf)), std::logic_error, [] (const auto& e) {
+ BOOST_CHECK_EXCEPTION(context.append({0x82, 0x01, 0x02}), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call append() on a finalized context"s;
});
}
diff --git a/tests/unit/security/additional-description.t.cpp b/tests/unit/security/additional-description.t.cpp
index 56a9090..2779816 100644
--- a/tests/unit/security/additional-description.t.cpp
+++ b/tests/unit/security/additional-description.t.cpp
@@ -72,10 +72,7 @@
it++;
BOOST_CHECK(it == aDescription.end());
- BOOST_CHECK_EQUAL_COLLECTIONS(aDescription.wireEncode().wire(),
- aDescription.wireEncode().wire() + aDescription.wireEncode().size(),
- DESC,
- DESC + sizeof(DESC));
+ BOOST_TEST(aDescription.wireEncode() == DESC, boost::test_tools::per_element());
AdditionalDescription aDescription2(Block{DESC});
BOOST_CHECK_EQUAL(aDescription2, aDescription);
diff --git a/tests/unit/security/detail/certificate-bundle-decoder.t.cpp b/tests/unit/security/detail/certificate-bundle-decoder.t.cpp
index 630aaec..1199994 100644
--- a/tests/unit/security/detail/certificate-bundle-decoder.t.cpp
+++ b/tests/unit/security/detail/certificate-bundle-decoder.t.cpp
@@ -99,7 +99,7 @@
{
// First segment contains first 250 bytes of cert1
Data d;
- d.setContent(make_span(certBlock1.wire(), 250));
+ d.setContent(make_span(certBlock1).first(250));
// Second segment contains the rest of cert1 and the first 100 bytes of cert2
auto buf = std::make_shared<Buffer>(certBlock1.begin() + 250, certBlock1.end());
diff --git a/tests/unit/security/pib/pib-data-fixture.cpp b/tests/unit/security/pib/pib-data-fixture.cpp
index 37e1e6d..4fb5e36 100644
--- a/tests/unit/security/pib/pib-data-fixture.cpp
+++ b/tests/unit/security/pib/pib-data-fixture.cpp
@@ -63,7 +63,7 @@
// EncodingBuffer buf;
// cert.wireEncode(buf, true);
-// cert.setSignatureValue(tpm.sign(buf.buf(), buf.size(), keyName, DigestAlgorithm::SHA256));
+// cert.setSignatureValue(tpm.sign({buf}, keyName, DigestAlgorithm::SHA256));
// printBytes(prefix + "_KEY" + to_string(keyId) + "_CERT" + to_string(certVersion),
// cert.wireEncode());
@@ -72,18 +72,12 @@
// }
// static void
-// printBytes(const std::string& name, const Block& block)
-// {
-// printBytes(name, make_span(block.wire(), block.size()));
-// }
-
-// static void
-// printBytes(const std::string& name, span<const uint8_t> buf)
+// printBytes(const std::string& name, span<const uint8_t> bytes)
// {
// std::cout << "\nconst uint8_t " << name << "[] = {\n"
// << " ";
-// std::string hex = toHex(buf);
+// std::string hex = toHex(bytes);
// for (size_t i = 0; i < hex.size(); i++) {
// if (i > 0 && i % 40 == 0)
diff --git a/tests/unit/security/validation-policy-config.t.cpp b/tests/unit/security/validation-policy-config.t.cpp
index 32fbf01..83c6f52 100644
--- a/tests/unit/security/validation-policy-config.t.cpp
+++ b/tests/unit/security/validation-policy-config.t.cpp
@@ -247,7 +247,7 @@
{
using namespace ndn::security::transform;
const auto& cert = this->identity.getDefaultKey().getDefaultCertificate().wireEncode();
- bufferSource(make_span(cert.wire(), cert.size())) >> base64Encode(false) >> streamSink(os);
+ bufferSource(cert) >> base64Encode(false) >> streamSink(os);
}
this->policy.load(this->baseConfig + R"CONF(
diff --git a/tests/unit/security/validation-policy-simple-hierarchy.t.cpp b/tests/unit/security/validation-policy-simple-hierarchy.t.cpp
index d5734a8..70fb49e 100644
--- a/tests/unit/security/validation-policy-simple-hierarchy.t.cpp
+++ b/tests/unit/security/validation-policy-simple-hierarchy.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -73,15 +73,15 @@
BOOST_AUTO_TEST_CASE(NonKeyNameInsideLocator)
{
- // auto cert = identity.getDefaultKey().getDefaultCertificate().wireEncode();
- // std::cerr << "Certificate idCert{\"" << toHex(cert.wire(), cert.size()) << "\"_block};" << std::endl;
+// auto cert = identity.getDefaultKey().getDefaultCertificate().wireEncode();
+// std::cerr << "Certificate idCert{\"" << toHex(cert) << "\"_block};" << std::endl;
- // cert = subIdentity.getDefaultKey().getDefaultCertificate().wireEncode();
- // std::cerr << "Certificate subIdCert{\"" << toHex(cert.wire(), cert.size()) << "\"_block};" << std::endl;
+// cert = subIdentity.getDefaultKey().getDefaultCertificate().wireEncode();
+// std::cerr << "Certificate subIdCert{\"" << toHex(cert) << "\"_block};" << std::endl;
- // Data packet("/Security/ValidatorFixture/Sub1/Sub2/Packet");
- // m_keyChain.sign(packet, signingByIdentity(subIdentity));
- // std::cerr << "Data packet{\"" << toHex(packet.wireEncode().wire(), packet.wireEncode().size()) << "\"_block};" << std::endl;
+// Data pkt("/Security/ValidatorFixture/Sub1/Sub2/Packet");
+// m_keyChain.sign(pkt, signingByIdentity(subIdentity));
+// std::cerr << "Data packet{\"" << toHex(pkt.wireEncode()) << "\"_block};" << std::endl;
// These are hard-coded with a key locator that is the exact name of the certificate
Certificate idCert{"06FD014C073C08085365637572697479081056616C696461746F724669787475726508034B455"
diff --git a/tests/unit/security/verification-helpers.t.cpp b/tests/unit/security/verification-helpers.t.cpp
index d15f8f2..79cc41c 100644
--- a/tests/unit/security/verification-helpers.t.cpp
+++ b/tests/unit/security/verification-helpers.t.cpp
@@ -48,10 +48,10 @@
// {"Sha256", signingWithSha256()}
// };
-// auto print = [] (const std::string& name, const uint8_t* buf, size_t size) {
+// auto print = [] (const std::string& name, span<const uint8_t> buf) {
// std::cout << " const Block " + name + "{{\n ";
-// std::string hex = toHex({buf, size});
+// std::string hex = toHex(buf);
// for (size_t i = 0; i < hex.size(); i++) {
// if (i > 0 && i % 32 == 0)
@@ -74,23 +74,22 @@
// std::cout << " const std::string name = \"" << type << "\";\n";
// if (signingInfo.getSignerType() == SigningInfo::SIGNER_TYPE_ID) {
-// print("cert", signingInfo.getPibIdentity().getDefaultKey().getDefaultCertificate().wireEncode().wire(),
-// signingInfo.getPibIdentity().getDefaultKey().getDefaultCertificate().wireEncode().size());
+// print("cert", signingInfo.getPibIdentity().getDefaultKey().getDefaultCertificate().wireEncode());
// }
// else {
-// print("cert", nullptr, 0);
+// print("cert", {});
// }
// std::cout << "\n";
// // Create data that can be verified by cert
// Data data(Name("/test/data").append(type));
// m_keyChain.sign(data, signingInfo);
-// print("goodData", data.wireEncode().wire(), data.wireEncode().size());
+// print("goodData", data.wireEncode());
// std::cout << "\n";
// // Create data that cannot be verified by cert
// m_keyChain.sign(data, signingByIdentity(wrongIdentity));
-// print("badSigData", data.wireEncode().wire(), data.wireEncode().size());
+// print("badSigData", data.wireEncode());
// std::cout << "\n";
// // Create interest that can be verified by cert
@@ -99,13 +98,13 @@
// signingInfoV03.setSignedInterestFormat(SignedInterestFormat::V03);
// interest1.setNonce(0xF72C8A4B);
// m_keyChain.sign(interest1, signingInfoV03);
-// print("goodInterest", interest1.wireEncode().wire(), interest1.wireEncode().size());
+// print("goodInterest", interest1.wireEncode());
// std::cout << "\n";
// // Create interest that cannot be verified by cert
// m_keyChain.sign(interest1, signingByIdentity(wrongIdentity)
// .setSignedInterestFormat(SignedInterestFormat::V03));
-// print("badSigInterest", interest1.wireEncode().wire(), interest1.wireEncode().size());
+// print("badSigInterest", interest1.wireEncode());
// std::cout << "\n";
// // Create interest that can be verified by cert (old signed Interest format)
@@ -114,13 +113,13 @@
// signingInfoV02.setSignedInterestFormat(SignedInterestFormat::V03);
// interest2.setNonce(0xF72C8A4B);
// m_keyChain.sign(interest2, signingInfoV02);
-// print("goodInterestOldFormat", interest2.wireEncode().wire(), interest2.wireEncode().size());
+// print("goodInterestOldFormat", interest2.wireEncode());
// std::cout << "\n";
// // Create interest that cannot be verified by cert (old signed Interest format)
// m_keyChain.sign(interest2, signingByIdentity(wrongIdentity)
// .setSignedInterestFormat(SignedInterestFormat::V02));
-// print("badSigInterestOldFormat", interest2.wireEncode().wire(), interest2.wireEncode().size());
+// print("badSigInterestOldFormat", interest2.wireEncode());
// std::cout << "\n};\n\n";
// }
// }
diff --git a/tests/unit/signature-info.t.cpp b/tests/unit/signature-info.t.cpp
index 11fdff1..dff4241 100644
--- a/tests/unit/signature-info.t.cpp
+++ b/tests/unit/signature-info.t.cpp
@@ -434,8 +434,7 @@
// encode
auto encoded = info.wireEncode();
BOOST_CHECK_EQUAL(info.hasWire(), true);
- BOOST_CHECK_EQUAL_COLLECTIONS(sigInfo, sigInfo + sizeof(sigInfo),
- encoded.wire(), encoded.wire() + encoded.size());
+ BOOST_TEST(encoded == sigInfo, boost::test_tools::per_element());
info.setValidityPeriod(vp1);
BOOST_CHECK_EQUAL(info.hasWire(), true);
diff --git a/tests/unit/util/io.t.cpp b/tests/unit/util/io.t.cpp
index ebe5799..270270c 100644
--- a/tests/unit/util/io.t.cpp
+++ b/tests/unit/util/io.t.cpp
@@ -187,10 +187,7 @@
void
wireDecode(const Block& block)
{
- // block must be 0xBB, 0x01, 0xEE
- BOOST_CHECK_EQUAL(block.type(), 0xBB);
- BOOST_REQUIRE_EQUAL(block.value_size(), 1);
- BOOST_CHECK_EQUAL(block.value()[0], 0xEE);
+ BOOST_TEST(block == "BB01EE"_block);
}
};
diff --git a/tests/unit/util/sha256.t.cpp b/tests/unit/util/sha256.t.cpp
index ae4fea3..c5fd1fd 100644
--- a/tests/unit/util/sha256.t.cpp
+++ b/tests/unit/util/sha256.t.cpp
@@ -112,7 +112,22 @@
BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
}
-BOOST_AUTO_TEST_CASE(InsertionOperatorBlock)
+BOOST_AUTO_TEST_CASE(InsertionOperatorUnsignedInt)
+{
+ const uint64_t input[] = {1, 2, 3, 4};
+ auto expected = fromHex("7236c00c170036c6de133a878210ddd58567aa1d0619a0f70f69e38ae6f916e9");
+
+ Sha256 statefulSha256;
+ for (size_t i = 0; i < sizeof(input) / sizeof(uint64_t); ++i) {
+ statefulSha256 << boost::endian::native_to_big(input[i]);
+ }
+ ConstBufferPtr digest = statefulSha256.computeDigest();
+
+ BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
+ BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
+}
+
+BOOST_AUTO_TEST_CASE(InsertionOperatorSpan)
{
const uint8_t input[] = {
0x16, 0x1b, // SignatureInfo
@@ -130,22 +145,7 @@
auto expected = fromHex("b372edfd4d6a4db2cfeaeead6c34fdee9b9e759f7b8d799cf8067e39e7f2886c");
Sha256 statefulSha256;
- statefulSha256 << Block{input};
- ConstBufferPtr digest = statefulSha256.computeDigest();
-
- BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
- BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
-}
-
-BOOST_AUTO_TEST_CASE(InsertionOperatorUint64t)
-{
- const uint64_t input[] = {1, 2, 3, 4};
- auto expected = fromHex("7236c00c170036c6de133a878210ddd58567aa1d0619a0f70f69e38ae6f916e9");
-
- Sha256 statefulSha256;
- for (size_t i = 0; i < sizeof(input) / sizeof(uint64_t); ++i) {
- statefulSha256 << boost::endian::native_to_big(input[i]);
- }
+ statefulSha256 << input;
ConstBufferPtr digest = statefulSha256.computeDigest();
BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
@@ -166,14 +166,6 @@
BOOST_CHECK_NO_THROW(sha << 42);
}
-BOOST_AUTO_TEST_CASE(Error)
-{
- Sha256 sha;
- sha << 42;
- sha.computeDigest(); // finalize
- BOOST_CHECK_THROW(sha << 42, Sha256::Error);
-}
-
BOOST_AUTO_TEST_CASE(StaticComputeDigest)
{
auto expected = fromHex("9f64a747e1b97f131fabb6b447296c9b6f0201e79fb3c5356e6c77e89b6a806a");
@@ -182,6 +174,14 @@
BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
}
+BOOST_AUTO_TEST_CASE(Error)
+{
+ Sha256 sha;
+ sha << 42;
+ sha.computeDigest(); // finalize
+ BOOST_CHECK_THROW(sha << 42, Sha256::Error);
+}
+
BOOST_AUTO_TEST_CASE(Print)
{
const uint8_t origin[] = {0x94, 0xEE, 0x05, 0x93, 0x35, 0xE5, 0x87, 0xE5,
diff --git a/tests/unit/util/simple-notification.hpp b/tests/unit/util/simple-notification.hpp
index acfa172..ece2c48 100644
--- a/tests/unit/util/simple-notification.hpp
+++ b/tests/unit/util/simple-notification.hpp
@@ -59,8 +59,7 @@
void
wireDecode(const Block& block)
{
- m_message.assign(reinterpret_cast<const char*>(block.value()),
- block.value_size());
+ m_message = readString(block);
// error for testing
if (!m_message.empty() && m_message[0] == '\x07')
diff --git a/tests/unit/util/sqlite3-statement.t.cpp b/tests/unit/util/sqlite3-statement.t.cpp
index a78b077..99ea89f 100644
--- a/tests/unit/util/sqlite3-statement.t.cpp
+++ b/tests/unit/util/sqlite3-statement.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -98,7 +98,7 @@
{
Sqlite3Statement stmt(db, "INSERT INTO test VALUES (5, ?)");
- stmt.bind(1, reinterpret_cast<const void*>(block.wire()), block.size(), SQLITE_STATIC);
+ stmt.bind(1, reinterpret_cast<const void*>(block.data()), block.size(), SQLITE_STATIC);
stmt.step();
}