Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 11 | * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 21 | #include "logging.hpp" |
| 22 | #include "object-manager.hpp" |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 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 | |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 33 | INIT_LOGGER ("Test.ObjectManager"); |
| 34 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 35 | using namespace Ndnx; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 36 | using namespace std; |
| 37 | using namespace boost; |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 38 | namespace fs = boost::filesystem; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 40 | BOOST_AUTO_TEST_SUITE(TestObjectManager) |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 41 | |
| 42 | BOOST_AUTO_TEST_CASE (ObjectManagerTest) |
| 43 | { |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 44 | INIT_LOGGERS (); |
| 45 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 46 | fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%"); |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 47 | _LOG_DEBUG ("tmpdir: " << tmpdir); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 48 | Name deviceName ("/device"); |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 50 | NdnxWrapperPtr ndnx = make_shared<NdnxWrapper> (); |
| 51 | ObjectManager manager (ndnx, tmpdir, "test-chronoshare"); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 53 | tuple<HashPtr,int> hash_semgents = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL (hash_semgents.get<1> (), 3); |
| 56 | |
| 57 | bool ok = manager.objectsToLocalFile (deviceName, *hash_semgents.get<0> (), tmpdir / "test.cc"); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 58 | BOOST_CHECK_EQUAL (ok, true); |
| 59 | |
| 60 | { |
| 61 | fs::ifstream origFile (fs::path("test") / "test-object-manager.cc"); |
| 62 | fs::ifstream newFile (tmpdir / "test.cc"); |
| 63 | |
| 64 | istream_iterator<char> eof, |
| 65 | origFileI (origFile), |
| 66 | newFileI (newFile); |
| 67 | |
| 68 | BOOST_CHECK_EQUAL_COLLECTIONS (origFileI, eof, newFileI, eof); |
| 69 | } |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 71 | remove_all (tmpdir); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | BOOST_AUTO_TEST_SUITE_END() |