name: Introducing new name::Component::is* methods
These methods allow checking if the name component follows the specific
naming convention without relying on exception handling.
Change-Id: I9799c860ad203f777d7ad6671c9a13506388c1c7
Refs: #2088
diff --git a/tests/unit-tests/test-name.cpp b/tests/unit-tests/test-name.cpp
index b95f69e..649bd6f 100644
--- a/tests/unit-tests/test-name.cpp
+++ b/tests/unit-tests/test-name.cpp
@@ -137,7 +137,8 @@
function<uint64_t(const name::Component&)>,
function<Name&(Name&, uint64_t)>,
Name/*expected*/,
- uint64_t/*value*/> > Dataset;
+ uint64_t/*value*/,
+ function<bool(const name::Component&)> > > Dataset;
Numeric()
{
@@ -146,27 +147,32 @@
bind(&name::Component::toNumberWithMarker, _1, 0xAA),
bind(&Name::appendNumberWithMarker, _1, 0xAA, _2),
Name("/%AA%03%E8"),
- 1000));
+ 1000,
+ bind(&name::Component::isNumberWithMarker, _1, 0xAA)));
dataset.push_back(boost::make_tuple(&name::Component::fromSegment,
bind(&name::Component::toSegment, _1),
bind(&Name::appendSegment, _1, _2),
Name("/%00%27%10"),
- 10000));
+ 10000,
+ bind(&name::Component::isSegment, _1)));
dataset.push_back(boost::make_tuple(&name::Component::fromSegmentOffset,
bind(&name::Component::toSegmentOffset, _1),
bind(&Name::appendSegmentOffset, _1, _2),
Name("/%FB%00%01%86%A0"),
- 100000));
+ 100000,
+ bind(&name::Component::isSegmentOffset, _1)));
dataset.push_back(boost::make_tuple(&name::Component::fromVersion,
bind(&name::Component::toVersion, _1),
bind(&Name::appendVersion, _1, _2),
Name("/%FD%00%0FB%40"),
- 1000000));
+ 1000000,
+ bind(&name::Component::isVersion, _1)));
dataset.push_back(boost::make_tuple(&name::Component::fromSequenceNumber,
bind(&name::Component::toSequenceNumber, _1),
bind(&Name::appendSequenceNumber, _1, _2),
Name("/%FE%00%98%96%80"),
- 10000000));
+ 10000000,
+ bind(&name::Component::isSequenceNumber, _1)));
}
Dataset dataset;
@@ -179,14 +185,16 @@
function<time::system_clock::TimePoint(const name::Component&)>,
function<Name&(Name&, const time::system_clock::TimePoint&)>,
Name/*expected*/,
- time::system_clock::TimePoint/*value*/> > Dataset;
+ time::system_clock::TimePoint/*value*/,
+ function<bool(const name::Component&)> > > Dataset;
Timestamp()
{
dataset.push_back(boost::make_tuple(&name::Component::fromTimestamp,
bind(&name::Component::toTimestamp, _1),
bind(&Name::appendTimestamp, _1, _2),
Name("/%FC%00%04%7BE%E3%1B%00%00"),
- (time::getUnixEpoch() + time::days(14600/*40 years*/))));
+ (time::getUnixEpoch() + time::days(14600/*40 years*/)),
+ bind(&name::Component::isTimestamp, _1)));
}
Dataset dataset;
@@ -205,9 +213,13 @@
// std::cout << name << std::endl;
// }
+ name::Component invalidComponent1;
+ name::Component invalidComponent2("1234567890");
+
for (typename T::Dataset::const_iterator it = this->dataset.begin();
it != this->dataset.end(); ++it) {
const Name& expected = it->template get<3>();
+ BOOST_TEST_MESSAGE("Check " << expected[0].toUri());
name::Component actualComponent = it->template get<0>()(it->template get<4>());
BOOST_CHECK_EQUAL(actualComponent, expected[0]);
@@ -216,8 +228,15 @@
it->template get<2>()(actualName, it->template get<4>());
BOOST_CHECK_EQUAL(actualName, expected);
+ BOOST_CHECK_EQUAL(it->template get<5>()(expected[0]), true);
BOOST_REQUIRE_NO_THROW(it->template get<1>()(expected[0]));
BOOST_CHECK_EQUAL(it->template get<1>()(expected[0]), it->template get<4>());
+
+ BOOST_CHECK_EQUAL(it->template get<5>()(invalidComponent1), false);
+ BOOST_CHECK_EQUAL(it->template get<5>()(invalidComponent2), false);
+
+ BOOST_REQUIRE_THROW(it->template get<1>()(invalidComponent1), name::Component::Error);
+ BOOST_REQUIRE_THROW(it->template get<1>()(invalidComponent2), name::Component::Error);
}
}