name-component: add test case for ZeroLengthComponent
refs #1933
Change-Id: I59791713c5523e10fd6aad45c5b3d3c1b32ab231
diff --git a/tests/unit-tests/test-name.cpp b/tests/unit-tests/test-name.cpp
index 54ceb54..e2f45ab 100644
--- a/tests/unit-tests/test-name.cpp
+++ b/tests/unit-tests/test-name.cpp
@@ -145,6 +145,29 @@
TestName, TestName+sizeof(TestName));
}
+BOOST_AUTO_TEST_CASE(ZeroLengthComponent)
+{
+ static const uint8_t compOctets[] {0x08, 0x00};
+ Block compBlock(compOctets, sizeof(compOctets));
+ name::Component comp;
+ BOOST_REQUIRE_NO_THROW(comp.wireDecode(compBlock));
+ BOOST_CHECK_EQUAL(comp.value_size(), 0);
+
+ static const uint8_t nameOctets[] {0x07, 0x08, 0x08, 0x01, 0x41, 0x08, 0x00, 0x08, 0x01, 0x42};
+ Block nameBlock(nameOctets, sizeof(nameOctets));
+ static const std::string nameUri("/A/.../B");
+ Name name;
+ BOOST_REQUIRE_NO_THROW(name.wireDecode(nameBlock));
+ BOOST_CHECK_EQUAL(name.toUri(), nameUri);
+ Block nameEncoded = name.wireEncode();
+ BOOST_CHECK(nameEncoded == nameBlock);
+
+ Name name2;
+ BOOST_REQUIRE_NO_THROW(name2.set(nameUri));
+ Block name2Encoded = name2.wireEncode();
+ BOOST_CHECK(name2Encoded == nameBlock);
+}
+
BOOST_AUTO_TEST_CASE(AppendNumber)
{
Name name;
@@ -422,6 +445,20 @@
BOOST_CHECK_EQUAL( 1, Name("/Z/A/C/Y").compare(1, 2, Name("/X/A"), 1));
}
+BOOST_AUTO_TEST_CASE(ZeroLengthComponentCompare)
+{
+ name::Component comp0("");
+ BOOST_REQUIRE_EQUAL(comp0.value_size(), 0);
+
+ BOOST_CHECK_EQUAL(comp0, comp0);
+ BOOST_CHECK_EQUAL(comp0, name::Component(""));
+ BOOST_CHECK_LT(comp0, name::Component("A"));
+ BOOST_CHECK_LE(comp0, name::Component("A"));
+ BOOST_CHECK_NE(comp0, name::Component("A"));
+ BOOST_CHECK_GT(name::Component("A"), comp0);
+ BOOST_CHECK_GE(name::Component("A"), comp0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn