/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2016-2019, Regents of the University of California,
 *                          Colorado State University,
 *                          University Pierre & Marie Curie, Sorbonne University.
 *
 * This file is part of ndn-tools (Named Data Networking Essential Tools).
 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
 *
 * ndn-tools 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.
 *
 * ndn-tools 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
 * ndn-tools, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
 *
 * @author Andrea Tosatto
 */

#ifndef NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
#define NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP

#include "tools/chunks/catchunks/discover-version.hpp"

#include "tests/test-common.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>

namespace ndn {
namespace chunks {
namespace tests {

using namespace ndn::tests;

class DiscoverVersionFixture : public UnitTestTimeFixture, virtual protected Options
{
public:
  DiscoverVersionFixture(const Options& options)
    : Options(options)
    , face(io)
    , name("/ndn/chunks/test")
    , discoveredVersion(0)
    , isDiscoveryFinished(false)
  {
  }

  virtual
  ~DiscoverVersionFixture() = default;

protected:
  void
  setDiscover(unique_ptr<DiscoverVersion> disc)
  {
    discover = std::move(disc);
    discover->onDiscoverySuccess.connect(bind(&DiscoverVersionFixture::onSuccess, this, _1));
    discover->onDiscoveryFailure.connect(bind(&DiscoverVersionFixture::onFailure, this, _1));
  }

  shared_ptr<Data>
  makeDataWithVersion(uint64_t version) const
  {
    auto data = make_shared<Data>(Name(name).appendVersion(version).appendSegment(0));
    data->setFinalBlock(name::Component::fromSegment(0));
    return signData(data);
  }

  static Options
  makeOptions()
  {
    Options options;
    options.isVerbose = false;
    options.interestLifetime = time::seconds(1);
    options.maxRetriesOnTimeoutOrNack = 15;
    return options;
  }

  virtual void
  onSuccess(const Name& versionedName)
  {
    isDiscoveryFinished = true;

    BOOST_REQUIRE(!versionedName.empty() && versionedName[-1].isVersion());
    discoveredVersion = versionedName[-1].toVersion();
  }

  virtual void
  onFailure(const std::string& reason)
  {
    isDiscoveryFinished = true;
  }

protected:
  boost::asio::io_service io;
  util::DummyClientFace face;
  Name name;
  unique_ptr<DiscoverVersion> discover;
  uint64_t discoveredVersion;
  bool isDiscoveryFinished;
};

} // namespace tests
} // namespace chunks
} // namespace ndn

#endif // NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
