/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012 University of California, Los Angeles
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
 *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
 *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
 */

#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp> 
#include <map>
using boost::test_tools::output_test_stream;

#include <boost/make_shared.hpp>
#include "../model/sync-scheduler.h"
#include "../model/sync-logic.h"

using namespace Sync;
using namespace std;
using namespace boost;



// void funcUpdate (const std::string &, const SeqNo &newSeq, const SeqNo &oldSeq)
// {
//   cout << "funcUpdate\n";
// }

// void funcRemove (const std::string &)
// {
//   cout << "funcRemove\n";
// }

struct SchedulerFixture
{
  SchedulerFixture ()
    : counter (0)
  {}

  int counter;
  
  Scheduler *scheduler;

  void everySecond ()
  {
    // cout << "." << flush;
    counter ++;

    if (counter < 9)
    scheduler->schedule (boost::posix_time::milliseconds (100), boost::bind (&SchedulerFixture::everySecond, this));
  }

  void setCounterFive ()
  {
    counter = 5;
  }

  void setCounterThree ()
  {
    counter = 3;
  }
};


#ifdef _DEBUG

BOOST_FIXTURE_TEST_SUITE (SchedulerTestSuite, SchedulerFixture)

BOOST_AUTO_TEST_CASE (BasicTest)
{
  BOOST_CHECK_NO_THROW (scheduler = new Scheduler ());

  scheduler->schedule (posix_time::milliseconds (100), bind (&SchedulerFixture::everySecond, this));

  sleep (1);
  // cout << counter << endl;
  BOOST_CHECK_EQUAL (counter, 9); // generally, should be 9

  scheduler->schedule (posix_time::seconds (2),
		       bind (&SchedulerFixture::setCounterFive, this));

  this_thread::sleep (posix_time::milliseconds (400)); // just in case

  scheduler->schedule (posix_time::milliseconds (600),
		       bind (&SchedulerFixture::setCounterThree, this));

  this_thread::sleep (posix_time::milliseconds (500));
  BOOST_CHECK_EQUAL (counter, 9); // still 9

  this_thread::sleep (posix_time::milliseconds (200));
  BOOST_CHECK_EQUAL (counter, 3);

  this_thread::sleep (posix_time::milliseconds (1000));
  BOOST_CHECK_EQUAL (counter, 5);
  
  BOOST_CHECK_NO_THROW (delete scheduler);
}

BOOST_AUTO_TEST_SUITE_END ()


void funcUpdate( const std::string &/*prefix*/, const SeqNo &/*newSeq*/, const SeqNo &/*oldSeq*/ )
{
}

void funcRemove( const std::string &/*prefix*/ )
{
}

BOOST_AUTO_TEST_CASE (SyncLogicTest)
{  
  SyncLogic *logic = 0;
  BOOST_CHECK_NO_THROW (logic = new SyncLogic ("/prefix", funcUpdate, funcRemove, make_shared<CcnxWrapper> ()));

  Scheduler &scheduler = logic->getScheduler ();
  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 0);

  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e")); 
  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 1);

  this_thread::sleep (posix_time::milliseconds (100)); // max waiting time
  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 0);

  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e")); 
  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e")); 
  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e")); 
  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 4);  

  this_thread::sleep (posix_time::milliseconds (19)); // min waiting time is 20
  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 4);  

  this_thread::sleep (posix_time::milliseconds (100)); // max waiting time
  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 0);
  
  BOOST_CHECK_NO_THROW (delete logic);
}

#endif
