Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 1cf5c43 | 2017-01-13 23:22:15 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, 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 "object-manager.hpp" |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 22 | |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 23 | #include "test-common.hpp" |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 24 | |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 25 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace chronoshare { |
| 29 | namespace tests { |
| 30 | |
| 31 | namespace fs = boost::filesystem; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 1cf5c43 | 2017-01-13 23:22:15 -0800 | [diff] [blame] | 33 | _LOG_INIT(Test.ObjectManager); |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 34 | |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 35 | class TestObjectManagerFixture : public IdentityManagementTimeFixture |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 36 | { |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 37 | public: |
| 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 | |
| 48 | public: |
| 49 | util::DummyClientFace face; |
| 50 | unique_ptr<ObjectManager> manager; |
| 51 | fs::path tmpdir; |
| 52 | }; |
| 53 | |
| 54 | BOOST_FIXTURE_TEST_SUITE(TestObjectManager, TestObjectManagerFixture) |
| 55 | |
| 56 | BOOST_AUTO_TEST_CASE(FromFileToFile) |
| 57 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 58 | Name deviceName("/device"); |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 59 | |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 60 | auto objects = manager->localFileToObjects(fs::path("tests") / "unit-tests" / "object-manager.t.cpp", deviceName); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 61 | |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 62 | BOOST_CHECK_EQUAL(std::get<1>(objects), 3); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 63 | |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 64 | bool ok = manager->objectsToLocalFile(deviceName, *std::get<0>(objects), tmpdir / "test.cpp"); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 65 | BOOST_CHECK_EQUAL(ok, true); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 66 | |
| 67 | { |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 68 | fs::ifstream origFile(fs::path("tests") / "unit-tests" / "object-manager.t.cpp"); |
| 69 | fs::ifstream newFile(tmpdir / "test.cpp"); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 70 | |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 71 | std::istream_iterator<char> eof, origFileI(origFile), newFileI(newFile); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL_COLLECTIONS(origFileI, eof, newFileI, eof); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 74 | } |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 77 | BOOST_AUTO_TEST_SUITE_END() |
Yukai Tu | d96dfb8 | 2016-10-24 13:48:01 -0700 | [diff] [blame] | 78 | |
| 79 | } // namespace tests |
| 80 | } // namespace chronoshare |
| 81 | } // namespace ndn |