/* -*- 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
 *	   Zhenkai Zhu <zhenkai@cs.ucla.edu>
 */

#include "logging.hpp"
#include "object-manager.hpp"

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>

#include <boost/test/unit_test.hpp>
#include <unistd.h>
#include <boost/make_shared.hpp>
#include <iostream>
#include <iterator>

INIT_LOGGER ("Test.ObjectManager");

using namespace Ndnx;
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;

BOOST_AUTO_TEST_SUITE(TestObjectManager)

BOOST_AUTO_TEST_CASE (ObjectManagerTest)
{
  INIT_LOGGERS ();

  fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%");
  _LOG_DEBUG ("tmpdir: " << tmpdir);
  Name deviceName ("/device");

  NdnxWrapperPtr ndnx = make_shared<NdnxWrapper> ();
  ObjectManager manager (ndnx, tmpdir, "test-chronoshare");

  tuple<HashPtr,int> hash_semgents = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName);

  BOOST_CHECK_EQUAL (hash_semgents.get<1> (), 3);

  bool ok = manager.objectsToLocalFile (deviceName, *hash_semgents.get<0> (), tmpdir / "test.cc");
  BOOST_CHECK_EQUAL (ok, true);

  {
    fs::ifstream origFile (fs::path("test") / "test-object-manager.cc");
    fs::ifstream newFile (tmpdir / "test.cc");

    istream_iterator<char> eof,
      origFileI (origFile),
      newFileI (newFile);

    BOOST_CHECK_EQUAL_COLLECTIONS (origFileI, eof, newFileI, eof);
  }

  remove_all (tmpdir);
}


BOOST_AUTO_TEST_SUITE_END()
