tests: Small refactoring of test cases
Change-Id: I09c372c0c9c8220b3408fafbb41c43e5c216884f
Refs: #1695, #1434
diff --git a/src/handles/base-handle.hpp b/src/handles/base-handle.hpp
index 3048856..9427356 100644
--- a/src/handles/base-handle.hpp
+++ b/src/handles/base-handle.hpp
@@ -74,13 +74,13 @@
{
return m_scheduler;
}
-/*
- inline RepoStorage&
- getStoreIndex()
- {
- return m_storeindex;
- }
-*/
+
+ // inline RepoStorage&
+ // getStoreIndex()
+ // {
+ // return m_storeindex;
+ // }
+
uint64_t
generateProcessId();
diff --git a/src/handles/delete-handle.hpp b/src/handles/delete-handle.hpp
index 4b0ac85..91ff244 100644
--- a/src/handles/delete-handle.hpp
+++ b/src/handles/delete-handle.hpp
@@ -22,6 +22,7 @@
#include "base-handle.hpp"
#include <ndn-cxx/security/validator-config.hpp>
+
namespace repo {
using std::vector;
@@ -61,8 +62,8 @@
onValidationFailed(const shared_ptr<const Interest>& interest, const string& reason);
/**
- * @todo delete check has not been realized due to the while loop of segmented data deletion.
- */
+ * @todo delete check has not been realized due to the while loop of segmented data deletion.
+ */
void
onCheckInterest(const Name& prefix, const Interest& interest);
diff --git a/src/handles/write-handle.hpp b/src/handles/write-handle.hpp
index 6d42630..48bd0e4 100644
--- a/src/handles/write-handle.hpp
+++ b/src/handles/write-handle.hpp
@@ -21,9 +21,9 @@
#define REPO_HANDLES_WRITE_HANDLE_HPP
#include "base-handle.hpp"
-//#include <ndn-cxx/security/signature-sha256.hpp>
-#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
+
#include <ndn-cxx/security/validator-config.hpp>
+
#include <queue>
namespace repo {
diff --git a/src/storage/index.cpp b/src/storage/index.cpp
index d2472fb..b141b51 100644
--- a/src/storage/index.cpp
+++ b/src/storage/index.cpp
@@ -100,7 +100,7 @@
}
else
{
- return std::pair<int64_t,Name>();
+ return std::make_pair(0, Name());
}
}
@@ -114,7 +114,7 @@
}
else
{
- return std::pair<int64_t,Name>();
+ return std::make_pair(0, Name());
}
}
@@ -138,7 +138,7 @@
}
else
{
- return std::pair<int64_t,Name>();
+ return std::make_pair(0, Name());
}
}
@@ -185,7 +185,7 @@
it != m_skipList.end(); ++it)
{
if (!interest.getName().isPrefixOf(it->getName()))
- return std::pair<int64_t,Name>();
+ return std::make_pair(0, Name());
if (matchesSimpleSelectors(interest, hash, (*it)))
return std::make_pair(it->getId(), it->getName());
}
@@ -194,7 +194,7 @@
{
IndexSkipList::const_iterator boundary = m_skipList.lower_bound(interest.getName());
if (boundary == m_skipList.end() || !interest.getName().isPrefixOf(boundary->getName()))
- return std::pair<int64_t,Name>();
+ return std::make_pair(0, Name());
Name successor = interest.getName().getSuccessor();
IndexSkipList::const_iterator last = interest.getName().size() == 0 ?
m_skipList.end() : m_skipList.lower_bound(interest.getName().getSuccessor());
@@ -210,7 +210,7 @@
return std::make_pair(prev->getId(), prev->getName());
}
else
- return std::pair<int64_t,Name>();
+ return std::make_pair(0, Name());
}
IndexSkipList::const_iterator first =
m_skipList.lower_bound(prev->getName().getPrefix(interest.getName().size() + 1));
@@ -223,7 +223,7 @@
last = first;
}
}
- return std::pair<int64_t,Name>();
+ return std::make_pair(0, Name());
}
Index::Entry::Entry(const Data& data, const int64_t id)
diff --git a/tests/dataset-fixtures.hpp b/tests/dataset-fixtures.hpp
index f306948..a957ee0 100644
--- a/tests/dataset-fixtures.hpp
+++ b/tests/dataset-fixtures.hpp
@@ -27,66 +27,74 @@
namespace repo {
namespace tests {
-static inline ndn::shared_ptr<ndn::Data>
-createData(const ndn::Name& name)
-{
- static ndn::KeyChain keyChain;
- static std::vector<uint8_t> content(1500, '-');
-
- ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
- data->setName(name);
- data->setContent(&content[0], content.size());
- keyChain.sign(*data);
-
- return data;
-}
-
class DatasetBase
{
public:
+ class Error : public std::runtime_error
+ {
+ public:
+ explicit
+ Error(const std::string& what)
+ : std::runtime_error(what)
+ {
+ }
+ };
+
typedef std::list<ndn::shared_ptr<ndn::Data> > DataContainer;
DataContainer data;
typedef std::list<std::pair<ndn::Interest, ndn::shared_ptr<ndn::Data> > > InterestContainer;
InterestContainer interests;
- typedef std::list<std::pair<ndn::Interest, int > > InterestIdContainer;
- InterestIdContainer interestsSelectors, interestDeleteCount;
+ typedef std::list<std::pair<ndn::Interest, size_t > > RemovalsContainer;
+ RemovalsContainer removals;
- typedef std::list<std::pair<int, ndn::shared_ptr<ndn::Data> > > IdContainer;
- IdContainer ids, insert;
-
- struct DataSetNameCompare
+protected:
+ ndn::shared_ptr<ndn::Data>
+ createData(const ndn::Name& name)
{
- bool operator()(const ndn::Name& a, const ndn::Name& b) const
- {
- return a < b;
- }
- };
+ if (map.count(name) > 0)
+ return map[name];
- struct DataSetDataCompare
+ static ndn::KeyChain keyChain;
+ static std::vector<uint8_t> content(1500, '-');
+
+ ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
+ data->setName(name);
+ data->setContent(&content[0], content.size());
+ keyChain.sign(*data);
+
+ map.insert(std::make_pair(name, data));
+ return data;
+ }
+
+ ndn::shared_ptr<ndn::Data>
+ getData(const ndn::Name& name)
{
- bool operator()(const Data& a, const Data& b) const
- {
- return a.getName() < b.getName();
- }
- };
+ if (map.count(name) > 0)
+ return map[name];
+ else
+ throw Error("Data with name " + name.toUri() + " is not found");
+ }
+
+private:
+ std::map<Name, shared_ptr<Data> > map;
};
template<size_t N>
-class BaseSmoketestFixture : public DatasetBase
+class SamePrefixDataset : public DatasetBase
{
public:
static const std::string&
getName()
{
- static std::string name = "BaseSmoketest";
+ static std::string name = "SamePrefixDataset";
return name;
}
- BaseSmoketestFixture()
+ SamePrefixDataset()
{
ndn::Name baseName("/x/y/z/test/1");
for (size_t i = 0; i < N; i++) {
@@ -96,54 +104,47 @@
this->data.push_back(data);
this->interests.push_back(std::make_pair(Interest(name), data));
- this->ids.push_back(std::make_pair(i+1, data));
}
}
};
-class BaseTestFixture : public DatasetBase
+class BasicDataset : public DatasetBase
{
public:
static const std::string&
getName()
{
- static std::string name = "BaseTest";
+ static std::string name = "BasicDataset";
return name;
}
- BaseTestFixture()
+ BasicDataset()
{
this->data.push_back(createData("/a"));
- this->interests.push_back(std::make_pair(Interest("/a"), this->data.back()));
- this->ids.push_back(std::make_pair(1, this->data.back()));
-
this->data.push_back(createData("/a/b"));
- this->interests.push_back(std::make_pair(Interest("/a/b"), this->data.back()));
- this->ids.push_back(std::make_pair(2, this->data.back()));
-
this->data.push_back(createData("/a/b/c"));
- this->interests.push_back(std::make_pair(Interest("/a/b/c"), this->data.back()));
- this->ids.push_back(std::make_pair(3, this->data.back()));
-
this->data.push_back(createData("/a/b/c/d"));
- this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), this->data.back()));
- this->ids.push_back(std::make_pair(4, this->data.back()));
+
+ 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/b/c/d"), getData("/a/b/c/d")));
}
};
//Fetch by prefix is useless due to the database is fetched by id
-class FetchByPrefixTestFixture : public DatasetBase
+class FetchByPrefixDataset : public DatasetBase
{
public:
static const std::string&
getName()
{
- static std::string name = "FetchByPrefix";
+ static std::string name = "FetchByPrefixDataset";
return name;
}
- FetchByPrefixTestFixture()
+ FetchByPrefixDataset()
{
this->data.push_back(createData("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z"));
this->interests.push_back(std::make_pair(Interest("/a"),
@@ -207,17 +208,17 @@
};
-class SelectorTestFixture : public DatasetBase
+class BasicChildSelectorDataset : public DatasetBase
{
public:
static const std::string&
getName()
{
- static std::string name = "SelectorTest";
+ static std::string name = "BasicChildSelectorDataset";
return name;
}
- SelectorTestFixture()
+ BasicChildSelectorDataset()
{
this->data.push_back(createData("/a/1"));
this->data.push_back(createData("/b/1"));
@@ -239,111 +240,8 @@
}
};
-class IndexTestFixture : public DatasetBase
-{
-public:
- static const std::string&
- getName()
- {
- static std::string name = "IndexTest";
- return name;
- }
- IndexTestFixture()
- {
- this->data.push_back(createData("/a/b/c"));
- this->interests.push_back(std::make_pair(Interest("/a/b/c"), this->data.back()));
- this->ids.push_back(std::make_pair(1, this->data.back()));
- this->insert.push_back(std::make_pair(1, this->data.back()));
-
- this->data.push_back(createData("/a/b/d/1"));
- this->interests.push_back(std::make_pair(Interest("/a/b/d"), this->data.back()));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/1"), this->data.back()));
- this->ids.push_back(std::make_pair(2, this->data.back()));
- this->ids.push_back(std::make_pair(2, this->data.back()));
- this->insert.push_back(std::make_pair(2, this->data.back()));
-
- this->data.push_back(createData("/a/b/d/2"));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/2"), this->data.back()));
- this->ids.push_back(std::make_pair(3, this->data.back()));
- this->insert.push_back(std::make_pair(3, this->data.back()));
-
- this->data.push_back(createData("/a/b/d/3"));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/3"), this->data.back()));
- this->ids.push_back(std::make_pair(4, this->data.back()));
- this->insert.push_back(std::make_pair(4, this->data.back()));
-
- this->data.push_back(createData("/a/b/d/4/I"));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/4/I"), this->data.back()));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/4"), this->data.back()));
- this->ids.push_back(std::make_pair(5, this->data.back()));
- this->ids.push_back(std::make_pair(5, this->data.back()));
- this->insert.push_back(std::make_pair(5, this->data.back()));
-
- this->data.push_back(createData("/a/b/d/4"));
- // this->ids.push_back(std::make_pair(7, this->data.back()));
- this->insert.push_back(std::make_pair(6, this->data.back()));
-
- this->data.push_back(createData("/a/b/d"));
- // this->ids.push_back(std::make_pair(8, this->data.back()));
- this->insert.push_back(std::make_pair(7, this->data.back()));
-
- this->data.push_back(createData("/a/b/e/1"));
- this->interests.push_back(std::make_pair(Interest("/a/b/e"), this->data.back()));
- this->interests.push_back(std::make_pair(Interest("/a/b/e/1"), this->data.back()));
- this->ids.push_back(std::make_pair(8, this->data.back()));
- this->ids.push_back(std::make_pair(8, this->data.back()));
- this->insert.push_back(std::make_pair(8, this->data.back()));
-
- Selectors selector_keylocator;
- ndn::SignatureSha256WithRsa rsaSignature(this->data.back()->getSignature());
-
- this->data.push_back(createData("/a/b/e"));
- this->ids.push_back(std::make_pair(9, this->data.back()));
- this->insert.push_back(std::make_pair(9, this->data.back()));
-
- Selectors selector;
- selector.setMinSuffixComponents(3);
- this->interestsSelectors.push_back(std::make_pair(Interest("/a/b/d").setSelectors(selector),
- 5));
-
- selector.setMinSuffixComponents(-1);
- selector.setChildSelector(0);
- this->interestsSelectors.push_back(std::make_pair(Interest("/a/b/d").setSelectors(selector),
- 2));
-
- selector.setMinSuffixComponents(2);
- this->interestsSelectors.push_back(std::make_pair(Interest("/a/b/d").setSelectors(selector),
- 2));
-
- selector.setChildSelector(1);
- this->interestsSelectors.push_back(std::make_pair(Interest("/a/b/d").setSelectors(selector),
- 6));
-
- selector.setChildSelector(-1);
- selector.setMaxSuffixComponents(2);
- this->interestsSelectors.push_back(std::make_pair(Interest("/a/b").setSelectors(selector),
- 1));
-
- ndn::name::Component from("3");
- ndn::name::Component to("4");
- Exclude exclude;
- exclude.excludeRange(from, to);
- selector.setChildSelector(1);
- selector.setExclude(exclude);
- this->interestsSelectors.push_back(std::make_pair(Interest("/a/b/d").setSelectors(selector),
- 3));
-
-
- KeyLocator keylocate = rsaSignature.getKeyLocator();
- // std::cout<<"keylocator from data = "<<keylocate.wireEncode()<<std::endl;
- selector_keylocator.setPublisherPublicKeyLocator(keylocate);
- this->interestsSelectors.push_back(std::make_pair
- (Interest("/a/b/e").setSelectors(selector_keylocator), 9));
- }
-};
-
-class ChildSelectorTestFixture : public DatasetBase
+class ExtendedChildSelectorDataset : public DatasetBase
{
public:
static const std::string&
@@ -353,132 +251,142 @@
return name;
}
- ChildSelectorTestFixture()
+ ExtendedChildSelectorDataset()
{
this->data.push_back(createData("/a/b/1"));
- this->insert.push_back(std::make_pair(1, this->data.back()));
+
this->data.push_back(createData("/a/c/1"));
- this->insert.push_back(std::make_pair(2, this->data.back()));
+ 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->insert.push_back(std::make_pair(3, this->data.back()));
this->data.push_back(createData("/b"));
- this->insert.push_back(std::make_pair(4, this->data.back()));
-
- Selectors selector;
- selector.setChildSelector(1);
- this->interestsSelectors.push_back(std::make_pair(Interest("/a").setSelectors(selector),
- 2));
}
};
-class StorageFixture : public DatasetBase
+
+class ComplexSelectorsDataset : public DatasetBase
{
public:
- static const std::string&
- getName()
- {
- static std::string name = "storage";
- return name;
- }
+ static const std::string&
+ getName()
+ {
+ static std::string name = "ComplexSelectorsDataset";
+ return name;
+ }
- StorageFixture()
- {
- this->data.push_back(createData("/a/b/c"));
- this->interests.push_back(std::make_pair(Interest("/a/b/c"), this->data.back()));
- this->ids.push_back(std::make_pair(1, this->data.back()));
- this->insert.push_back(std::make_pair(1, this->data.back()));
+ std::map<std::string, shared_ptr<Data> > map;
- this->data.push_back(createData("/a/b/d/1"));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/1"), this->data.back()));
- this->ids.push_back(std::make_pair(2, this->data.back()));
- this->insert.push_back(std::make_pair(2, this->data.back()));
+ void
+ addData(const std::string& name)
+ {
+ }
- this->data.push_back(createData("/a/b/d/2"));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/2"), this->data.back()));
- this->ids.push_back(std::make_pair(3, this->data.back()));
- this->insert.push_back(std::make_pair(3, this->data.back()));
+ 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"));
- this->data.push_back(createData("/a/b/d/3"));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/3"), this->data.back()));
- this->ids.push_back(std::make_pair(4, this->data.back()));
- this->insert.push_back(std::make_pair(4, this->data.back()));
+ // 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/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/e/1"), this->getData("/a/b/e/1")));
- this->data.push_back(createData("/a/b/d/4"));
- this->ids.push_back(std::make_pair(5, this->data.back()));
- this->interests.push_back(std::make_pair(Interest("/a/b/d/4"), this->data.back()));
- this->insert.push_back(std::make_pair(5, this->data.back()));
+ // Complex selects
+ this->interests.push_back(std::make_pair(Interest("/a/b")
+ .setSelectors(Selectors()
+ .setMinSuffixComponents(2)
+ .setMaxSuffixComponents(2)),
+ this->getData("/a/b/c")));
- this->data.push_back(createData("/a/b/e/1"));
- this->interests.push_back(std::make_pair(Interest("/a/b/e/1"), this->data.back()));
- this->ids.push_back(std::make_pair(6, this->data.back()));
- this->insert.push_back(std::make_pair(6, this->data.back()));
+ this->interests.push_back(std::make_pair(Interest("/a/b/d")
+ .setSelectors(Selectors()
+ .setMinSuffixComponents(-1)
+ .setChildSelector(0)),
+ this->getData("/a/b/d/1")));
- Selectors selector_keylocator;
- ndn::SignatureSha256WithRsa rsaSignature(this->data.back()->getSignature());
+ this->interests.push_back(std::make_pair(Interest("/a/b/d")
+ .setSelectors(Selectors()
+ .setMinSuffixComponents(2)
+ .setChildSelector(0)),
+ this->getData("/a/b/d/1")));
- this->data.push_back(createData("/a/b/e/2"));
- this->ids.push_back(std::make_pair(7, this->data.back()));
- this->interests.push_back(std::make_pair(Interest("/a/b/e/2"), this->data.back()));
- this->insert.push_back(std::make_pair(7, this->data.back()));
-
- Selectors selector;
- selector.setChildSelector(0);
- this->interestsSelectors.push_back(std::make_pair
- (Interest("/a/b/d").setSelectors(selector), 2));
- this->interestDeleteCount.push_back(std::make_pair
- (Interest("/a/b/d").setSelectors(selector), 4));
+ 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")));
- selector.setChildSelector(1);
- this->interestsSelectors.push_back(std::make_pair
- (Interest("/a/b/d").setSelectors(selector), 5));
- this->interestDeleteCount.push_back(std::make_pair
- (Interest("/a/b/d").setSelectors(selector), 0));
+ this->interests.push_back(std::make_pair(Interest("/a/b/d")
+ .setSelectors(Selectors().setMinSuffixComponents(3)),
+ this->getData("/a/b/d/4/I")));
- selector.setChildSelector(-1);
- selector.setMaxSuffixComponents(2);
- this->interestsSelectors.push_back(std::make_pair
- (Interest("/a/b").setSelectors(selector), 1));
- this->interestDeleteCount.push_back(std::make_pair
- (Interest("/a/b").setSelectors(selector), 1));
+ // 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/I")));
- ndn::name::Component from("3");
- ndn::name::Component to("4");
- Exclude exclude;
- exclude.excludeRange(from, to);
- selector.setChildSelector(1);
- selector.setExclude(exclude);
- this->interestsSelectors.push_back(std::make_pair
- (Interest("/a/b/d").setSelectors(selector), 3));
- this->interestDeleteCount.push_back(std::make_pair
- (Interest("/a/b/d").setSelectors(selector), 0));
+ // 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")));
+ // 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/1")));
- KeyLocator keylocate = rsaSignature.getKeyLocator();
- selector_keylocator.setPublisherPublicKeyLocator(keylocate);
- this->interestsSelectors.push_back(std::make_pair
- (Interest("/a/b/e").setSelectors(selector_keylocator),
- 6));
- this->interestDeleteCount
- .push_back(std::make_pair(Interest("/a/b/e")
- .setSelectors(selector_keylocator), 2));
+ // 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< BaseTestFixture,
- FetchByPrefixTestFixture,
- SelectorTestFixture,
- BaseSmoketestFixture<10> > DatasetFixtures;
-typedef boost::mpl::vector< BaseTestFixture,
- BaseSmoketestFixture<10> > DatasetFixtures_Sqlite;
+typedef boost::mpl::vector< BasicDataset,
+ FetchByPrefixDataset,
+ BasicChildSelectorDataset,
+ ExtendedChildSelectorDataset,
+ SamePrefixDataset<10>,
+ SamePrefixDataset<100> > CommonDatasets;
-typedef boost::mpl::vector<IndexTestFixture> DatasetFixtures_Index;
-typedef boost::mpl::vector<StorageFixture> DatasetFixtures_Storage;
-typedef boost::mpl::vector<ChildSelectorTestFixture> DatasetFixtures_Selector;
} // namespace tests
} // namespace repo
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index 5fc669e..10775f7 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -303,7 +303,13 @@
}
}
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, DatasetFixtures, Fixture<T>)
+typedef boost::mpl::vector< BasicDataset,
+ FetchByPrefixDataset,
+ BasicChildSelectorDataset,
+ ExtendedChildSelectorDataset,
+ SamePrefixDataset<10> > Datasets;
+
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, Datasets, Fixture<T>)
{
this->generateDefaultCertificateFile();
this->validator.load("tests/integrated/insert-delete-validator-config.conf");
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index c198871..d4eba2e 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -116,15 +116,21 @@
};
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(Read, T, DatasetFixtures, BasicInterestReadFixture<T>)
+typedef boost::mpl::vector< BasicDataset,
+ FetchByPrefixDataset,
+ BasicChildSelectorDataset,
+ ExtendedChildSelectorDataset,
+ SamePrefixDataset<10> > Datasets;
+
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(Read, T, Datasets, BasicInterestReadFixture<T>)
{
// Insert dataset
- // for (typename T::DataContainer::iterator i = this->data.begin();
- // i != this->data.end(); ++i) {
- // BOOST_CHECK_EQUAL(this->handle.insertData(**i), true);
- // }
+ // for (typename T::DataContainer::iterator i = this->data.begin();
+ // i != this->data.end(); ++i) {
+ // BOOST_CHECK_EQUAL(this->handle.insertData(**i), true);
+ // }
-// BOOST_CHECK_EQUAL(this->handle.size(), this->data.size());
+ // BOOST_CHECK_EQUAL(this->handle.size(), this->data.size());
this->startListen();
this->scheduler.scheduleEvent(ndn::time::seconds(0),
diff --git a/tests/unit/index.cpp b/tests/unit/index.cpp
index a7ea5e4..49af9fe 100644
--- a/tests/unit/index.cpp
+++ b/tests/unit/index.cpp
@@ -28,60 +28,7 @@
namespace repo {
namespace tests {
-BOOST_AUTO_TEST_SUITE(TestIndex)
-
-template<class Dataset>
-class Fixture : public Dataset
-{
-};
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(IndexGeneralTest, T, DatasetFixtures_Storage, Fixture<T>)
-{
- Index index(65535);
- for (typename T::IdContainer::iterator i = this->insert.begin();
- i != this->insert.end(); ++i)
- {
- BOOST_CHECK_EQUAL(index.insert(*i->second, i->first), true);
- }
- BOOST_CHECK_EQUAL(index.size(), 7);
-
- typename T::IdContainer::iterator id = this->ids.begin();
- for (typename T::InterestContainer::iterator i = this->interests.begin();
- i != this->interests.end(); ++i)
- {
- vector<std::pair<int, ndn::Name> > id_names;
- BOOST_CHECK_EQUAL(index.find(i->first.getName()).first, id->first);
- BOOST_CHECK_EQUAL(index.hasData(*i->second), true);
- ++id;
- }
-
- for (typename T::InterestIdContainer::iterator i = this->interestsSelectors.begin();
- i != this->interestsSelectors.end(); ++i)
- {
-
- BOOST_CHECK_EQUAL(index.find(i->first).first, i->second);
- ndn::Name name = index.find(i->first).second;
- BOOST_CHECK_EQUAL(index.erase(name), true);
- }
- BOOST_CHECK_EQUAL(index.size(), 2);
-}
-
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(IndexTestSelector, T, DatasetFixtures_Selector, Fixture<T>)
-{
- Index index(65535);
- for (typename T::IdContainer::iterator i = this->insert.begin();
- i != this->insert.end(); ++i)
- BOOST_CHECK_EQUAL(index.insert(*i->second, i->first), true);
- for (typename T::InterestIdContainer::iterator i = this->interestsSelectors.begin();
- i != this->interestsSelectors.end(); ++i)
- {
- BOOST_CHECK_EQUAL(index.find(i->first).first, i->second);
- }
-
-
-}
-
+BOOST_AUTO_TEST_SUITE(Index)
class FindFixture
{
@@ -116,7 +63,7 @@
}
protected:
- Index m_index;
+ repo::Index m_index;
KeyChain m_keyChain;
shared_ptr<Interest> m_interest;
};
@@ -418,6 +365,64 @@
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
diff --git a/tests/unit/repo-storage.cpp b/tests/unit/repo-storage.cpp
index 41f9930..5058f08 100644
--- a/tests/unit/repo-storage.cpp
+++ b/tests/unit/repo-storage.cpp
@@ -30,67 +30,47 @@
namespace tests {
BOOST_AUTO_TEST_SUITE(RepoStorage)
+
template<class Dataset>
class Fixture : public Dataset, public RepoStorageFixture
{
};
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(NdnNameSkipList, T, DatasetFixtures_Storage, Fixture<T>)
+// Combine CommonDatasets with ComplexSelectorDataset
+typedef boost::mpl::push_back<CommonDatasets,
+ ComplexSelectorsDataset>::type Datasets;
+
+
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, Datasets, Fixture<T>)
{
- //Insert
+ BOOST_TEST_MESSAGE(T::getName());
+
+ // Insert data into repo
for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i)
+ i != this->data.end(); ++i)
{
BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
}
-
- //Read
+
+ // check size directly with the storage (repo doesn't have interface yet)
+ BOOST_CHECK_EQUAL(this->store->size(), this->data.size());
+
+ // Read
for (typename T::InterestContainer::iterator i = this->interests.begin();
- i != this->interests.end(); ++i)
+ 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);
- // int rc = memcmp(dataTest->getContent().value(),
- // i->second->getContent().value(), sizeof(i->second->getContent().value()));
- //BOOST_CHECK_EQUAL(rc, 0);
- BOOST_CHECK_EQUAL(this->handle->deleteData(i->first.getName()), 1);
}
-
- //Insert
- for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i)
+
+ // Remove items
+ for (typename T::RemovalsContainer::iterator i = this->removals.begin();
+ i != this->removals.end(); ++i)
{
- BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
+ size_t nRemoved = 0;
+ BOOST_REQUIRE_NO_THROW(nRemoved = this->handle->deleteData(i->first));
+ BOOST_CHECK_EQUAL(nRemoved, i->second);
}
-
- //Erase
- for (typename T::InterestIdContainer::iterator i = this->interestDeleteCount.begin();
- i != this->interestDeleteCount.end(); ++i)
- {
- BOOST_CHECK_EQUAL(this->handle->deleteData(i->first), i->second);
- }
-}
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(Index, T, DatasetFixtures_Storage, Fixture<T>)
-{
-
- for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i)
- {
- BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
- }
- ndn::Interest interest("/a");
- ndn::Interest interest1("/a/b/d/1");
-
- BOOST_CHECK_EQUAL(this->handle->deleteData(interest), 7);
-
-
- for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i)
- {
- BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
- }
- BOOST_CHECK_EQUAL(this->handle->deleteData(interest.getName()), 7);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit/skiplist.cpp b/tests/unit/skiplist.cpp
index 34083d6..5bbb0ff 100644
--- a/tests/unit/skiplist.cpp
+++ b/tests/unit/skiplist.cpp
@@ -36,27 +36,7 @@
{
};
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(NdnNameSkipList, T, DatasetFixtures, Fixture<T>)
-{
- repo::SkipList<ndn::Name, typename T::DataSetNameCompare> skipList;
- //Insert
- for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i) {
- skipList.insert((*i)->getName());
- }
-
- //find and erase
- for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i) {
- typename repo::SkipList<ndn::Name, typename T::DataSetNameCompare>::iterator findIterator =
- skipList.find((*i)->getName());
- skipList.erase(findIterator);
- }
-
- //@todo test lower_bound
-}
-
-BOOST_AUTO_TEST_CASE(IntGtSkipList)
+BOOST_AUTO_TEST_CASE(Correctness)
{
typedef repo::SkipList<int, std::greater<int> > IntGtSkipList;
IntGtSkipList sl;
@@ -153,6 +133,56 @@
BOOST_CHECK(it3 == sl.end());
}
+class Item : public ndn::Name
+{
+public:
+ explicit
+ Item(const ndn::Name& name = "")
+ : ndn::Name(name)
+ , randomValue(ndn::random::generateWord64())
+ {
+ }
+
+public:
+ uint64_t randomValue;
+};
+
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, CommonDatasets, Fixture<T>)
+{
+ BOOST_TEST_MESSAGE(T::getName());
+ typedef repo::SkipList<Item, std::less<Item> > SkipList;
+ SkipList skipList;
+
+ std::vector<Item> items;
+ std::set<ndn::Name> names;
+ for (typename T::DataContainer::iterator i = this->data.begin();
+ i != this->data.end(); ++i) {
+ std::pair<std::set<ndn::Name>::iterator, bool> ret = names.insert((*i)->getName());
+ if (ret.second) {
+ items.push_back(Item((*i)->getName()));
+ }
+ }
+
+ // Insert
+ for (std::vector<Item>::iterator i = items.begin(); i != items.end(); ++i) {
+ skipList.insert(*i);
+ }
+
+ BOOST_CHECK_EQUAL(items.size(), skipList.size());
+
+ // Randomize items
+ std::random_shuffle(items.begin(), items.end());
+
+ // Find items and check if the right item is found
+ for (std::vector<Item>::iterator i = items.begin(); i != items.end(); ++i) {
+ SkipList::iterator item = skipList.find(*i);
+ BOOST_CHECK(item != skipList.end());
+
+ BOOST_CHECK_EQUAL(static_cast<const Name&>(*item), static_cast<const Name&>(*i));
+ BOOST_CHECK_EQUAL(item->randomValue, i->randomValue);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
diff --git a/tests/unit/sqlite-handle.cpp b/tests/unit/sqlite-handle.cpp
index 17a4832..59c5977 100644
--- a/tests/unit/sqlite-handle.cpp
+++ b/tests/unit/sqlite-handle.cpp
@@ -32,42 +32,45 @@
template<class Dataset>
class Fixture : public SqliteFixture, public Dataset
{
+public:
+ std::map<int64_t, shared_ptr<Data> > idToDataMap;
};
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertReadDelete, T, DatasetFixtures_Sqlite, Fixture<T>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertReadDelete, T, CommonDatasets, Fixture<T>)
{
BOOST_TEST_MESSAGE(T::getName());
- // Insert
- for (typename T::IdContainer::iterator i = this->ids.begin();
- i != this->ids.end(); ++i) {
- BOOST_CHECK_EQUAL(this->handle->insert(*i->second), i->first);
- }
+ std::vector<int64_t> ids;
+ // Insert
+ for (typename T::DataContainer::iterator 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);
+ }
BOOST_CHECK_EQUAL(this->handle->size(), this->data.size());
+ std::random_shuffle(ids.begin(), ids.end());
+
// Read (all items should exist)
- for (typename T::IdContainer::iterator i = this->ids.begin();
- i != this->ids.end(); ++i) {
- shared_ptr<Data> retrievedData = this->handle->read(i->first);
- BOOST_CHECK_EQUAL(*retrievedData, *i->second);
+ for (std::vector<int64_t>::iterator i = ids.begin(); i != ids.end(); ++i) {
+ shared_ptr<Data> retrievedData = this->handle->read(*i);
+
+ BOOST_REQUIRE(this->idToDataMap.count(*i) > 0);
+ BOOST_CHECK_EQUAL(*this->idToDataMap[*i], *retrievedData);
}
+ BOOST_CHECK_EQUAL(this->handle->size(), this->data.size());
// Delete
- for (typename T::IdContainer::iterator i = this->ids.begin();
- i != this->ids.end(); ++i) {
- //std::cout<<"remove name = "<<i->second->getName()<<std::endl;
- BOOST_CHECK_EQUAL(this->handle->erase(i->first), true);
+ for (std::vector<int64_t>::iterator i = ids.begin(); i != ids.end(); ++i) {
+ BOOST_CHECK_EQUAL(this->handle->erase(*i), true);
}
- /*
- // Read (none of the items should exist)
- for (typename T::InterestContainer::iterator i = this->interests.begin();
- i != this->interests.end(); ++i) {
- ndn::Data retrievedData;
- BOOST_REQUIRE_EQUAL(this->handle->readData(i->first, retrievedData), false);
- }*/
-
+ BOOST_CHECK_EQUAL(this->handle->size(), 0);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index 67a541a..6d911f7 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -153,11 +153,9 @@
};
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(BulkInsertAndRead, T, DatasetFixtures_Storage,
- TcpBulkInsertFixture<T>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(BulkInsertAndRead, T, CommonDatasets, TcpBulkInsertFixture<T>)
{
BOOST_TEST_MESSAGE(T::getName());
- // BOOST_CHECK_EQUAL(this->handle->size(), 1);
// start bulk inserter
this->bulkInserter.listen("localhost", "17376");
@@ -168,16 +166,10 @@
// actually run the test
this->ioService.run();
-// BOOST_CHECK_EQUAL(this->handle->size(), this->data.size());
-
// 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);
- // int rc = memcmp(retrievedData->getContent().value(),
- // i->second->getContent().value(), sizeof(i->second->getContent().value()));
- //BOOST_CHECK_EQUAL(rc, 0);
-
}
}