blob: 78337b310787e24193ee1526321b8dd509076ea8 [file] [log] [blame]
/* -*- 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 "object-manager.h"
#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>
using namespace Ccnx;
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;
BOOST_AUTO_TEST_SUITE(ObjectManagerTests)
BOOST_AUTO_TEST_CASE (ObjectManagerTest)
{
fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%");
cout << tmpdir << endl;
Name deviceName ("/device");
CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> ();
ObjectManager manager (ccnx, tmpdir);
HashPtr hash = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName);
bool ok = manager.objectsToLocalFile (deviceName, *hash, 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()