blob: 8cbc97e46f7e2201e3e5065faa61331e8a181cf5 [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, Regents of the University of California.
Alexander Afanasyev68f2a952013-01-08 14:34:16 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyev68f2a952013-01-08 14:34:16 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * 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 Afanasyev68f2a952013-01-08 14:34:16 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * 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 Afanasyev68f2a952013-01-08 14:34:16 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * 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 Afanasyev68f2a952013-01-08 14:34:16 -080019 */
20
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080021#include "logging.hpp"
22#include "object-manager.hpp"
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080023
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
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080033INIT_LOGGER ("Test.ObjectManager");
34
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070035using namespace Ndnx;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080036using namespace std;
37using namespace boost;
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080038namespace fs = boost::filesystem;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080039
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080040BOOST_AUTO_TEST_SUITE(TestObjectManager)
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080041
42BOOST_AUTO_TEST_CASE (ObjectManagerTest)
43{
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080044 INIT_LOGGERS ();
45
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080046 fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%");
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080047 _LOG_DEBUG ("tmpdir: " << tmpdir);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080048 Name deviceName ("/device");
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080049
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070050 NdnxWrapperPtr ndnx = make_shared<NdnxWrapper> ();
51 ObjectManager manager (ndnx, tmpdir, "test-chronoshare");
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080052
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080053 tuple<HashPtr,int> hash_semgents = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080054
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080055 BOOST_CHECK_EQUAL (hash_semgents.get<1> (), 3);
56
57 bool ok = manager.objectsToLocalFile (deviceName, *hash_semgents.get<0> (), tmpdir / "test.cc");
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080058 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 Afanasyeva35756b2013-01-22 16:59:11 -080070
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080071 remove_all (tmpdir);
72}
73
74
75BOOST_AUTO_TEST_SUITE_END()