/* -*- 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 + "/" + 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.fetch(interest, 1, 5);
	// 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.fetch(interest, 1, 5);
	// give time for ccnd to react
	sleep(1);
	TestStructApp poo;

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

}


