blob: dc801a7a961dc475852ed4f8e7daf873c6964d5a [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -08003 * Copyright (c) 2013-2017, 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 "object-manager.hpp"
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080022
Yukai Tud96dfb82016-10-24 13:48:01 -070023#include "test-common.hpp"
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080024
Yukai Tud96dfb82016-10-24 13:48:01 -070025#include <ndn-cxx/util/dummy-client-face.hpp>
26
27namespace ndn {
28namespace chronoshare {
29namespace tests {
30
31namespace fs = boost::filesystem;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080032
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -080033_LOG_INIT(Test.ObjectManager);
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080034
Yukai Tud96dfb82016-10-24 13:48:01 -070035class TestObjectManagerFixture : public IdentityManagementTimeFixture
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080036{
Yukai Tud96dfb82016-10-24 13:48:01 -070037public:
38 TestObjectManagerFixture()
39 : face(m_io, m_keyChain, {true, true})
40 {
41 tmpdir = fs::unique_path(UNIT_TEST_CONFIG_PATH) / "TestObjectManager";
42 if (exists(tmpdir)) {
43 remove_all(tmpdir);
44 }
45 manager = make_unique<ObjectManager>(face, m_keyChain, tmpdir, "test-chronoshare");
46 }
47
48public:
49 util::DummyClientFace face;
50 unique_ptr<ObjectManager> manager;
51 fs::path tmpdir;
52};
53
54BOOST_FIXTURE_TEST_SUITE(TestObjectManager, TestObjectManagerFixture)
55
56BOOST_AUTO_TEST_CASE(FromFileToFile)
57{
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080058 Name deviceName("/device");
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080059
Yukai Tud96dfb82016-10-24 13:48:01 -070060 auto objects = manager->localFileToObjects(fs::path("tests") / "unit-tests" / "object-manager.t.cpp", deviceName);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080061
Yukai Tud96dfb82016-10-24 13:48:01 -070062 BOOST_CHECK_EQUAL(std::get<1>(objects), 3);
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080063
Yukai Tud96dfb82016-10-24 13:48:01 -070064 bool ok = manager->objectsToLocalFile(deviceName, *std::get<0>(objects), tmpdir / "test.cpp");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080065 BOOST_CHECK_EQUAL(ok, true);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080066
67 {
Yukai Tud96dfb82016-10-24 13:48:01 -070068 fs::ifstream origFile(fs::path("tests") / "unit-tests" / "object-manager.t.cpp");
69 fs::ifstream newFile(tmpdir / "test.cpp");
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080070
Yukai Tud96dfb82016-10-24 13:48:01 -070071 std::istream_iterator<char> eof, origFileI(origFile), newFileI(newFile);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080072
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080073 BOOST_CHECK_EQUAL_COLLECTIONS(origFileI, eof, newFileI, eof);
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080074 }
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080075}
76
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080077BOOST_AUTO_TEST_SUITE_END()
Yukai Tud96dfb82016-10-24 13:48:01 -070078
79} // namespace tests
80} // namespace chronoshare
81} // namespace ndn