name: add append() overload that takes a span
Refs: #5186
Change-Id: I5fa8ac6c5da82424ac0566d0a21f72b75082af2f
diff --git a/tests/unit/mgmt/nfd/status-dataset.t.cpp b/tests/unit/mgmt/nfd/status-dataset.t.cpp
index 2c8c7f7..b9cc84d 100644
--- a/tests/unit/mgmt/nfd/status-dataset.t.cpp
+++ b/tests/unit/mgmt/nfd/status-dataset.t.cpp
@@ -301,7 +301,7 @@
this->advanceClocks(500_ms);
Name prefix("/localhost/nfd/faces/query");
- prefix.append(filter.wireEncode().begin(), filter.wireEncode().end());
+ prefix.append(filter.wireEncode());
FaceStatus payload;
payload.setFaceId(8795);
this->sendDataset(prefix, payload);
@@ -330,7 +330,7 @@
this->advanceClocks(500_ms);
Name prefix("/localhost/nfd/faces/query");
- prefix.append(filter.wireEncode().begin(), filter.wireEncode().end());
+ prefix.append(filter.wireEncode());
FaceStatus payload;
payload.setFaceId(14022);
this->sendDataset(prefix, payload);
diff --git a/tests/unit/name-component.t.cpp b/tests/unit/name-component.t.cpp
index 2743514..bd0a553 100644
--- a/tests/unit/name-component.t.cpp
+++ b/tests/unit/name-component.t.cpp
@@ -271,78 +271,63 @@
BOOST_AUTO_TEST_SUITE_END() // Decode
-BOOST_AUTO_TEST_CASE(Compare)
+BOOST_AUTO_TEST_CASE(ConstructFromSpan)
{
- const std::vector<Component> comps = {
- Component("0120 0000000000000000000000000000000000000000000000000000000000000000"_block),
- Component("0120 0000000000000000000000000000000000000000000000000000000000000001"_block),
- Component("0120 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
- Component("0220 0000000000000000000000000000000000000000000000000000000000000000"_block),
- Component("0220 0000000000000000000000000000000000000000000000000000000000000001"_block),
- Component("0220 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
- Component(0x03),
- Component("0301 44"_block),
- Component("0301 46"_block),
- Component("0302 4141"_block),
- Component(),
- Component("D"),
- Component("F"),
- Component("AA"),
- Component(0x53B2),
- Component("FD53B201 44"_block),
- Component("FD53B201 46"_block),
- Component("FD53B202 4141"_block),
- };
+ const uint8_t arr[] = {1, 2, 3};
+ Component c1(arr);
+ BOOST_TEST(c1.wireEncode() == "0803010203"_block);
+ Component c2(128, arr);
+ BOOST_TEST(c2.wireEncode() == "8003010203"_block);
- for (size_t i = 0; i < comps.size(); ++i) {
- for (size_t j = 0; j < comps.size(); ++j) {
- Component lhs = comps[i];
- Component rhs = comps[j];
- BOOST_CHECK_EQUAL(lhs == rhs, i == j);
- BOOST_CHECK_EQUAL(lhs != rhs, i != j);
- BOOST_CHECK_EQUAL(lhs < rhs, i < j);
- BOOST_CHECK_EQUAL(lhs <= rhs, i <= j);
- BOOST_CHECK_EQUAL(lhs > rhs, i > j);
- BOOST_CHECK_EQUAL(lhs >= rhs, i >= j);
- }
- }
+ const std::vector<uint8_t> vec = {4, 5, 6};
+ Component c3(vec);
+ BOOST_TEST(c3.wireEncode() == "0803040506"_block);
+ Component c4(128, vec);
+ BOOST_TEST(c4.wireEncode() == "8003040506"_block);
+
+ Component c5(128, {7, 8});
+ BOOST_TEST(c5.wireEncode() == "80020708"_block);
+
+ const Block b("090109"_block);
+ Component c6(128, b);
+ BOOST_TEST(c6.wireEncode() == "8003090109"_block);
}
-BOOST_AUTO_TEST_SUITE(CreateFromIterators) // Bug 2490
+BOOST_AUTO_TEST_SUITE(ConstructFromIterators) // Bug 2490
using ContainerTypes = boost::mpl::vector<std::vector<uint8_t>,
std::list<uint8_t>,
std::vector<int8_t>,
std::list<int8_t>>;
-BOOST_AUTO_TEST_CASE_TEMPLATE(ZeroOctet, T, ContainerTypes)
+BOOST_AUTO_TEST_CASE_TEMPLATE(ZeroOctets, T, ContainerTypes)
{
T bytes;
Component c(bytes.begin(), bytes.end());
- BOOST_CHECK_EQUAL(c.type(), tlv::GenericNameComponent);
- BOOST_CHECK_EQUAL(c.value_size(), 0);
- BOOST_CHECK_EQUAL(c.size(), 2);
+ BOOST_TEST(c.type() == tlv::GenericNameComponent);
+ BOOST_TEST(c.value_size() == 0);
+ BOOST_TEST(c.size() == 2);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(OneOctet, T, ContainerTypes)
{
T bytes{1};
- Component c(0x09, bytes.begin(), bytes.end());
- BOOST_CHECK_EQUAL(c.type(), 0x09);
- BOOST_CHECK_EQUAL(c.value_size(), 1);
- BOOST_CHECK_EQUAL(c.size(), 3);
+ Component c(9, bytes.begin(), bytes.end());
+ BOOST_TEST(c.type() == 0x09);
+ BOOST_TEST(c.value_size() == 1);
+ BOOST_TEST(c.size() == 3);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(FourOctets, T, ContainerTypes)
{
T bytes{1, 2, 3, 4};
Component c(0xFCEC, bytes.begin(), bytes.end());
- BOOST_CHECK_EQUAL(c.type(), 0xFCEC);
- BOOST_CHECK_EQUAL(c.value_size(), 4);
- BOOST_CHECK_EQUAL(c.size(), 8);
+ BOOST_TEST(c.type() == 0xFCEC);
+ BOOST_TEST(c.value_size() == 4);
+ BOOST_TEST(c.size() == 8);
}
-BOOST_AUTO_TEST_SUITE_END() // CreateFromIterators
+BOOST_AUTO_TEST_SUITE_END() // ConstructFromIterators
BOOST_AUTO_TEST_SUITE(NamingConvention)
@@ -585,6 +570,43 @@
BOOST_AUTO_TEST_SUITE_END() // NamingConvention
+BOOST_AUTO_TEST_CASE(Compare)
+{
+ const std::vector<Component> comps = {
+ Component("0120 0000000000000000000000000000000000000000000000000000000000000000"_block),
+ Component("0120 0000000000000000000000000000000000000000000000000000000000000001"_block),
+ Component("0120 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
+ Component("0220 0000000000000000000000000000000000000000000000000000000000000000"_block),
+ Component("0220 0000000000000000000000000000000000000000000000000000000000000001"_block),
+ Component("0220 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"_block),
+ Component(0x03),
+ Component("0301 44"_block),
+ Component("0301 46"_block),
+ Component("0302 4141"_block),
+ Component(),
+ Component("D"),
+ Component("F"),
+ Component("AA"),
+ Component(0x53B2),
+ Component("FD53B201 44"_block),
+ Component("FD53B201 46"_block),
+ Component("FD53B202 4141"_block),
+ };
+
+ for (size_t i = 0; i < comps.size(); ++i) {
+ for (size_t j = 0; j < comps.size(); ++j) {
+ const auto& lhs = comps[i];
+ const auto& rhs = comps[j];
+ BOOST_CHECK_EQUAL(lhs == rhs, i == j);
+ BOOST_CHECK_EQUAL(lhs != rhs, i != j);
+ BOOST_CHECK_EQUAL(lhs < rhs, i < j);
+ BOOST_CHECK_EQUAL(lhs <= rhs, i <= j);
+ BOOST_CHECK_EQUAL(lhs > rhs, i > j);
+ BOOST_CHECK_EQUAL(lhs >= rhs, i >= j);
+ }
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END() // TestNameComponent
} // namespace tests
diff --git a/tests/unit/name.t.cpp b/tests/unit/name.t.cpp
index 45149cb..bfddb4f 100644
--- a/tests/unit/name.t.cpp
+++ b/tests/unit/name.t.cpp
@@ -239,17 +239,18 @@
name.append(25042, {'P', '3'});
BOOST_CHECK_EQUAL(name.wireEncode(), "070C 0804456D6964 FD61D2025033"_block);
- name.append(Component(make_span<uint8_t>({'.'})));
+ const uint8_t arr[] = {'.'};
+ name.append(arr);
BOOST_CHECK_EQUAL(name.wireEncode(), "070F 0804456D6964 FD61D2025033 08012E"_block);
- const std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B};
- name.append(16, v1.begin(), v1.end());
+ const std::vector<uint8_t> vec{0x28, 0xF0, 0xA3, 0x6B};
+ name.append(16, vec.begin(), vec.end());
BOOST_CHECK_EQUAL(name.wireEncode(), "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block);
name.clear();
BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block);
- name.append(v1.begin(), v1.end());
+ name.append(vec.begin(), vec.end());
BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080428F0A36B"_block);
name.append("xKh");