blob: 78337b310787e24193ee1526321b8dd509076ea8 [file] [log] [blame]
Alexander Afanasyev68f2a952013-01-08 14:34:16 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
22#include "object-manager.h"
23
24#include <boost/filesystem.hpp>
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080025#include <boost/filesystem/fstream.hpp>
26
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080027#include <boost/test/unit_test.hpp>
28#include <unistd.h>
29#include <boost/make_shared.hpp>
30#include <iostream>
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080031#include <iterator>
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080032
33using namespace Ccnx;
34using namespace std;
35using namespace boost;
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080036namespace fs = boost::filesystem;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080037
38BOOST_AUTO_TEST_SUITE(ObjectManagerTests)
39
40BOOST_AUTO_TEST_CASE (ObjectManagerTest)
41{
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080042 fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%");
43 cout << tmpdir << endl;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080044 Name deviceName ("/device");
45
46 CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> ();
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080047 ObjectManager manager (ccnx, tmpdir);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080048
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080049 HashPtr hash = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080050
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080051 bool ok = manager.objectsToLocalFile (deviceName, *hash, tmpdir / "test.cc");
52 BOOST_CHECK_EQUAL (ok, true);
53
54 {
55 fs::ifstream origFile (fs::path("test") / "test-object-manager.cc");
56 fs::ifstream newFile (tmpdir / "test.cc");
57
58 istream_iterator<char> eof,
59 origFileI (origFile),
60 newFileI (newFile);
61
62 BOOST_CHECK_EQUAL_COLLECTIONS (origFileI, eof, newFileI, eof);
63 }
64
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080065 remove_all (tmpdir);
66}
67
68
69BOOST_AUTO_TEST_SUITE_END()