blob: 36c5c57d491022114eb8cdebfa3acfc8e6aec807 [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
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080022#include "logging.h"
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080023#include "object-manager.h"
24
25#include <boost/filesystem.hpp>
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080026#include <boost/filesystem/fstream.hpp>
27
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080028#include <boost/test/unit_test.hpp>
29#include <unistd.h>
30#include <boost/make_shared.hpp>
31#include <iostream>
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080032#include <iterator>
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080033
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080034INIT_LOGGER ("Test.ObjectManager");
35
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080036using namespace Ccnx;
37using namespace std;
38using namespace boost;
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080039namespace fs = boost::filesystem;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080040
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080041BOOST_AUTO_TEST_SUITE(TestObjectManager)
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080042
43BOOST_AUTO_TEST_CASE (ObjectManagerTest)
44{
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080045 INIT_LOGGERS ();
46
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080047 fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%");
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080048 _LOG_DEBUG ("tmpdir: " << tmpdir);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080049 Name deviceName ("/device");
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080050
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080051 CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> ();
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080052 ObjectManager manager (ccnx, tmpdir, "test-chronoshare");
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080053
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080054 tuple<HashPtr,int> hash_semgents = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080055
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080056 BOOST_CHECK_EQUAL (hash_semgents.get<1> (), 3);
57
58 bool ok = manager.objectsToLocalFile (deviceName, *hash_semgents.get<0> (), tmpdir / "test.cc");
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080059 BOOST_CHECK_EQUAL (ok, true);
60
61 {
62 fs::ifstream origFile (fs::path("test") / "test-object-manager.cc");
63 fs::ifstream newFile (tmpdir / "test.cc");
64
65 istream_iterator<char> eof,
66 origFileI (origFile),
67 newFileI (newFile);
68
69 BOOST_CHECK_EQUAL_COLLECTIONS (origFileI, eof, newFileI, eof);
70 }
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080071
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080072 remove_all (tmpdir);
73}
74
75
76BOOST_AUTO_TEST_SUITE_END()