table: eliminate Selectors from CS tests
refs #4805
Change-Id: I6ae48fc40e62aeeb41cde7530d6bfa6b6d5ef000
diff --git a/tests/daemon/table/cs-fixture.hpp b/tests/daemon/table/cs-fixture.hpp
new file mode 100644
index 0000000..15bf89e
--- /dev/null
+++ b/tests/daemon/table/cs-fixture.hpp
@@ -0,0 +1,113 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_TESTS_DAEMON_TABLE_CS_FIXTURE_HPP
+#define NFD_TESTS_DAEMON_TABLE_CS_FIXTURE_HPP
+
+#include "table/cs.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/daemon/global-io-fixture.hpp"
+
+#include <cstring>
+
+namespace nfd {
+namespace cs {
+namespace tests {
+
+using namespace nfd::tests;
+
+#define CHECK_CS_FIND(expected) find([&] (uint32_t found) { BOOST_CHECK_EQUAL(expected, found); });
+
+class CsFixture : public GlobalIoTimeFixture
+{
+protected:
+ Name
+ insert(uint32_t id, const Name& name, const std::function<void(Data&)>& modifyData = nullptr,
+ bool isUnsolicited = false)
+ {
+ auto data = makeData(name);
+ data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
+
+ if (modifyData != nullptr) {
+ modifyData(*data);
+ }
+
+ data->wireEncode();
+ cs.insert(*data, isUnsolicited);
+
+ return data->getFullName();
+ }
+
+ Interest&
+ startInterest(const Name& name)
+ {
+ interest = make_shared<Interest>(name);
+ interest->setCanBePrefix(false);
+ return *interest;
+ }
+
+ void
+ find(const std::function<void(uint32_t)>& check)
+ {
+ bool hasResult = false;
+ cs.find(*interest,
+ [&] (const Interest& interest, const Data& data) {
+ hasResult = true;
+ const Block& content = data.getContent();
+ uint32_t found = 0;
+ std::memcpy(&found, content.value(), sizeof(found));
+ check(found);
+ },
+ bind([&] {
+ hasResult = true;
+ check(0);
+ }));
+
+ // current Cs::find implementation is synchronous
+ BOOST_CHECK(hasResult);
+ }
+
+ size_t
+ erase(const Name& prefix, size_t limit)
+ {
+ optional<size_t> nErased;
+ cs.erase(prefix, limit, [&] (size_t nErased1) { nErased = nErased1; });
+
+ // current Cs::erase implementation is synchronous
+ // if callback was not invoked, bad_optional_access would occur
+ return *nErased;
+ }
+
+protected:
+ Cs cs;
+ shared_ptr<Interest> interest;
+};
+
+} // namespace tests
+} // namespace cs
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_TABLE_CS_FIXTURE_HPP
diff --git a/tests/daemon/table/cs-policy-lru.t.cpp b/tests/daemon/table/cs-policy-lru.t.cpp
index bc28639..ed4fa7c 100644
--- a/tests/daemon/table/cs-policy-lru.t.cpp
+++ b/tests/daemon/table/cs-policy-lru.t.cpp
@@ -24,17 +24,13 @@
*/
#include "table/cs-policy-lru.hpp"
-#include "table/cs.hpp"
-#include "tests/test-common.hpp"
-#include "tests/daemon/global-io-fixture.hpp"
+#include "tests/daemon/table/cs-fixture.hpp"
namespace nfd {
namespace cs {
namespace tests {
-using namespace nfd::tests;
-
BOOST_AUTO_TEST_SUITE(Table)
BOOST_AUTO_TEST_SUITE(TestCsLru)
@@ -44,51 +40,45 @@
BOOST_CHECK_EQUAL(policyNames.count("lru"), 1);
}
-BOOST_FIXTURE_TEST_CASE(EvictOne, GlobalIoTimeFixture)
+BOOST_FIXTURE_TEST_CASE(EvictOne, CsFixture)
{
- Cs cs(3);
cs.setPolicy(make_unique<LruPolicy>());
+ cs.setLimit(3);
- cs.insert(*makeData("ndn:/A"));
- cs.insert(*makeData("ndn:/B"));
- cs.insert(*makeData("ndn:/C"));
+ insert(1, "/A");
+ insert(2, "/B");
+ insert(3, "/C");
BOOST_CHECK_EQUAL(cs.size(), 3);
// evict A
- cs.insert(*makeData("ndn:/D"));
+ insert(4, "/D");
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/A"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
+ startInterest("/A");
+ CHECK_CS_FIND(0);
// use C then B
- cs.find(Interest("ndn:/C"),
- bind([] { BOOST_CHECK(true); }),
- bind([] { BOOST_CHECK(false); }));
- cs.find(Interest("ndn:/B"),
- bind([] { BOOST_CHECK(true); }),
- bind([] { BOOST_CHECK(false); }));
+ startInterest("/C");
+ CHECK_CS_FIND(3);
+ startInterest("/B");
+ CHECK_CS_FIND(2);
// evict D then C
- cs.insert(*makeData("ndn:/E"));
+ insert(5, "/E");
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/D"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
- cs.insert(*makeData("ndn:/F"));
+ startInterest("/D");
+ CHECK_CS_FIND(0);
+ insert(6, "/F");
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/C"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
+ startInterest("/C");
+ CHECK_CS_FIND(0);
// refresh B
- cs.insert(*makeData("ndn:/B"));
+ insert(12, "/B");
// evict E
- cs.insert(*makeData("ndn:/G"));
+ insert(7, "/G");
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/E"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
+ startInterest("/E");
+ CHECK_CS_FIND(0);
}
BOOST_AUTO_TEST_SUITE_END() // TestCsLru
diff --git a/tests/daemon/table/cs-policy-priority-fifo.t.cpp b/tests/daemon/table/cs-policy-priority-fifo.t.cpp
index 37fcbc7..c059756 100644
--- a/tests/daemon/table/cs-policy-priority-fifo.t.cpp
+++ b/tests/daemon/table/cs-policy-priority-fifo.t.cpp
@@ -24,17 +24,13 @@
*/
#include "table/cs-policy-priority-fifo.hpp"
-#include "table/cs.hpp"
-#include "tests/test-common.hpp"
-#include "tests/daemon/global-io-fixture.hpp"
+#include "tests/daemon/table/cs-fixture.hpp"
namespace nfd {
namespace cs {
namespace tests {
-using namespace nfd::tests;
-
BOOST_AUTO_TEST_SUITE(Table)
BOOST_AUTO_TEST_SUITE(TestCsPriorityFifo)
@@ -44,107 +40,60 @@
BOOST_CHECK_EQUAL(policyNames.count("priority_fifo"), 1);
}
-BOOST_FIXTURE_TEST_CASE(EvictOne, GlobalIoTimeFixture)
+BOOST_FIXTURE_TEST_CASE(EvictOne, CsFixture)
{
- Cs cs(3);
cs.setPolicy(make_unique<PriorityFifoPolicy>());
+ cs.setLimit(3);
- shared_ptr<Data> dataA = makeData("ndn:/A");
- dataA->setFreshnessPeriod(99999_ms);
- dataA->wireEncode();
- cs.insert(*dataA);
+ insert(1, "/A", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
+ insert(2, "/B", [] (Data& data) { data.setFreshnessPeriod(10_ms); });
+ insert(3, "/C", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }, true);
+ advanceClocks(11_ms);
- shared_ptr<Data> dataB = makeData("ndn:/B");
- dataB->setFreshnessPeriod(10_ms);
- dataB->wireEncode();
- cs.insert(*dataB);
-
- shared_ptr<Data> dataC = makeData("ndn:/C");
- dataC->setFreshnessPeriod(99999_ms);
- dataC->wireEncode();
- cs.insert(*dataC, true);
-
- this->advanceClocks(11_ms);
-
- // evict unsolicited
- shared_ptr<Data> dataD = makeData("ndn:/D");
- dataD->setFreshnessPeriod(99999_ms);
- dataD->wireEncode();
- cs.insert(*dataD);
+ // evict /C (unsolicited)
+ insert(4, "/D", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/C"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
+ startInterest("/C");
+ CHECK_CS_FIND(0);
- // evict stale
- shared_ptr<Data> dataE = makeData("ndn:/E");
- dataE->setFreshnessPeriod(99999_ms);
- dataE->wireEncode();
- cs.insert(*dataE);
+ // evict /B (stale)
+ insert(5, "/E", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/B"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
+ startInterest("/B");
+ CHECK_CS_FIND(0);
- // evict fifo
- shared_ptr<Data> dataF = makeData("ndn:/F");
- dataF->setFreshnessPeriod(99999_ms);
- dataF->wireEncode();
- cs.insert(*dataF);
+ // evict /F (fresh)
+ insert(6, "/F", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/A"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
+ startInterest("/A");
+ CHECK_CS_FIND(0);
}
-BOOST_FIXTURE_TEST_CASE(Refresh, GlobalIoTimeFixture)
+BOOST_FIXTURE_TEST_CASE(Refresh, CsFixture)
{
- Cs cs(3);
cs.setPolicy(make_unique<PriorityFifoPolicy>());
+ cs.setLimit(3);
- shared_ptr<Data> dataA = makeData("ndn:/A");
- dataA->setFreshnessPeriod(99999_ms);
- dataA->wireEncode();
- cs.insert(*dataA);
+ insert(1, "/A", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
+ insert(2, "/B", [] (Data& data) { data.setFreshnessPeriod(10_ms); });
+ insert(3, "/C", [] (Data& data) { data.setFreshnessPeriod(10_ms); });
+ advanceClocks(11_ms);
- shared_ptr<Data> dataB = makeData("ndn:/B");
- dataB->setFreshnessPeriod(10_ms);
- dataB->wireEncode();
- cs.insert(*dataB);
-
- shared_ptr<Data> dataC = makeData("ndn:/C");
- dataC->setFreshnessPeriod(10_ms);
- dataC->wireEncode();
- cs.insert(*dataC);
-
- this->advanceClocks(11_ms);
-
- // refresh dataB
- shared_ptr<Data> dataB2 = make_shared<Data>(*dataB);
- dataB2->wireEncode();
- cs.insert(*dataB2);
+ // refresh /B
+ insert(12, "/B", [] (Data& data) { data.setFreshnessPeriod(0_ms); });
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/A"),
- bind([] { BOOST_CHECK(true); }),
- bind([] { BOOST_CHECK(false); }));
+ startInterest("/A");
+ CHECK_CS_FIND(1);
+ startInterest("/B");
+ CHECK_CS_FIND(12);
+ startInterest("/C");
+ CHECK_CS_FIND(3);
- cs.find(Interest("ndn:/B"),
- bind([] { BOOST_CHECK(true); }),
- bind([] { BOOST_CHECK(false); }));
-
- cs.find(Interest("ndn:/C"),
- bind([] { BOOST_CHECK(true); }),
- bind([] { BOOST_CHECK(false); }));
-
- // evict dataC stale
- shared_ptr<Data> dataD = makeData("ndn:/D");
- dataD->setFreshnessPeriod(99999_ms);
- dataD->wireEncode();
- cs.insert(*dataD);
+ // evict /C from stale queue
+ insert(4, "/D", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
BOOST_CHECK_EQUAL(cs.size(), 3);
- cs.find(Interest("ndn:/C"),
- bind([] { BOOST_CHECK(false); }),
- bind([] { BOOST_CHECK(true); }));
+ startInterest("/C");
+ CHECK_CS_FIND(0);
}
BOOST_AUTO_TEST_SUITE_END() // TestCsPriorityFifo
diff --git a/tests/daemon/table/cs.t.cpp b/tests/daemon/table/cs.t.cpp
index db980d2..85886da 100644
--- a/tests/daemon/table/cs.t.cpp
+++ b/tests/daemon/table/cs.t.cpp
@@ -25,106 +25,18 @@
#include "table/cs.hpp"
-#include "tests/test-common.hpp"
-#include "tests/daemon/global-io-fixture.hpp"
+#include "tests/daemon/table/cs-fixture.hpp"
-#include <cstring>
-
-#include <ndn-cxx/exclude.hpp>
#include <ndn-cxx/lp/tags.hpp>
-#include <ndn-cxx/util/sha256.hpp>
namespace nfd {
namespace cs {
namespace tests {
-using namespace nfd::tests;
-
-#define CHECK_CS_FIND(expected) find([&] (uint32_t found) { BOOST_CHECK_EQUAL(expected, found); });
-
BOOST_AUTO_TEST_SUITE(Table)
-BOOST_FIXTURE_TEST_SUITE(TestCs, GlobalIoFixture)
+BOOST_FIXTURE_TEST_SUITE(TestCs, CsFixture)
-class FindFixture : public GlobalIoTimeFixture
-{
-protected:
- Name
- insert(uint32_t id, const Name& name, const std::function<void(Data&)>& modifyData = nullptr)
- {
- shared_ptr<Data> data = makeData(name);
- data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
-
- if (modifyData != nullptr) {
- modifyData(*data);
- }
-
- data->wireEncode();
- m_cs.insert(*data);
-
- return data->getFullName();
- }
-
- Interest&
- startInterest(const Name& name)
- {
- m_interest = make_shared<Interest>(name);
- return *m_interest;
- }
-
- void
- find(const std::function<void(uint32_t)>& check)
- {
- bool hasResult = false;
- m_cs.find(*m_interest,
- [&] (const Interest& interest, const Data& data) {
- hasResult = true;
- const Block& content = data.getContent();
- uint32_t found = 0;
- std::memcpy(&found, content.value(), sizeof(found));
- check(found);
- },
- bind([&] {
- hasResult = true;
- check(0);
- }));
-
- // current Cs::find implementation is synchronous
- BOOST_CHECK(hasResult);
- }
-
- size_t
- erase(const Name& prefix, size_t limit)
- {
- optional<size_t> nErased;
- m_cs.erase(prefix, limit, [&] (size_t nErased1) { nErased = nErased1; });
-
- // current Cs::erase implementation is synchronous
- // if callback was not invoked, bad_optional_access would occur
- return *nErased;
- }
-
-protected:
- Cs m_cs;
- shared_ptr<Interest> m_interest;
-};
-
-BOOST_FIXTURE_TEST_SUITE(Find, FindFixture)
-
-BOOST_AUTO_TEST_CASE(EmptyDataName)
-{
- insert(1, "/");
-
- startInterest("/");
- CHECK_CS_FIND(1);
-}
-
-BOOST_AUTO_TEST_CASE(EmptyInterestName)
-{
- insert(1, "/A");
-
- startInterest("/");
- CHECK_CS_FIND(1);
-}
+BOOST_AUTO_TEST_SUITE(Find)
BOOST_AUTO_TEST_CASE(ExactName)
{
@@ -138,6 +50,19 @@
CHECK_CS_FIND(2);
}
+BOOST_AUTO_TEST_CASE(ExactName_CanBePrefix)
+{
+ insert(1, "/");
+ insert(2, "/A");
+ insert(3, "/A/B");
+ insert(4, "/A/C");
+ insert(5, "/D");
+
+ startInterest("/A")
+ .setCanBePrefix(true);
+ CHECK_CS_FIND(2);
+}
+
BOOST_AUTO_TEST_CASE(FullName)
{
Name n1 = insert(1, "/A");
@@ -150,20 +75,19 @@
CHECK_CS_FIND(2);
}
-BOOST_AUTO_TEST_CASE(Leftmost)
+BOOST_AUTO_TEST_CASE(FullName_EmptyDataName)
{
- insert(1, "/A");
- insert(2, "/B/p/1");
- insert(3, "/B/p/2");
- insert(4, "/B/q/1");
- insert(5, "/B/q/2");
- insert(6, "/C");
+ Name n1 = insert(1, "/");
+ Name n2 = insert(2, "/");
- startInterest("/B");
+ startInterest(n1);
+ CHECK_CS_FIND(1);
+
+ startInterest(n2);
CHECK_CS_FIND(2);
}
-BOOST_AUTO_TEST_CASE(Rightmost)
+BOOST_AUTO_TEST_CASE(PrefixName)
{
insert(1, "/A");
insert(2, "/B/p/1");
@@ -173,102 +97,18 @@
insert(6, "/C");
startInterest("/B")
- .setChildSelector(1);
- CHECK_CS_FIND(4);
+ .setCanBePrefix(true);
+ CHECK_CS_FIND(2);
}
-BOOST_AUTO_TEST_CASE(MinSuffixComponents)
+BOOST_AUTO_TEST_CASE(PrefixName_NoCanBePrefix)
{
- insert(1, "/");
- insert(2, "/A");
- insert(3, "/B/1");
- insert(4, "/C/1/2");
- insert(5, "/D/1/2/3");
- insert(6, "/E/1/2/3/4");
+ insert(1, "/B/p/1");
- startInterest("/")
- .setMinSuffixComponents(0);
- CHECK_CS_FIND(1);
-
- startInterest("/")
- .setMinSuffixComponents(1);
- CHECK_CS_FIND(1);
-
- startInterest("/")
- .setMinSuffixComponents(2);
- CHECK_CS_FIND(2);
-
- startInterest("/")
- .setMinSuffixComponents(3);
- CHECK_CS_FIND(3);
-
- startInterest("/")
- .setMinSuffixComponents(4);
- CHECK_CS_FIND(4);
-
- startInterest("/")
- .setMinSuffixComponents(5);
- CHECK_CS_FIND(5);
-
- startInterest("/")
- .setMinSuffixComponents(6);
- CHECK_CS_FIND(6);
-
- startInterest("/")
- .setMinSuffixComponents(7);
+ startInterest("/B");
CHECK_CS_FIND(0);
}
-BOOST_AUTO_TEST_CASE(MaxSuffixComponents)
-{
- insert(1, "/");
- insert(2, "/A");
- insert(3, "/B/2");
- insert(4, "/C/2/3");
- insert(5, "/D/2/3/4");
- insert(6, "/E/2/3/4/5");
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(0);
- CHECK_CS_FIND(0);
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(1);
- CHECK_CS_FIND(1);
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(2);
- CHECK_CS_FIND(2);
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(3);
- CHECK_CS_FIND(3);
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(4);
- CHECK_CS_FIND(4);
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(5);
- CHECK_CS_FIND(5);
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(6);
- CHECK_CS_FIND(6);
-
- startInterest("/")
- .setChildSelector(1)
- .setMaxSuffixComponents(7);
- CHECK_CS_FIND(6);
-}
-
BOOST_AUTO_TEST_CASE(MustBeFresh)
{
insert(1, "/A/1"); // omitted FreshnessPeriod means FreshnessPeriod = 0 ms
@@ -278,107 +118,34 @@
// lookup at exact same moment as insertion is not tested because this won't happen in reality
- this->advanceClocks(500_ms); // @500ms
+ advanceClocks(500_ms); // @500ms
startInterest("/A")
+ .setCanBePrefix(true)
.setMustBeFresh(true);
CHECK_CS_FIND(3);
- this->advanceClocks(1500_ms); // @2s
+ advanceClocks(1500_ms); // @2s
startInterest("/A")
+ .setCanBePrefix(true)
.setMustBeFresh(true);
CHECK_CS_FIND(4);
- this->advanceClocks(3500_s); // @3502s
+ advanceClocks(3500_s); // @3502s
startInterest("/A")
+ .setCanBePrefix(true)
.setMustBeFresh(true);
CHECK_CS_FIND(4);
- this->advanceClocks(3500_s); // @7002s
+ advanceClocks(3500_s); // @7002s
startInterest("/A")
+ .setCanBePrefix(true)
.setMustBeFresh(true);
CHECK_CS_FIND(0);
}
-BOOST_AUTO_TEST_CASE(DigestOrder)
-{
- Name n1 = insert(1, "/A");
- Name n2 = insert(2, "/A");
-
- uint32_t expectedLeftmost = 0, expectedRightmost = 0;
- if (n1 < n2) {
- expectedLeftmost = 1;
- expectedRightmost = 2;
- }
- else {
- BOOST_CHECK_MESSAGE(n1 != n2, "implicit digest collision detected");
- expectedLeftmost = 2;
- expectedRightmost = 1;
- }
-
- startInterest("/A")
- .setChildSelector(0);
- CHECK_CS_FIND(expectedLeftmost);
- startInterest("/A")
- .setChildSelector(1);
- CHECK_CS_FIND(expectedRightmost);
-}
-
-BOOST_AUTO_TEST_CASE(DigestExclude)
-{
- insert(1, "/A");
- Name n2 = insert(2, "/A");
- insert(3, "/A/B");
-
- uint8_t digest00[ndn::util::Sha256::DIGEST_SIZE];
- std::fill_n(digest00, sizeof(digest00), 0x00);
- uint8_t digestFF[ndn::util::Sha256::DIGEST_SIZE];
- std::fill_n(digestFF, sizeof(digestFF), 0xFF);
-
- ndn::Exclude excludeDigest;
- excludeDigest.excludeRange(
- name::Component::fromImplicitSha256Digest(digest00, sizeof(digest00)),
- name::Component::fromImplicitSha256Digest(digestFF, sizeof(digestFF)));
-
- startInterest("/A")
- .setChildSelector(0)
- .setExclude(excludeDigest);
- CHECK_CS_FIND(3);
-
- startInterest("/A")
- .setChildSelector(1)
- .setExclude(excludeDigest);
- CHECK_CS_FIND(3);
-
- ndn::Exclude excludeGeneric;
- excludeGeneric.excludeAfter(name::Component(static_cast<uint8_t*>(nullptr), 0));
-
- startInterest("/A")
- .setChildSelector(0)
- .setExclude(excludeGeneric);
- find([] (uint32_t found) { BOOST_CHECK(found == 1 || found == 2); });
-
- startInterest("/A")
- .setChildSelector(1)
- .setExclude(excludeGeneric);
- find([] (uint32_t found) { BOOST_CHECK(found == 1 || found == 2); });
-
- ndn::Exclude exclude2 = excludeGeneric;
- exclude2.excludeOne(n2.get(-1));
-
- startInterest("/A")
- .setChildSelector(0)
- .setExclude(exclude2);
- CHECK_CS_FIND(1);
-
- startInterest("/A")
- .setChildSelector(1)
- .setExclude(exclude2);
- CHECK_CS_FIND(1);
-}
-
BOOST_AUTO_TEST_SUITE_END() // Find
-BOOST_FIXTURE_TEST_CASE(Erase, FindFixture)
+BOOST_AUTO_TEST_CASE(Erase)
{
insert(1, "/A/B/1");
insert(2, "/A/B/2");
@@ -386,10 +153,10 @@
insert(4, "/A/C/4");
insert(5, "/D/5");
insert(6, "/E/6");
- BOOST_CHECK_EQUAL(m_cs.size(), 6);
+ BOOST_CHECK_EQUAL(cs.size(), 6);
BOOST_CHECK_EQUAL(erase("/A", 3), 3);
- BOOST_CHECK_EQUAL(m_cs.size(), 3);
+ BOOST_CHECK_EQUAL(cs.size(), 3);
int nDataUnderA = 0;
startInterest("/A/B/1");
find([&] (uint32_t found) { nDataUnderA += static_cast<int>(found > 0); });
@@ -402,42 +169,42 @@
BOOST_CHECK_EQUAL(nDataUnderA, 1);
BOOST_CHECK_EQUAL(erase("/D", 2), 1);
- BOOST_CHECK_EQUAL(m_cs.size(), 2);
+ BOOST_CHECK_EQUAL(cs.size(), 2);
startInterest("/D/5");
CHECK_CS_FIND(0);
BOOST_CHECK_EQUAL(erase("/F", 2), 0);
- BOOST_CHECK_EQUAL(m_cs.size(), 2);
+ BOOST_CHECK_EQUAL(cs.size(), 2);
}
// When the capacity limit is set to zero, Data cannot be inserted;
// this test case covers this situation.
// The behavior of non-zero capacity limit depends on the eviction policy,
// and is tested in policy test suites.
-BOOST_FIXTURE_TEST_CASE(ZeroCapacity, FindFixture)
+BOOST_AUTO_TEST_CASE(ZeroCapacity)
{
- m_cs.setLimit(0);
+ cs.setLimit(0);
- BOOST_CHECK_EQUAL(m_cs.getLimit(), 0);
- BOOST_CHECK_EQUAL(m_cs.size(), 0);
- BOOST_CHECK(m_cs.begin() == m_cs.end());
+ BOOST_CHECK_EQUAL(cs.getLimit(), 0);
+ BOOST_CHECK_EQUAL(cs.size(), 0);
+ BOOST_CHECK(cs.begin() == cs.end());
insert(1, "/A");
- BOOST_CHECK_EQUAL(m_cs.size(), 0);
+ BOOST_CHECK_EQUAL(cs.size(), 0);
startInterest("/A");
CHECK_CS_FIND(0);
}
-BOOST_FIXTURE_TEST_CASE(EnablementFlags, FindFixture)
+BOOST_AUTO_TEST_CASE(EnablementFlags)
{
- BOOST_CHECK_EQUAL(m_cs.shouldAdmit(), true);
- BOOST_CHECK_EQUAL(m_cs.shouldServe(), true);
+ BOOST_CHECK_EQUAL(cs.shouldAdmit(), true);
+ BOOST_CHECK_EQUAL(cs.shouldServe(), true);
insert(1, "/A");
- m_cs.enableAdmit(false);
+ cs.enableAdmit(false);
insert(2, "/B");
- m_cs.enableAdmit(true);
+ cs.enableAdmit(true);
insert(3, "/C");
startInterest("/A");
@@ -447,20 +214,20 @@
startInterest("/C");
CHECK_CS_FIND(3);
- m_cs.enableServe(false);
+ cs.enableServe(false);
startInterest("/A");
CHECK_CS_FIND(0);
startInterest("/C");
CHECK_CS_FIND(0);
- m_cs.enableServe(true);
+ cs.enableServe(true);
startInterest("/A");
CHECK_CS_FIND(1);
startInterest("/C");
CHECK_CS_FIND(3);
}
-BOOST_FIXTURE_TEST_CASE(CachePolicyNoCache, FindFixture)
+BOOST_AUTO_TEST_CASE(CachePolicyNoCache)
{
insert(1, "/A", [] (Data& data) {
data.setTag(make_shared<lp::CachePolicyTag>(
@@ -473,8 +240,6 @@
BOOST_AUTO_TEST_CASE(Enumeration)
{
- Cs cs;
-
Name nameA("/A");
Name nameAB("/A/B");
Name nameABC("/A/B/C");
@@ -483,7 +248,7 @@
BOOST_CHECK_EQUAL(cs.size(), 0);
BOOST_CHECK(cs.begin() == cs.end());
- cs.insert(*makeData(nameABC));
+ insert(123, nameABC);
BOOST_CHECK_EQUAL(cs.size(), 1);
BOOST_CHECK(cs.begin() != cs.end());
BOOST_CHECK(cs.begin()->getName() == nameABC);
@@ -495,9 +260,9 @@
BOOST_CHECK(j++ == cs.begin());
BOOST_CHECK(j == cs.end());
- cs.insert(*makeData(nameA));
- cs.insert(*makeData(nameAB));
- cs.insert(*makeData(nameD));
+ insert(1, nameA);
+ insert(12, nameAB);
+ insert(4, nameD);
std::set<Name> expected = {nameA, nameAB, nameABC, nameD};
std::set<Name> actual;