/* -*- 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-ccnx-wrapper.h"
#include "../model/sync-app-data-fetch.h"
#include "../model/sync-app-data-publish.h"

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

class TestStructApp {
public:
  map<string, string> data;
  void set(string str1, string str2) {
    data.insert(make_pair(str1, str2));
  }

  void erase(string str1, string str2) {
    data.erase(str1);
  }

  string toString(){
    map<string, string>::iterator it = data.begin(); 
    string str = "";
    for (; it != data.end(); ++it){
      str += "<";
      str += it->first;
      str += "|";
      str += it->second;
      str += ">";
    }
    return str;
  }

};

BOOST_AUTO_TEST_CASE (AppDataPublishAndFetchTest)
{
  TestStructApp foo;
  TestStructApp bar;
	
  string interest = "/april/fool";
  string seq[5] = {"1", "2", "3", "4", "5"};
  string str[5] = {"panda", "express", "tastes", "so", "good"};

  for (int i = 0; i < 5; i++) {
    foo.set(interest + "/" + "0/" /*session*/ + seq[i], str[i]);
  }

  boost::function<void (string, string)> setFunc =
    bind(&TestStructApp::set, &bar, _1, _2);

  shared_ptr<CcnxWrapper> handle(new CcnxWrapper());

  AppDataFetch fetcher(handle, setFunc);
  AppDataPublish publisher(handle);

  for (int i = 1; i <= 5; i++) {
    publisher.publishData(interest, 0, str[i - 1], 5);
  }

  BOOST_CHECK_EQUAL(publisher.getHighestSeq(interest, 0), 5);
  BOOST_CHECK_EQUAL(publisher.getRecentData(interest, 0), str[4]);

  fetcher.onUpdate (interest, SeqNo (0,5), SeqNo (0,0));
  // give time for ccnd to react
  sleep(1);
  BOOST_CHECK_EQUAL(foo.toString(), bar.toString());


  boost::function<void (string, string)> eraseFunc =
    bind(&TestStructApp::erase, &bar, _1, _2);
  fetcher.setDataCallback(eraseFunc);

  fetcher.onUpdate (interest, SeqNo (0,5), SeqNo (0,0));
  // give time for ccnd to react
  sleep(1);
  TestStructApp poo;

  BOOST_CHECK_EQUAL(poo.toString(), bar.toString());

}


