/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014,  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/sqlite-storage.hpp"

#include "../sqlite-fixture.hpp"
#include "../dataset-fixtures.hpp"

#include <boost/test/unit_test.hpp>

namespace repo {
namespace tests {

BOOST_AUTO_TEST_SUITE(SqliteStorage)

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, CommonDatasets, Fixture<T>)
{
  BOOST_TEST_MESSAGE(T::getName());

  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(), static_cast<int64_t>(this->data.size()));

  std::random_shuffle(ids.begin(), ids.end());

  // 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);

    BOOST_REQUIRE(this->idToDataMap.count(*i) > 0);
    BOOST_CHECK_EQUAL(*this->idToDataMap[*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) {
    BOOST_CHECK_EQUAL(this->handle->erase(*i), true);
  }

  BOOST_CHECK_EQUAL(this->handle->size(), 0);
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace tests
} // namespace repo
