/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012-2017 University of California, Los Angeles
 *
 * This file is part of ChronoSync, synchronization library for distributed realtime
 * applications for NDN.
 *
 * ChronoSync 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.
 *
 * ChronoSync 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
 * ChronoSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "interest-table.hpp"

#include <unistd.h>

#include "../unit-test-time-fixture.hpp"
#include "boost-test.hpp"

namespace chronosync {
namespace test {

class InterestTableFixture : public ndn::tests::UnitTestTimeFixture
{
public:
  InterestTableFixture()
  {
    uint8_t origin[4] = {0x01, 0x02, 0x03, 0x04};
    Name prefix("/test/prefix");

    Name interestName1;
    digest1 = ndn::crypto::computeSha256Digest(origin, 1);
    interestName1.append(prefix).append(name::Component(digest1));
    interest1 = make_shared<Interest>(interestName1);
    interest1->setInterestLifetime(time::milliseconds(100));

    Name interestName2;
    digest2 = ndn::crypto::computeSha256Digest(origin, 2);
    interestName2.append(prefix).append(name::Component(digest2));
    interest2 = make_shared<Interest>(interestName2);
    interest2->setInterestLifetime(time::milliseconds(100));

    Name interestName3;
    digest3 = ndn::crypto::computeSha256Digest(origin, 3);
    interestName3.append(prefix).append(name::Component(digest3));
    interest3 = make_shared<Interest>(interestName3);
    interest3->setInterestLifetime(time::milliseconds(100));
  }

  void
  insert(InterestTable& table,
         shared_ptr<Interest> interest,
         ndn::ConstBufferPtr digest)
  {
    table.insert(interest, digest);
  }

  shared_ptr<Interest> interest1;
  ndn::ConstBufferPtr digest1;

  shared_ptr<Interest> interest2;
  ndn::ConstBufferPtr digest2;

  shared_ptr<Interest> interest3;
  ndn::ConstBufferPtr digest3;
};

BOOST_FIXTURE_TEST_SUITE(InterestTableTest, InterestTableFixture)

BOOST_AUTO_TEST_CASE(Container)
{
  InterestContainer container;

  container.insert(make_shared<UnsatisfiedInterest>(interest1, digest1));
  container.insert(make_shared<UnsatisfiedInterest>(interest2, digest2));
  container.insert(make_shared<UnsatisfiedInterest>(interest3, digest3));

  BOOST_CHECK_EQUAL(container.size(), 3);
  BOOST_CHECK(container.find(digest3) != container.end());
  BOOST_CHECK(container.find(digest2) != container.end());
  BOOST_CHECK(container.find(digest1) != container.end());
}

BOOST_AUTO_TEST_CASE(Basic)
{
  InterestTable table(io);

  table.insert(interest1, digest1);
  table.insert(interest2, digest2);
  table.insert(interest3, digest3);

  BOOST_CHECK_EQUAL(table.size(), 3);
  InterestTable::const_iterator it = table.begin();
  BOOST_CHECK(it != table.end());
  it++;
  BOOST_CHECK(it != table.end());
  it++;
  BOOST_CHECK(it != table.end());
  it++;
  BOOST_CHECK(it == table.end());

  BOOST_CHECK_EQUAL(table.size(), 3);
  table.erase(digest1);
  BOOST_CHECK_EQUAL(table.size(), 2);
  table.erase(digest2);
  BOOST_CHECK_EQUAL(table.size(), 1);
  ConstUnsatisfiedInterestPtr pendingInterest = *table.begin();
  table.clear();
  BOOST_CHECK_EQUAL(table.size(), 0);
  BOOST_CHECK(*pendingInterest->digest == *digest3);
}

BOOST_AUTO_TEST_CASE(Expire)
{
  InterestTable table(io);

  insert(table, interest1, digest1);

  advanceClocks(ndn::time::milliseconds(10), 10);

  insert(table, interest2, digest2);
  insert(table, interest3, digest3);

  advanceClocks(ndn::time::milliseconds(10), 5);

  insert(table, interest2, digest2);

  advanceClocks(ndn::time::milliseconds(10), 2);
  BOOST_CHECK_EQUAL(table.size(), 2);

  advanceClocks(ndn::time::milliseconds(10), 5);
  BOOST_CHECK_EQUAL(table.size(), 1);

  advanceClocks(ndn::time::milliseconds(10), 15);
  BOOST_CHECK_EQUAL(table.size(), 0);
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace test
} // namespace chronosync
