Remove dependency on Selectors and refactor codebase.
Change-Id: Ic3024b76ba0eea61f790c91c36090b4aa68702a3
Refs: #4522
diff --git a/tests/dataset-fixtures.hpp b/tests/dataset-fixtures.hpp
index bb03bd6..1a4e272 100644
--- a/tests/dataset-fixtures.hpp
+++ b/tests/dataset-fixtures.hpp
@@ -40,13 +40,13 @@
}
};
- typedef std::list<std::shared_ptr<ndn::Data> > DataContainer;
+ using DataContainer = std::list<std::shared_ptr<ndn::Data>>;
DataContainer data;
- typedef std::list<std::pair<ndn::Interest, std::shared_ptr<ndn::Data> > > InterestContainer;
+ using InterestContainer = std::list<std::pair<ndn::Interest, std::shared_ptr<ndn::Data>>>;
InterestContainer interests;
- typedef std::list<std::pair<ndn::Interest, size_t > > RemovalsContainer;
+ using RemovalsContainer = std::list<std::pair<ndn::Interest, size_t>>;
RemovalsContainer removals;
protected:
@@ -77,7 +77,7 @@
}
private:
- std::map<Name, shared_ptr<Data> > map;
+ std::map<Name, std::shared_ptr<Data>> map;
};
@@ -205,187 +205,10 @@
}
};
-
-class BasicChildSelectorDataset : public DatasetBase
-{
-public:
- static const std::string&
- getName()
- {
- static std::string name = "BasicChildSelectorDataset";
- return name;
- }
-
- BasicChildSelectorDataset()
- {
- this->data.push_back(createData("/a/1"));
- this->data.push_back(createData("/b/1"));
- this->interests.push_back(std::make_pair(Interest()
- .setName("/b")
- .setSelectors(Selectors()
- .setChildSelector(0)),
- this->data.back()));
-
- this->data.push_back(createData("/c/1"));
- this->data.push_back(createData("/b/99"));
- this->interests.push_back(std::make_pair(Interest()
- .setName("/b")
- .setSelectors(Selectors()
- .setChildSelector(1)),
- this->data.back()));
- this->data.push_back(createData("/b/5"));
- this->data.push_back(createData("/b/55"));
- }
-};
-
-
-class ExtendedChildSelectorDataset : public DatasetBase
-{
-public:
- static const std::string&
- getName()
- {
- static std::string name = "storage";
- return name;
- }
-
- ExtendedChildSelectorDataset()
- {
- this->data.push_back(createData("/a/b/1"));
-
- this->data.push_back(createData("/a/c/1"));
- this->interests.push_back(std::make_pair(Interest("/a")
- .setSelectors(Selectors()
- .setChildSelector(1)),
- this->data.back()));
-
- this->data.push_back(createData("/a/c/2"));
-
- this->data.push_back(createData("/b"));
- }
-};
-
-
-class ComplexSelectorsDataset : public DatasetBase
-{
-public:
- static const std::string&
- getName()
- {
- static std::string name = "ComplexSelectorsDataset";
- return name;
- }
-
- std::map<std::string, shared_ptr<Data> > map;
-
- void
- addData(const std::string& name)
- {
- }
-
- ComplexSelectorsDataset()
- {
- // Dataset
- this->data.push_back(createData("/a/b/c"));
- this->data.push_back(createData("/a/b/d/1"));
- this->data.push_back(createData("/a/b/d/2"));
- this->data.push_back(createData("/a/b/d/3"));
- this->data.push_back(createData("/a/b/d/4/I"));
- this->data.push_back(createData("/a/b/d/4"));
- this->data.push_back(createData("/a/b/d"));
- this->data.push_back(createData("/a/b/e/1"));
- this->data.push_back(createData("/a/b/e"));
-
- // 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")));
- 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")));
- 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
- this->interests.push_back(std::make_pair(Interest("/a/b")
- .setSelectors(Selectors()
- .setMinSuffixComponents(2)
- .setMaxSuffixComponents(2)),
- this->getData("/a/b/c")));
-
- this->interests.push_back(std::make_pair(Interest("/a/b/d")
- .setSelectors(Selectors()
- .setMinSuffixComponents(-1)
- .setChildSelector(0)),
- this->getData("/a/b/d")));
-
- this->interests.push_back(std::make_pair(Interest("/a/b/d")
- .setSelectors(Selectors()
- .setMinSuffixComponents(2)
- .setChildSelector(0)),
- this->getData("/a/b/d/1")));
-
- this->interests.push_back(std::make_pair(
- Interest("/a/b/d")
- .setSelectors(Selectors()
- .setChildSelector(1)
- .setMaxSuffixComponents(2)
- .setMinSuffixComponents(2)
- .setExclude(Exclude()
- .excludeRange(ndn::name::Component("3"),
- ndn::name::Component("4")))),
- this->getData("/a/b/d/2")));
-
-
- this->interests.push_back(std::make_pair(Interest("/a/b/d")
- .setSelectors(Selectors().setMinSuffixComponents(3)),
- this->getData("/a/b/d/4/I")));
-
- // According to selector definition, RightMost for the next level and LeftMost for the next-next level
- this->interests.push_back(std::make_pair(Interest("/a/b/d")
- .setSelectors(Selectors()
- .setMinSuffixComponents(2)
- .setChildSelector(1)),
- 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/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")
- .setSelectors(Selectors()
- .setPublisherPublicKeyLocator(
- this->data.back()
- ->getSignature().getKeyLocator())),
- this->getData("/a/b/e")));
-
- // Removals
- this->removals.push_back(std::make_pair(Interest("/a/b/d/2"), 1));
-
- this->removals.push_back(std::make_pair(
- Interest("/a/b/d")
- .setSelectors(Selectors()
- .setMaxSuffixComponents(2)
- .setMinSuffixComponents(2)
- .setExclude(Exclude()
- .excludeOne(ndn::name::Component("3")))),
- 2));
- }
-};
-
-
-typedef boost::mpl::vector<BasicDataset,
- FetchByPrefixDataset,
- BasicChildSelectorDataset,
- ExtendedChildSelectorDataset,
- SamePrefixDataset<10>,
- SamePrefixDataset<100>> CommonDatasets;
-
-
+using CommonDatasets = boost::mpl::vector<BasicDataset,
+ FetchByPrefixDataset,
+ SamePrefixDataset<10>,
+ SamePrefixDataset<100>>;
} // namespace tests
} // namespace repo
diff --git a/tests/integrated/command-fixture.cpp b/tests/integrated/command-fixture.cpp
index a803a51..ad7955a 100644
--- a/tests/integrated/command-fixture.cpp
+++ b/tests/integrated/command-fixture.cpp
@@ -28,8 +28,8 @@
, dispatcher(repoFace, keyChain)
, validator(repoFace)
{
- this->saveIdentityCertificate(keyChain.getPib().getDefaultIdentity().getName(),
- "tests/integrated/insert-delete-test.cert");
+ this->addIdentity("/ndn/test/repo");
+ this->saveIdentityCertificate("/ndn/test/repo", "tests/integrated/insert-delete-test.cert");
validator.load("tests/integrated/insert-delete-validator-config.conf");
}
diff --git a/tests/integrated/insert-delete-validator-config.conf b/tests/integrated/insert-delete-validator-config.conf
index c97bb4c..0820266 100644
--- a/tests/integrated/insert-delete-validator-config.conf
+++ b/tests/integrated/insert-delete-validator-config.conf
@@ -1,8 +1,7 @@
; The test rules below are for test suite TestBasicCommandInsertDelete.
; Signed interests and data packets are signed by default certificate.
; In these test rules, the type of checker is fixed signer and signer type is file.
-; So user who wants to run this test could use security tool to dump the defualt
-; certificate into a file named "insert-delete-test.cert"
+
rule
{
id "Test Rule For Signed Interest"
@@ -20,7 +19,7 @@
key-locator
{
type name
- name /DEFAULT
+ name /ndn/test/repo
relation equal
}
}
@@ -43,7 +42,7 @@
key-locator
{
type name
- name /DEFAULT
+ name /ndn/test/repo
relation equal
}
}
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index ea58abe..f3685f6 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -36,9 +36,6 @@
#include <boost/mpl/vector.hpp>
#include <boost/test/unit_test.hpp>
-
-#include <iostream>
-
namespace repo {
namespace tests {
@@ -46,6 +43,7 @@
using ndn::time::seconds;
using ndn::EventId;
+
// All the test cases in this test suite should be run at once.
BOOST_AUTO_TEST_SUITE(TestBasicCommandInsertDelete)
@@ -60,6 +58,7 @@
, deleteHandle(repoFace, *handle, dispatcher, scheduler, validator)
, insertFace(repoFace.getIoService())
, deleteFace(repoFace.getIoService())
+ , signer(keyChain)
{
Name cmdPrefix("/repo/command");
repoFace.registerPrefix(cmdPrefix, nullptr,
@@ -113,6 +112,8 @@
Face insertFace;
Face deleteFace;
std::map<Name, EventId> insertEvents;
+ std::map<Name, Name> deleteNamePairs;
+ ndn::security::CommandInterestSigner signer;
};
template<class T> void
@@ -129,9 +130,7 @@
insertEvents.erase(event);
}
// schedule an event 50ms later to check whether insert is Ok
- scheduler.scheduleEvent(500_ms,
- bind(&Fixture<T>::checkInsertOk, this, interest));
-
+ scheduler.scheduleEvent(500_ms, std::bind(&Fixture<T>::checkInsertOk, this, interest));
}
@@ -165,8 +164,7 @@
BOOST_CHECK_EQUAL(statusCode, 200);
//schedlute an event to check whether delete is Ok.
- scheduler.scheduleEvent(100_ms,
- bind(&Fixture<T>::checkDeleteOk, this, interest));
+ scheduler.scheduleEvent(100_ms, std::bind(&Fixture<T>::checkDeleteOk, this, interest));
}
template<class T> void
@@ -185,25 +183,25 @@
Fixture<T>::sendInsertInterest(const Interest& insertInterest)
{
insertFace.expressInterest(insertInterest,
- bind(&Fixture<T>::onInsertData, this, _1, _2),
- bind(&Fixture<T>::onInsertTimeout, this, _1), // Nack
- bind(&Fixture<T>::onInsertTimeout, this, _1));
+ std::bind(&Fixture<T>::onInsertData, this, _1, _2),
+ std::bind(&Fixture<T>::onInsertTimeout, this, _1), // Nack
+ std::bind(&Fixture<T>::onInsertTimeout, this, _1));
}
template<class T> void
Fixture<T>::sendDeleteInterest(const Interest& deleteInterest)
{
deleteFace.expressInterest(deleteInterest,
- bind(&Fixture<T>::onDeleteData, this, _1, _2),
- bind(&Fixture<T>::onDeleteTimeout, this, _1), // Nack
- bind(&Fixture<T>::onDeleteTimeout, this, _1));
+ std::bind(&Fixture<T>::onDeleteData, this, _1, _2),
+ std::bind(&Fixture<T>::onDeleteTimeout, this, _1), // Nack
+ std::bind(&Fixture<T>::onDeleteTimeout, this, _1));
}
template<class T> void
Fixture<T>::checkInsertOk(const Interest& interest)
{
BOOST_TEST_MESSAGE(interest);
- shared_ptr<Data> data = handle->readData(interest);
+ std::shared_ptr<Data> data = handle->readData(interest);
if (data) {
int rc = memcmp(data->getContent().value(), content, sizeof(content));
BOOST_CHECK_EQUAL(rc, 0);
@@ -216,10 +214,14 @@
template<class T> void
Fixture<T>::checkDeleteOk(const Interest& interest)
{
- shared_ptr<Data> data = handle->readData(interest);
- BOOST_CHECK_EQUAL(data, shared_ptr<Data>());
+ std::map<Name, Name>::iterator name = deleteNamePairs.find(interest.getName());
+ BOOST_CHECK_MESSAGE(name != deleteNamePairs.end(), "Delete name not found: " << interest.getName());
+ Interest dataInterest(name->second);
+ std::shared_ptr<Data> data = handle->readData(dataInterest);
+ BOOST_CHECK(!data);
}
+
template<class T> void
Fixture<T>::scheduleInsertEvent()
{
@@ -230,24 +232,20 @@
RepoCommandParameter insertParameter;
insertParameter.setName(Name((*i)->getName())
.appendNumber(ndn::random::generateWord64()));
-
insertCommandName.append(insertParameter.wireEncode());
- Interest insertInterest(insertCommandName);
- keyChain.sign(insertInterest);
-
+ Interest insertInterest = signer.makeCommandInterest(insertCommandName);
// schedule a job to express insertInterest every 50ms
scheduler.scheduleEvent(milliseconds(timeCount * 50 + 1000),
- bind(&Fixture<T>::sendInsertInterest, this, insertInterest));
+ std::bind(&Fixture<T>::sendInsertInterest, this, insertInterest));
// schedule what to do when interest timeout
EventId delayEventId = scheduler.scheduleEvent(milliseconds(5000 + timeCount * 50),
- bind(&Fixture<T>::delayedInterest, this));
+ std::bind(&Fixture<T>::delayedInterest, this));
insertEvents[insertParameter.getName()] = delayEventId;
-
- //The delayEvent will be canceled in onInsertInterest
+ // The delayEvent will be canceled in onInsertInterest
insertFace.setInterestFilter(insertParameter.getName(),
- bind(&Fixture<T>::onInsertInterest, this, _2),
+ std::bind(&Fixture<T>::onInsertInterest, this, _2),
ndn::RegisterPrefixSuccessCallback(),
- bind(&Fixture<T>::onRegisterFailed, this, _2));
+ std::bind(&Fixture<T>::onRegisterFailed, this, _2));
timeCount++;
}
}
@@ -263,27 +261,23 @@
deleteParameter.setProcessId(ndn::random::generateWord64());
deleteParameter.setName((*i)->getName());
deleteCommandName.append(deleteParameter.wireEncode());
- Interest deleteInterest(deleteCommandName);
- keyChain.sign(deleteInterest);
+ Interest deleteInterest = signer.makeCommandInterest(deleteCommandName);
+ deleteNamePairs[deleteInterest.getName()] = (*i)->getName();
scheduler.scheduleEvent(milliseconds(4000 + timeCount * 50),
- bind(&Fixture<T>::sendDeleteInterest, this, deleteInterest));
+ std::bind(&Fixture<T>::sendDeleteInterest, this, deleteInterest));
timeCount++;
}
}
-typedef boost::mpl::vector<BasicDataset,
- FetchByPrefixDataset,
- BasicChildSelectorDataset,
- ExtendedChildSelectorDataset,
- SamePrefixDataset<10>> Datasets;
+using Datasets = boost::mpl::vector<BasicDataset,
+ FetchByPrefixDataset,
+ SamePrefixDataset<10>>;
BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, Datasets, Fixture<T>)
{
// schedule events
- this->scheduler.scheduleEvent(0_s,
- bind(&Fixture<T>::scheduleInsertEvent, this));
- this->scheduler.scheduleEvent(10_s,
- bind(&Fixture<T>::scheduleDeleteEvent, this));
+ this->scheduler.scheduleEvent(0_s, std::bind(&Fixture<T>::scheduleInsertEvent, this));
+ this->scheduler.scheduleEvent(10_s, std::bind(&Fixture<T>::scheduleDeleteEvent, this));
this->repoFace.processEvents(30_s);
}
diff --git a/tests/integrated/test-basic-command-watch.cpp b/tests/integrated/test-basic-command-watch.cpp
deleted file mode 100644
index 6fe677d..0000000
--- a/tests/integrated/test-basic-command-watch.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2018, Regents of the University of California.
- *
- * This file is part of NDN repo-ng (Next generation of NDN repository).
- * See AUTHORS.md for complete list of repo-ng authors and contributors.
- *
- * repo-ng 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.
- *
- * repo-ng 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
- * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "handles/watch-handle.hpp"
-#include "storage/sqlite-storage.hpp"
-
-#include "command-fixture.hpp"
-#include "../repo-storage-fixture.hpp"
-#include "../dataset-fixtures.hpp"
-
-#include <ndn-cxx/util/random.hpp>
-
-#include <boost/mpl/vector.hpp>
-#include <boost/test/unit_test.hpp>
-
-namespace repo {
-namespace tests {
-
-using ndn::time::milliseconds;
-using ndn::time::seconds;
-using ndn::EventId;
-
-// All the test cases in this test suite should be run at once.
-BOOST_AUTO_TEST_SUITE(TestBasicCommandWatchDelete)
-
-const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
-
-template<class Dataset>
-class Fixture : public CommandFixture, public RepoStorageFixture, public Dataset
-{
-public:
- Fixture()
- : watchHandle(repoFace, *handle, dispatcher, scheduler, validator)
- , watchFace(repoFace.getIoService())
- {
- Name cmdPrefix("/repo/command");
- repoFace.registerPrefix(cmdPrefix, nullptr,
- [] (const Name& cmdPrefix, const std::string& reason) {
- BOOST_FAIL("Command prefix registration error: " << reason);
- });
- }
-
- void
- scheduleWatchEvent();
-
- void
- onWatchInterest(const Interest& interest);
-
- void
- onRegisterFailed(const std::string& reason);
-
- void
- delayedInterest();
-
- void
- onWatchData(const Interest& interest, const Data& data);
-
- void
- onWatchStopData(const Interest& interest, const Data& data);
-
- void
- onWatchTimeout(const Interest& interest);
-
- void
- sendWatchStartInterest(const Interest& interest);
-
- void
- sendWatchStopInterest(const Interest& interest);
-
- void
- checkWatchOk(const Interest& interest);
-
-public:
- WatchHandle watchHandle;
- Face watchFace;
- std::map<Name, EventId> watchEvents;
-};
-
-template<class T> void
-Fixture<T>::onWatchInterest(const Interest& interest)
-{
- auto data = make_shared<Data>(Name(interest.getName())
- .appendNumber(ndn::random::generateWord64() + 100));
- data->setContent(content, sizeof(content));
- data->setFreshnessPeriod(0_ms);
- keyChain.sign(*data);
- watchFace.put(*data);
-
- // schedule an event 50ms later to check whether watch is Ok
- scheduler.scheduleEvent(10000_ms,
- bind(&Fixture<T>::checkWatchOk, this,
- Interest(data->getName())));
-}
-
-
-template<class T> void
-Fixture<T>::onRegisterFailed(const std::string& reason)
-{
- BOOST_ERROR("ERROR: Failed to register prefix in local hub's daemon" + reason);
-}
-
-template<class T> void
-Fixture<T>::delayedInterest()
-{
- BOOST_ERROR("Fetching interest does not come. It may be satisfied in CS or something is wrong");
-}
-
-template<class T> void
-Fixture<T>::onWatchData(const Interest& interest, const Data& data)
-{
- RepoCommandResponse response;
- response.wireDecode(data.getContent().blockFromValue());
-
- int statusCode = response.getCode();
- BOOST_CHECK_EQUAL(statusCode, 100);
-}
-
-template<class T> void
-Fixture<T>::onWatchStopData(const Interest& interest, const Data& data)
-{
- RepoCommandResponse response;
- response.wireDecode(data.getContent().blockFromValue());
-
- int statusCode = response.getCode();
- BOOST_CHECK_EQUAL(statusCode, 101);
-}
-
-template<class T> void
-Fixture<T>::onWatchTimeout(const Interest& interest)
-{
- BOOST_ERROR("Watch command timeout");
-}
-
-template<class T> void
-Fixture<T>::sendWatchStartInterest(const Interest& watchInterest)
-{
- watchFace.expressInterest(watchInterest,
- bind(&Fixture<T>::onWatchData, this, _1, _2),
- bind(&Fixture<T>::onWatchTimeout, this, _1), // Nack
- bind(&Fixture<T>::onWatchTimeout, this, _1));
-}
-
-template<class T> void
-Fixture<T>::sendWatchStopInterest(const Interest& watchInterest)
-{
- watchFace.expressInterest(watchInterest,
- bind(&Fixture<T>::onWatchStopData, this, _1, _2),
- bind(&Fixture<T>::onWatchTimeout, this, _1), // Nack
- bind(&Fixture<T>::onWatchTimeout, this, _1));
-}
-
-template<class T> void
-Fixture<T>::checkWatchOk(const Interest& interest)
-{
- BOOST_TEST_MESSAGE(interest);
- shared_ptr<Data> data = handle->readData(interest);
- if (data) {
- int rc = memcmp(data->getContent().value(), content, sizeof(content));
- BOOST_CHECK_EQUAL(rc, 0);
- }
- else {
- std::cerr<<"Check Watch Failed"<<std::endl;
- }
-}
-
-template<class T> void
-Fixture<T>::scheduleWatchEvent()
-{
- Name watchCommandName("/repo/command/watch/start");
- RepoCommandParameter watchParameter;
- watchParameter.setName(Name("/a/b"));
- watchParameter.setMaxInterestNum(10);
- watchParameter.setInterestLifetime(50000_ms);
- watchParameter.setWatchTimeout(1000000000_ms);
- watchCommandName.append(watchParameter.wireEncode());
- Interest watchInterest(watchCommandName);
- keyChain.sign(watchInterest);
- //schedule a job to express watchInterest
- scheduler.scheduleEvent(1000_ms,
- bind(&Fixture<T>::sendWatchStartInterest, this, watchInterest));
-
- Name watchStopName("/repo/command/watch/stop");
- RepoCommandParameter watchStopParameter;
- watchStopName.append(watchStopParameter.wireEncode());
- Interest watchStopInterest(watchStopName);
- keyChain.sign(watchStopInterest);
-
- //The delayEvent will be canceled in onWatchInterest
- watchFace.setInterestFilter(watchParameter.getName(),
- bind(&Fixture<T>::onWatchInterest, this, _2),
- ndn::RegisterPrefixSuccessCallback(),
- bind(&Fixture<T>::onRegisterFailed, this, _2));
-}
-
-typedef boost::mpl::vector<BasicDataset> Dataset;
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(WatchDelete, T, Dataset, Fixture<T>)
-{
- // schedule events
- this->scheduler.scheduleEvent(1_s,
- bind(&Fixture<T>::scheduleWatchEvent, this));
-
- this->repoFace.processEvents(500_s);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace repo
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index 0ad2f3c..d73b0d1 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -27,12 +27,14 @@
#include <boost/asio/io_service.hpp>
#include <boost/test/unit_test.hpp>
+#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/time.hpp>
namespace repo {
namespace tests {
-// All the test cases in this test suite should be run at once.
+NDN_LOG_INIT(repo.tests.read);
+
BOOST_AUTO_TEST_SUITE(TestBasicInerestRead)
const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
@@ -69,13 +71,16 @@
(*i)->setContent(content, sizeof(content));
(*i)->setFreshnessPeriod(36000_ms);
keyChain.sign(**i);
+ NDN_LOG_DEBUG(**i);
bool rc = handle->insertData(**i);
BOOST_CHECK_EQUAL(rc, true);
+ NDN_LOG_DEBUG("Inserted Data " << (**i).getName());
+
Interest readInterest((*i)->getName());
readInterest.setMustBeFresh(true);
scheduler.scheduleEvent(ndn::time::milliseconds(timeCount * 50),
- bind(&BasicInterestReadFixture<Dataset>::sendInterest, this,
+ std::bind(&BasicInterestReadFixture<Dataset>::sendInterest, this,
readInterest));
timeCount++;
}
@@ -91,22 +96,25 @@
void
onReadTimeout(const ndn::Interest& interest)
{
- BOOST_ERROR("Insert not successfull or Read data does not successfull");
+ NDN_LOG_DEBUG("Timed out " << interest.getName());
+ BOOST_ERROR("Insert or read not successfull");
}
void
onReadNack(const ndn::Interest& interest, const ndn::lp::Nack& nack)
{
+ NDN_LOG_DEBUG("Nacked " << interest.getName() << nack.getReason());
BOOST_ERROR("Read nacked");
}
void
sendInterest(const ndn::Interest& interest)
{
+ NDN_LOG_DEBUG("Sending Interest " << interest.getName());
readFace.expressInterest(interest,
- bind(&BasicInterestReadFixture::onReadData, this, _1, _2),
- bind(&BasicInterestReadFixture::onReadNack, this, _1, _2),
- bind(&BasicInterestReadFixture::onReadTimeout, this, _1));
+ std::bind(&BasicInterestReadFixture::onReadData, this, _1, _2),
+ std::bind(&BasicInterestReadFixture::onReadNack, this, _1, _2),
+ std::bind(&BasicInterestReadFixture::onReadTimeout, this, _1));
}
public:
@@ -117,17 +125,16 @@
ndn::Face readFace;
};
-typedef boost::mpl::vector<BasicDataset,
- FetchByPrefixDataset,
- BasicChildSelectorDataset,
- ExtendedChildSelectorDataset,
- SamePrefixDataset<10>> Datasets;
+
+using Datasets = boost::mpl::vector<BasicDataset,
+ FetchByPrefixDataset,
+ SamePrefixDataset<10>>;
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Read, T, Datasets, BasicInterestReadFixture<T>)
{
this->startListen();
this->scheduler.scheduleEvent(1_s,
- bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
+ std::bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
this->repoFace.processEvents(20_s);
diff --git a/tests/repo-storage-fixture.hpp b/tests/repo-storage-fixture.hpp
index 29df163..9a82169 100644
--- a/tests/repo-storage-fixture.hpp
+++ b/tests/repo-storage-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014, Regents of the University of California.
+ * Copyright (c) 2018, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -32,8 +32,8 @@
{
public:
RepoStorageFixture()
- : store(make_shared<SqliteStorage>("unittestdb"))
- , handle(new RepoStorage(static_cast<int64_t>(65535), *store))
+ : store(std::make_shared<SqliteStorage>("unittestdb"))
+ , handle(std::make_shared<RepoStorage>(*store))
{
}
@@ -44,8 +44,8 @@
public:
- shared_ptr<Storage> store;
- shared_ptr<RepoStorage> handle;
+ std::shared_ptr<Storage> store;
+ std::shared_ptr<RepoStorage> handle;
};
} // namespace tests
diff --git a/tests/unit/index.cpp b/tests/unit/index.cpp
deleted file mode 100644
index 6f255a2..0000000
--- a/tests/unit/index.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2017, Regents of the University of California.
- *
- * This file is part of NDN repo-ng (Next generation of NDN repository).
- * See AUTHORS.md for complete list of repo-ng authors and contributors.
- *
- * repo-ng 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.
- *
- * repo-ng 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
- * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "storage/index.hpp"
-
-#include "../sqlite-fixture.hpp"
-#include "../dataset-fixtures.hpp"
-
-#include <iostream>
-
-#include <ndn-cxx/security/signing-helpers.hpp>
-#include <ndn-cxx/util/sha256.hpp>
-#include <ndn-cxx/util/random.hpp>
-
-#include <boost/mpl/push_back.hpp>
-#include <boost/test/unit_test.hpp>
-
-namespace repo {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(Index)
-
-class FindFixture
-{
-protected:
- FindFixture()
- : m_index(std::numeric_limits<size_t>::max())
- {
- }
-
- Name
- insert(int id, const Name& name)
- {
- shared_ptr<Data> data = make_shared<Data>(name);
- data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
- m_keyChain.sign(*data, ndn::signingWithSha256());
- data->wireEncode();
- m_index.insert(*data, id);
-
- return data->getFullName();
- }
-
- Interest&
- startInterest(const Name& name)
- {
- m_interest = make_shared<Interest>(name);
- return *m_interest;
- }
-
- int
- find()
- {
- std::pair<int, Name> found = m_index.find(*m_interest);
- return found.first;
- }
-
-protected:
- repo::Index m_index;
- KeyChain m_keyChain;
- shared_ptr<Interest> m_interest;
-};
-
-BOOST_FIXTURE_TEST_SUITE(Find, FindFixture)
-
-BOOST_AUTO_TEST_CASE(EmptyDataName)
-{
- insert(1, "ndn:/");
- startInterest("ndn:/");
- BOOST_CHECK_EQUAL(find(), 1);
-}
-
-BOOST_AUTO_TEST_CASE(EmptyInterestName)
-{
- insert(1, "ndn:/A");
- startInterest("ndn:/");
- 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");
- insert(2, "ndn:/B/p/1");
- insert(3, "ndn:/B/p/2");
- insert(4, "ndn:/B/q/1");
- insert(5, "ndn:/B/q/2");
- insert(6, "ndn:/C");
-
- startInterest("ndn:/B");
- BOOST_CHECK_EQUAL(find(), 2);
-}
-
-BOOST_AUTO_TEST_CASE(Rightmost)
-{
- insert(1, "ndn:/A");
- insert(2, "ndn:/B/p/1");
- insert(3, "ndn:/B/p/2");
- insert(4, "ndn:/B/q/1");
- insert(5, "ndn:/B/q/2");
- insert(6, "ndn:/C");
-
- startInterest("ndn:/B")
- .setChildSelector(1);
- BOOST_CHECK_EQUAL(find(), 4);
-}
-
-BOOST_AUTO_TEST_CASE(MinSuffixComponents)
-{
- insert(1, "ndn:/");
- insert(2, "ndn:/A");
- 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:/")
- .setMinSuffixComponents(0);
- BOOST_CHECK_EQUAL(find(), 1);
-
- startInterest("ndn:/")
- .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(MaxSuffixComponents)
-{
- insert(1, "ndn:/");
- insert(2, "ndn:/A");
- 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)
-{
- insert(1, "ndn:/A");
- insert(2, "ndn:/A");
- // We don't know which comes first, but there must be some order
-
- startInterest("ndn:/A")
- .setChildSelector(0);
- uint32_t leftmost = find();
-
- startInterest("ndn:/A")
- .setChildSelector(1);
- uint32_t rightmost = find();
-
- BOOST_CHECK_NE(leftmost, rightmost);
-}
-
-BOOST_AUTO_TEST_CASE(DigestExclude)
-{
- insert(1, "ndn:/A");
- Name n2 = insert(2, "ndn:/A");
- insert(3, "ndn:/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);
-
- Exclude excludeDigest;
- excludeDigest.excludeRange(
- name::Component::fromImplicitSha256Digest(digest00, sizeof(digest00)),
- name::Component::fromImplicitSha256Digest(digestFF, sizeof(digestFF)));
-
- startInterest("ndn:/A")
- .setChildSelector(0)
- .setExclude(excludeDigest);
- BOOST_CHECK_EQUAL(find(), 3);
-
- startInterest("ndn:/A")
- .setChildSelector(1)
- .setExclude(excludeDigest);
- BOOST_CHECK_EQUAL(find(), 3);
-
- Exclude excludeGeneric;
- excludeGeneric.excludeAfter(name::Component(static_cast<uint8_t*>(nullptr), 0));
-
- startInterest("ndn:/A")
- .setChildSelector(0)
- .setExclude(excludeGeneric);
- int found1 = find();
- BOOST_CHECK(found1 == 1 || found1 == 2);
-
- startInterest("ndn:/A")
- .setChildSelector(1)
- .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:/A")
- .setChildSelector(1)
- .setExclude(exclude2);
- BOOST_CHECK_EQUAL(find(), 1);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // Find
-
-
-template<class Dataset>
-class Fixture : public Dataset
-{
-public:
- Fixture()
- : index(65535)
- {
- }
-
-public:
- std::map<int64_t, shared_ptr<Data> > idToDataMap;
- repo::Index index;
-};
-
-// Combine CommonDatasets with ComplexSelectorDataset
-typedef boost::mpl::push_back<CommonDatasets,
- ComplexSelectorsDataset>::type Datasets;
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>)
-{
- BOOST_TEST_MESSAGE(T::getName());
-
- for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i)
- {
- int64_t id = std::abs(static_cast<int64_t>(ndn::random::generateWord64()));
- this->idToDataMap.insert(std::make_pair(id, *i));
-
- BOOST_CHECK_EQUAL(this->index.insert(**i, id), true);
- }
-
- BOOST_CHECK_EQUAL(this->index.size(), this->data.size());
-
- for (typename T::InterestContainer::iterator i = this->interests.begin();
- i != this->interests.end(); ++i)
- {
- std::pair<int64_t, Name> item = this->index.find(i->first);
-
- BOOST_REQUIRE_GT(item.first, 0);
- BOOST_REQUIRE(this->idToDataMap.count(item.first) > 0);
-
- BOOST_TEST_MESSAGE(i->first);
- BOOST_CHECK_EQUAL(*this->idToDataMap[item.first], *i->second);
-
- BOOST_CHECK_EQUAL(this->index.hasData(*i->second), true);
- }
-
- // Need support for selector-based removal
- // for (typename T::RemovalsContainer::iterator i = this->removals.begin();
- // i != this->removals.end(); ++i)
- // {
- // size_t nRemoved = 0;
- // BOOST_REQUIRE_NO_THROW(this->index.erase(*i));
- // BOOST_CHECK_EQUAL(nRemoved, i->seconds);
- // }
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace repo
diff --git a/tests/unit/repo-command-parameter.cpp b/tests/unit/repo-command-parameter.cpp
index 3e35169..f01832a 100644
--- a/tests/unit/repo-command-parameter.cpp
+++ b/tests/unit/repo-command-parameter.cpp
@@ -19,8 +19,12 @@
#include "repo-command-parameter.hpp"
-#include <ndn-cxx/selectors.hpp>
+#include "common.hpp"
+#include <ndn-cxx/encoding/block.hpp>
+#include <ndn-cxx/encoding/block-helpers.hpp>
+
+#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
namespace repo {
@@ -35,33 +39,21 @@
parameter.setStartBlockId(1);
parameter.setEndBlockId(100);
parameter.setProcessId(1234567890);
- ndn::Selectors selectors;
- selectors.setMaxSuffixComponents(1);
- parameter.setSelectors(selectors);
- ndn::Block wire = parameter.wireEncode();
+ Block wire = parameter.wireEncode();
// These octets are obtained by the snippet below.
// This check is intended to detect unexpected encoding change in the future.
- //for (auto it = wire.begin(); it != wire.end(); ++it) {
- // printf("0x%02x, ", *it);
- //}
- static const uint8_t expected[] = {
- 0xc9, 0x1c, 0x07, 0x09, 0x08, 0x01, 0x61, 0x08, 0x01, 0x62, 0x08,
- 0x01, 0x63, 0x09, 0x03, 0x0e, 0x01, 0x01, 0xcc, 0x01, 0x01, 0xcd,
- 0x01, 0x64, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2
- };
+ // Construct a \c Block from hexadecimal \p input.
+ Block expected = "C917 0709080161080162080163CC0101CD0164CE04499602D2"_block;
- BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
- wire.begin(), wire.end());
+ BOOST_CHECK_EQUAL(wire, expected);
repo::RepoCommandParameter decoded(wire);
BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName());
BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId());
BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId());
BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId());
- BOOST_CHECK_EQUAL(decoded.getSelectors().getMaxSuffixComponents(),
- parameter.getSelectors().getMaxSuffixComponents());
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit/repo-command-response.cpp b/tests/unit/repo-command-response.cpp
index 7686c50..057b180 100644
--- a/tests/unit/repo-command-response.cpp
+++ b/tests/unit/repo-command-response.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2018, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -19,6 +19,8 @@
#include "repo-command-response.hpp"
+#include "common.hpp"
+
#include <boost/test/unit_test.hpp>
namespace repo {
@@ -36,21 +38,15 @@
response.setInsertNum(100);
response.setDeleteNum(100);
- ndn::Block wire = response.wireEncode();
+ Block wire = response.wireEncode();
// These octets are obtained by the snippet below.
// This check is intended to detect unexpected encoding change in the future.
- //for (auto it = wire.begin(); it != wire.end(); ++it) {
- // printf("0x%02x, ", *it);
- //}
- static const uint8_t expected[] = {
- 0xcf, 0x16, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2, 0xd0, 0x02,
- 0x01, 0x94, 0xcc, 0x01, 0x01, 0xcd, 0x01, 0x64, 0xd1, 0x01,
- 0x64, 0xd2, 0x01, 0x64
- };
+ // Construct a \c Block from hexadecimal \p input.
- BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
- wire.begin(), wire.end());
+ Block expected = "CF16 CE04499602D2D0020194CC0101CD0164D10164D20164"_block;
+
+ BOOST_CHECK_EQUAL(wire, expected);
repo::RepoCommandResponse decoded(wire);
BOOST_CHECK_EQUAL(decoded.getCode(), response.getCode());
diff --git a/tests/unit/repo-storage.cpp b/tests/unit/repo-storage.cpp
index 1caecf1..0458c23 100644
--- a/tests/unit/repo-storage.cpp
+++ b/tests/unit/repo-storage.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -37,41 +37,31 @@
{
};
-// Combine CommonDatasets with ComplexSelectorDataset
-typedef boost::mpl::push_back<CommonDatasets,
- ComplexSelectorsDataset>::type Datasets;
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, CommonDatasets, Fixture<T>)
{
- // typedef ComplexSelectorsDataset T;
BOOST_TEST_MESSAGE(T::getName());
// Insert data into repo
- for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i)
- {
- BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
- }
+ for (auto i = this->data.begin(); i != this->data.end(); ++i) {
+ BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
+ }
// check size directly with the storage (repo doesn't have interface yet)
BOOST_CHECK_EQUAL(this->store->size(), static_cast<int64_t>(this->data.size()));
// Read
- for (typename T::InterestContainer::iterator i = this->interests.begin();
- i != this->interests.end(); ++i)
- {
- shared_ptr<ndn::Data> dataTest = this->handle->readData(i->first);
- BOOST_CHECK_EQUAL(*this->handle->readData(i->first), *i->second);
- }
+ for (auto i = this->interests.begin(); i != this->interests.end(); ++i) {
+ std::shared_ptr<ndn::Data> dataTest = this->handle->readData(i->first);
+ BOOST_CHECK_EQUAL(*dataTest, *i->second);
+ }
// Remove items
- for (typename T::RemovalsContainer::iterator i = this->removals.begin();
- i != this->removals.end(); ++i)
- {
- size_t nRemoved = 0;
- BOOST_REQUIRE_NO_THROW(nRemoved = this->handle->deleteData(i->first));
- BOOST_CHECK_EQUAL(nRemoved, i->second);
- }
+ for (auto i = this->removals.begin(); i != this->removals.end(); ++i) {
+ size_t nRemoved = 0;
+ nRemoved = this->handle->deleteData(i->first);
+ BOOST_CHECK_EQUAL(nRemoved, i->second);
+ }
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit/sqlite-handle.cpp b/tests/unit/sqlite-handle.cpp
index ca7c7dd..9cfb0bf 100644
--- a/tests/unit/sqlite-handle.cpp
+++ b/tests/unit/sqlite-handle.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -34,40 +34,40 @@
class Fixture : public SqliteFixture, public Dataset
{
public:
- std::map<int64_t, shared_ptr<Data>> idToDataMap;
+ std::map<Name, std::shared_ptr<Data>> nameToDataMap;
};
BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertReadDelete, T, CommonDatasets, Fixture<T>)
{
BOOST_TEST_CHECKPOINT(T::getName());
- std::vector<int64_t> ids;
+ std::vector<Name> names;
// Insert
- for (typename T::DataContainer::iterator i = this->data.begin();
+ for (auto i = this->data.begin();
i != this->data.end(); ++i) {
- int64_t id = -1;
- BOOST_REQUIRE_NO_THROW(id = this->handle->insert(**i));
-
- this->idToDataMap.insert(std::make_pair(id, *i));
- ids.push_back(id);
+ Name name = Name();
+ this->handle->insert(**i);
+ name = (*i)->getFullName();
+ this->nameToDataMap.insert(std::make_pair(name, *i));
+ names.push_back(name);
}
BOOST_CHECK_EQUAL(this->handle->size(), static_cast<int64_t>(this->data.size()));
std::mt19937 rng{std::random_device{}()};
- std::shuffle(ids.begin(), ids.end(), rng);
+ std::shuffle(names.begin(), names.end(), rng);
// Read (all items should exist)
- for (std::vector<int64_t>::iterator i = ids.begin(); i != ids.end(); ++i) {
- shared_ptr<Data> retrievedData = this->handle->read(*i);
+ for (auto i = names.begin(); i != names.end(); ++i) {
+ std::shared_ptr<Data> retrievedData = this->handle->read(*i);
- BOOST_REQUIRE(this->idToDataMap.count(*i) > 0);
- BOOST_CHECK_EQUAL(*this->idToDataMap[*i], *retrievedData);
+ BOOST_REQUIRE(this->nameToDataMap.count(*i) > 0);
+ BOOST_CHECK_EQUAL(*this->nameToDataMap[*i], *retrievedData);
}
BOOST_CHECK_EQUAL(this->handle->size(), static_cast<int64_t>(this->data.size()));
// Delete
- for (std::vector<int64_t>::iterator i = ids.begin(); i != ids.end(); ++i) {
+ for (auto i = names.begin(); i != names.end(); ++i) {
BOOST_CHECK_EQUAL(this->handle->erase(*i), true);
}
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index f35a42f..48ec17d 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -57,17 +57,16 @@
ip::tcp::endpoint serverEndpoint = *endpoint;
socket.async_connect(serverEndpoint,
- bind(&TcpClient::onSuccessfullConnect, this, _1));
+ std::bind(&TcpClient::onSuccessfullConnect, this, _1));
}
virtual void
onSuccessfullConnect(const boost::system::error_code& error)
{
- if (error)
- {
- BOOST_FAIL("TCP connection aborted");
- return;
- }
+ if (error) {
+ BOOST_FAIL("TCP connection aborted");
+ return;
+ }
}
public:
@@ -86,7 +85,7 @@
, bulkInserter(ioService, *handle)
{
guardEvent = scheduler.scheduleEvent(ndn::time::seconds(2),
- bind(&TcpBulkInsertFixture::fail, this, "Test timed out"));
+ std::bind(&TcpBulkInsertFixture::fail, this, "Test timed out"));
}
virtual void
@@ -102,15 +101,12 @@
// described in http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/overview/implementation.html,
// scatter-gather is limited to at most `min(64,IOV_MAX)` buffers to be transmitted
// in a single operation
- for (typename Dataset::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i) {
+ for (auto i = this->data.begin(); i != this->data.end(); ++i) {
- socket.async_send(boost::asio::buffer((*i)->wireEncode().wire(), (*i)->wireEncode().size()),
- bind(&TcpBulkInsertFixture::onSendFinished, this, _1, false));
+ socket.async_send(boost::asio::buffer((*i)->wireEncode().wire(), (*i)->wireEncode().size()),
+ std::bind(&TcpBulkInsertFixture::onSendFinished, this, _1, false));
}
-
- socket.async_send(boost::asio::buffer(static_cast<const uint8_t*>(0), 0),
- bind(&TcpBulkInsertFixture::onSendFinished, this, _1, true));
+ onSendFinished(error, true);
}
void
@@ -127,7 +123,7 @@
// In case there are some outstanding handlers
// ioService.post(bind(&TcpBulkInsertFixture::stop, this));
scheduler.scheduleEvent(ndn::time::seconds(1),
- bind(&TcpBulkInsertFixture::stop, this));
+ std::bind(&TcpBulkInsertFixture::stop, this));
}
}
@@ -170,9 +166,8 @@
this->ioService.run();
// Read (all items should exist)
- for (typename T::InterestContainer::iterator i = this->interests.begin();
- i != this->interests.end(); ++i) {
- BOOST_CHECK_EQUAL(*this->handle->readData(i->first), *i->second);
+ for (auto i = this->interests.begin(); i != this->interests.end(); ++i) {
+ BOOST_CHECK_EQUAL(*this->handle->readData(i->first), *i->second);
}
}