tests: Small refactoring of test cases

Change-Id: I09c372c0c9c8220b3408fafbb41c43e5c216884f
Refs: #1695, #1434
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