Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 25 | #include <boost/filesystem/fstream.hpp> |
| 26 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 27 | #include <boost/test/unit_test.hpp> |
| 28 | #include <unistd.h> |
| 29 | #include <boost/make_shared.hpp> |
| 30 | #include <iostream> |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 31 | #include <iterator> |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 32 | |
| 33 | using namespace Ccnx; |
| 34 | using namespace std; |
| 35 | using namespace boost; |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 36 | namespace fs = boost::filesystem; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(ObjectManagerTests) |
| 39 | |
| 40 | BOOST_AUTO_TEST_CASE (ObjectManagerTest) |
| 41 | { |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 42 | fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%"); |
| 43 | cout << tmpdir << endl; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 44 | Name deviceName ("/device"); |
| 45 | |
| 46 | CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> (); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 47 | ObjectManager manager (ccnx, tmpdir); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 48 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 49 | HashPtr hash = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 50 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 51 | 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 Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 65 | remove_all (tmpdir); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | BOOST_AUTO_TEST_SUITE_END() |