tests: Fix test cases for ImplictSha256DigestComponent
Change-Id: Ibce7419ba8b2607039844e26a64eb554b4568c5c
Refs: #2172
diff --git a/tests/dataset-fixtures.hpp b/tests/dataset-fixtures.hpp
index a957ee0..9321c9f 100644
--- a/tests/dataset-fixtures.hpp
+++ b/tests/dataset-fixtures.hpp
@@ -126,9 +126,9 @@
this->data.push_back(createData("/a/b/c"));
this->data.push_back(createData("/a/b/c/d"));
- this->interests.push_back(std::make_pair(Interest("/a"), getData("/a/b/c/d")));
- this->interests.push_back(std::make_pair(Interest("/a/b"), getData("/a/b/c/d")));
- this->interests.push_back(std::make_pair(Interest("/a/b/c"), getData("/a/b/c/d")));
+ this->interests.push_back(std::make_pair(Interest("/a"), getData("/a")));
+ this->interests.push_back(std::make_pair(Interest("/a/b"), getData("/a/b")));
+ this->interests.push_back(std::make_pair(Interest("/a/b/c"), getData("/a/b/c")));
this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), getData("/a/b/c/d")));
}
};
@@ -300,13 +300,13 @@
// Basic selects
this->interests.push_back(std::make_pair(Interest("/a/b/c"), this->getData("/a/b/c")));
- this->interests.push_back(std::make_pair(Interest("/a/b/d"), this->getData("/a/b/d/1")));
+ this->interests.push_back(std::make_pair(Interest("/a/b/d"), this->getData("/a/b/d")));
this->interests.push_back(std::make_pair(Interest("/a/b/d/1"), this->getData("/a/b/d/1")));
this->interests.push_back(std::make_pair(Interest("/a/b/d/2"), this->getData("/a/b/d/2")));
this->interests.push_back(std::make_pair(Interest("/a/b/d/3"), this->getData("/a/b/d/3")));
this->interests.push_back(std::make_pair(Interest("/a/b/d/4/I"), this->getData("/a/b/d/4/I")));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/4"), this->getData("/a/b/d/4/I")));
- this->interests.push_back(std::make_pair(Interest("/a/b/e"), this->getData("/a/b/e/1")));
+ this->interests.push_back(std::make_pair(Interest("/a/b/d/4"), this->getData("/a/b/d/4")));
+ this->interests.push_back(std::make_pair(Interest("/a/b/e"), this->getData("/a/b/e")));
this->interests.push_back(std::make_pair(Interest("/a/b/e/1"), this->getData("/a/b/e/1")));
// Complex selects
@@ -320,7 +320,7 @@
.setSelectors(Selectors()
.setMinSuffixComponents(-1)
.setChildSelector(0)),
- this->getData("/a/b/d/1")));
+ this->getData("/a/b/d")));
this->interests.push_back(std::make_pair(Interest("/a/b/d")
.setSelectors(Selectors()
@@ -349,13 +349,13 @@
.setSelectors(Selectors()
.setMinSuffixComponents(2)
.setChildSelector(1)),
- this->getData("/a/b/d/4/I")));
+ this->getData("/a/b/d/4")));
// because of the digest component, /a/b/d will be to the right of /a/b/d/4
this->interests.push_back(std::make_pair(Interest("/a/b/d")
.setSelectors(Selectors()
.setChildSelector(1)),
- this->getData("/a/b/d")));
+ this->getData("/a/b/d/4")));
// Alex: this interest doesn't make sense, as all Data packets will have the same selector
this->interests.push_back(std::make_pair(Interest("/a/b/e")
@@ -363,7 +363,7 @@
.setPublisherPublicKeyLocator(
this->data.back()
->getSignature().getKeyLocator())),
- this->getData("/a/b/e/1")));
+ this->getData("/a/b/e")));
// Removals
this->removals.push_back(std::make_pair(Interest("/a/b/d/2"), 1));
diff --git a/tests/unit/index.cpp b/tests/unit/index.cpp
index 936158c..f2cf919 100644
--- a/tests/unit/index.cpp
+++ b/tests/unit/index.cpp
@@ -38,7 +38,7 @@
{
}
- void
+ Name
insert(int id, const Name& name)
{
shared_ptr<Data> data = make_shared<Data>(name);
@@ -46,6 +46,8 @@
m_keyChain.signWithSha256(*data);
data->wireEncode();
m_index.insert(*data, id);
+
+ return data->getFullName();
}
Interest&
@@ -84,6 +86,30 @@
BOOST_CHECK_EQUAL(find(), 1);
}
+BOOST_AUTO_TEST_CASE(ExactName)
+{
+ insert(1, "ndn:/");
+ insert(2, "ndn:/A");
+ insert(3, "ndn:/A/B");
+ insert(4, "ndn:/A/C");
+ insert(5, "ndn:/D");
+
+ startInterest("ndn:/A");
+ BOOST_CHECK_EQUAL(find(), 2);
+}
+
+BOOST_AUTO_TEST_CASE(FullName)
+{
+ Name n1 = insert(1, "ndn:/A");
+ Name n2 = insert(2, "ndn:/A");
+
+ startInterest(n1);
+ BOOST_CHECK_EQUAL(find(), 1);
+
+ startInterest(n2);
+ BOOST_CHECK_EQUAL(find(), 2);
+}
+
BOOST_AUTO_TEST_CASE(Leftmost)
{
insert(1, "ndn:/A");
@@ -111,123 +137,96 @@
BOOST_CHECK_EQUAL(find(), 4);
}
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(Leftmost_ExactName1, 1)
-BOOST_AUTO_TEST_CASE(Leftmost_ExactName1)
-{
- insert(1, "ndn:/");
- insert(2, "ndn:/A/B");
- insert(3, "ndn:/A/C");
- insert(4, "ndn:/A");
- insert(5, "ndn:/D");
-
- // Intuitively you would think Data 4 should be between Data 1 and 2,
- // but Data 4 has full Name ndn:/A/<32-octet hash>.
- startInterest("ndn:/A");
- BOOST_CHECK_EQUAL(find(), 2);
-}
-
-BOOST_AUTO_TEST_CASE(Leftmost_ExactName33)
+BOOST_AUTO_TEST_CASE(MinSuffixComponents)
{
insert(1, "ndn:/");
insert(2, "ndn:/A");
- insert(3, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 33 'B's
- insert(4, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's
- insert(5, "ndn:/D");
-
- // Data 2 is returned, because <32-octet hash> is less than Data 3.
- startInterest("ndn:/A");
- BOOST_CHECK_EQUAL(find(), 2);
-}
-
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MinSuffixComponents, 2)
-BOOST_AUTO_TEST_CASE(MinSuffixComponents)
-{
- insert(1, "ndn:/A/1/2/3/4");
- insert(2, "ndn:/B/1/2/3");
- insert(3, "ndn:/C/1/2");
- insert(4, "ndn:/D/1");
- insert(5, "ndn:/E");
- insert(6, "ndn:/");
+ insert(3, "ndn:/B/1");
+ insert(4, "ndn:/C/1/2");
+ insert(5, "ndn:/D/1/2/3");
+ insert(6, "ndn:/E/1/2/3/4");
startInterest("ndn:/")
- .setChildSelector(1)
.setMinSuffixComponents(0);
- BOOST_CHECK_EQUAL(find(), 6);
-
- startInterest("ndn:/")
- .setChildSelector(1)
- .setMinSuffixComponents(1);
- BOOST_CHECK_EQUAL(find(), 6);
-
- startInterest("ndn:/")
- .setChildSelector(1)
- .setMinSuffixComponents(2);
- BOOST_CHECK_EQUAL(find(), 5);
-
- startInterest("ndn:/")
- .setChildSelector(1)
- .setMinSuffixComponents(3);
- BOOST_CHECK_EQUAL(find(), 4);
-
- startInterest("ndn:/")
- .setChildSelector(1)
- .setMinSuffixComponents(4);
- BOOST_CHECK_EQUAL(find(), 3);
-
- startInterest("ndn:/")
- .setChildSelector(1)
- .setMinSuffixComponents(5);
- BOOST_CHECK_EQUAL(find(), 2);
-
- startInterest("ndn:/")
- .setChildSelector(1)
- .setMinSuffixComponents(6);
BOOST_CHECK_EQUAL(find(), 1);
startInterest("ndn:/")
- .setChildSelector(1)
+ .setMinSuffixComponents(1);
+ BOOST_CHECK_EQUAL(find(), 1);
+
+ startInterest("ndn:/")
+ .setMinSuffixComponents(2);
+ BOOST_CHECK_EQUAL(find(), 2);
+
+ startInterest("ndn:/")
+ .setMinSuffixComponents(3);
+ BOOST_CHECK_EQUAL(find(), 3);
+
+ startInterest("ndn:/")
+ .setMinSuffixComponents(4);
+ BOOST_CHECK_EQUAL(find(), 4);
+
+ startInterest("ndn:/")
+ .setMinSuffixComponents(5);
+ BOOST_CHECK_EQUAL(find(), 5);
+
+ startInterest("ndn:/")
+ .setMinSuffixComponents(6);
+ BOOST_CHECK_EQUAL(find(), 6);
+
+ startInterest("ndn:/")
.setMinSuffixComponents(7);
BOOST_CHECK_EQUAL(find(), 0);
}
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MaxSuffixComponents, 5)
BOOST_AUTO_TEST_CASE(MaxSuffixComponents)
{
insert(1, "ndn:/");
insert(2, "ndn:/A");
- insert(3, "ndn:/A/B");
- insert(4, "ndn:/A/B/C");
- insert(5, "ndn:/A/B/C/D");
- insert(6, "ndn:/A/B/C/D/E");
- // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component.
+ insert(3, "ndn:/B/2");
+ insert(4, "ndn:/C/2/3");
+ insert(5, "ndn:/D/2/3/4");
+ insert(6, "ndn:/E/2/3/4/5");
startInterest("ndn:/")
+ .setChildSelector(1)
.setMaxSuffixComponents(0);
BOOST_CHECK_EQUAL(find(), 0);
startInterest("ndn:/")
+ .setChildSelector(1)
.setMaxSuffixComponents(1);
BOOST_CHECK_EQUAL(find(), 1);
startInterest("ndn:/")
+ .setChildSelector(1)
.setMaxSuffixComponents(2);
BOOST_CHECK_EQUAL(find(), 2);
startInterest("ndn:/")
+ .setChildSelector(1)
.setMaxSuffixComponents(3);
BOOST_CHECK_EQUAL(find(), 3);
startInterest("ndn:/")
+ .setChildSelector(1)
.setMaxSuffixComponents(4);
BOOST_CHECK_EQUAL(find(), 4);
startInterest("ndn:/")
+ .setChildSelector(1)
.setMaxSuffixComponents(5);
BOOST_CHECK_EQUAL(find(), 5);
startInterest("ndn:/")
+ .setChildSelector(1)
.setMaxSuffixComponents(6);
BOOST_CHECK_EQUAL(find(), 6);
+
+ startInterest("ndn:/")
+ .setChildSelector(1)
+ .setMaxSuffixComponents(7);
+ BOOST_CHECK_EQUAL(find(), 6);
}
BOOST_AUTO_TEST_CASE(DigestOrder)
@@ -247,126 +246,59 @@
BOOST_CHECK_NE(leftmost, rightmost);
}
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(DigestExclude, 1)
BOOST_AUTO_TEST_CASE(DigestExclude)
{
- insert(1, "ndn:/A/B");
- insert(2, "ndn:/A");
- insert(3, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's
+ insert(1, "ndn:/A");
+ Name n2 = insert(2, "ndn:/A");
+ insert(3, "ndn:/A/B");
+
+ uint8_t digest00[ndn::crypto::SHA256_DIGEST_SIZE];
+ std::fill_n(digest00, sizeof(digest00), 0x00);
+ uint8_t digestFF[ndn::crypto::SHA256_DIGEST_SIZE];
+ std::fill_n(digestFF, sizeof(digestFF), 0xFF);
+
+ Exclude excludeDigest;
+ excludeDigest.excludeRange(
+ name::Component::fromImplicitSha256Digest(digest00, sizeof(digest00)),
+ name::Component::fromImplicitSha256Digest(digestFF, sizeof(digestFF)));
startInterest("ndn:/A")
- .setExclude(Exclude().excludeBefore(Name::Component(reinterpret_cast<const uint8_t*>(
- "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
- "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"), 31))); // 31 0xFF's
- BOOST_CHECK_EQUAL(find(), 2);
+ .setChildSelector(0)
+ .setExclude(excludeDigest);
+ BOOST_CHECK_EQUAL(find(), 3);
startInterest("ndn:/A")
.setChildSelector(1)
- .setExclude(Exclude().excludeAfter(Name::Component(reinterpret_cast<const uint8_t*>(
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00"), 33))); // 33 0x00's
- BOOST_CHECK_EQUAL(find(), 2);
-}
-
-BOOST_AUTO_TEST_CASE(ExactName32)
-{
- insert(1, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 32 'B's
- insert(2, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 32 'C's
-
- startInterest("ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
- BOOST_CHECK_EQUAL(find(), 1);
-}
-
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MinSuffixComponents32, 2)
-BOOST_AUTO_TEST_CASE(MinSuffixComponents32)
-{
- insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/1/2/3/4"); // 32 'x's
- insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/B/1/2/3");
- insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/C/1/2");
- insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/D/1");
- insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/E");
- insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setChildSelector(1)
- .setMinSuffixComponents(0);
- BOOST_CHECK_EQUAL(find(), 6);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setChildSelector(1)
- .setMinSuffixComponents(1);
- BOOST_CHECK_EQUAL(find(), 6);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setChildSelector(1)
- .setMinSuffixComponents(2);
- BOOST_CHECK_EQUAL(find(), 5);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setChildSelector(1)
- .setMinSuffixComponents(3);
- BOOST_CHECK_EQUAL(find(), 4);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setChildSelector(1)
- .setMinSuffixComponents(4);
+ .setExclude(excludeDigest);
BOOST_CHECK_EQUAL(find(), 3);
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setChildSelector(1)
- .setMinSuffixComponents(5);
- BOOST_CHECK_EQUAL(find(), 2);
+ Exclude excludeGeneric;
+ excludeGeneric.excludeAfter(name::Component(static_cast<uint8_t*>(nullptr), 0));
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
+ startInterest("ndn:/A")
+ .setChildSelector(0)
+ .setExclude(excludeGeneric);
+ int found1 = find();
+ BOOST_CHECK(found1 == 1 || found1 == 2);
+
+ startInterest("ndn:/A")
.setChildSelector(1)
- .setMinSuffixComponents(6);
+ .setExclude(excludeGeneric);
+ int found2 = find();
+ BOOST_CHECK(found2 == 1 || found2 == 2);
+
+ Exclude exclude2 = excludeGeneric;
+ exclude2.excludeOne(n2.get(-1));
+
+ startInterest("ndn:/A")
+ .setChildSelector(0)
+ .setExclude(exclude2);
BOOST_CHECK_EQUAL(find(), 1);
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
+ startInterest("ndn:/A")
.setChildSelector(1)
- .setMinSuffixComponents(7);
- BOOST_CHECK_EQUAL(find(), 0);
-}
-
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MaxSuffixComponents32, 5)
-BOOST_AUTO_TEST_CASE(MaxSuffixComponents32)
-{
- insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/"); // 32 'x's
- insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A");
- insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B");
- insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C");
- insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D");
- insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D/E");
- // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component.
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setMaxSuffixComponents(0);
- BOOST_CHECK_EQUAL(find(), 0);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setMaxSuffixComponents(1);
+ .setExclude(exclude2);
BOOST_CHECK_EQUAL(find(), 1);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setMaxSuffixComponents(2);
- BOOST_CHECK_EQUAL(find(), 2);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setMaxSuffixComponents(3);
- BOOST_CHECK_EQUAL(find(), 3);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setMaxSuffixComponents(4);
- BOOST_CHECK_EQUAL(find(), 4);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setMaxSuffixComponents(5);
- BOOST_CHECK_EQUAL(find(), 5);
-
- startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
- .setMaxSuffixComponents(6);
- BOOST_CHECK_EQUAL(find(), 6);
}
BOOST_AUTO_TEST_SUITE_END() // Find
@@ -386,15 +318,12 @@
repo::Index index;
};
-// // Combine CommonDatasets with ComplexSelectorDataset
-// typedef boost::mpl::push_back<CommonDatasets,
-// ComplexSelectorsDataset>::type Datasets;
+// Combine CommonDatasets with ComplexSelectorDataset
+typedef boost::mpl::push_back<CommonDatasets,
+ ComplexSelectorsDataset>::type Datasets;
-// BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>)
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(Bulk, 7)
-BOOST_FIXTURE_TEST_CASE(Bulk, Fixture<ComplexSelectorsDataset>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>)
{
- typedef ComplexSelectorsDataset T;
BOOST_TEST_MESSAGE(T::getName());
for (typename T::DataContainer::iterator i = this->data.begin();
diff --git a/tests/unit/repo-storage.cpp b/tests/unit/repo-storage.cpp
index 9554aea..9157115 100644
--- a/tests/unit/repo-storage.cpp
+++ b/tests/unit/repo-storage.cpp
@@ -36,15 +36,13 @@
{
};
-// // Combine CommonDatasets with ComplexSelectorDataset
-// typedef boost::mpl::push_back<CommonDatasets,
-// ComplexSelectorsDataset>::type Datasets;
+// Combine CommonDatasets with ComplexSelectorDataset
+typedef boost::mpl::push_back<CommonDatasets,
+ ComplexSelectorsDataset>::type Datasets;
-// BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>)
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(Bulk, 7)
-BOOST_FIXTURE_TEST_CASE(Bulk, Fixture<ComplexSelectorsDataset>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>)
{
- typedef ComplexSelectorsDataset T;
+ // typedef ComplexSelectorsDataset T;
BOOST_TEST_MESSAGE(T::getName());
// Insert data into repo
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index 7cf2074..6d911f7 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -153,11 +153,8 @@
};
-// BOOST_FIXTURE_TEST_CASE_TEMPLATE(BulkInsertAndRead, T, CommonDatasets, TcpBulkInsertFixture<T>)
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(BulkInsertAndRead, 3)
-BOOST_FIXTURE_TEST_CASE(BulkInsertAndRead, TcpBulkInsertFixture<BasicDataset>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(BulkInsertAndRead, T, CommonDatasets, TcpBulkInsertFixture<T>)
{
- typedef BasicDataset T;
BOOST_TEST_MESSAGE(T::getName());
// start bulk inserter