Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2016, Regents of the University of California, |
| 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
| 6 | * |
| 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 9 | * |
| 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 22 | * |
| 23 | * @author Andrea Tosatto |
| 24 | * @author Weiwei Liu |
| 25 | */ |
| 26 | |
| 27 | #ifndef NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP |
| 28 | #define NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP |
| 29 | |
| 30 | #include "tools/chunks/catchunks/pipeline-interests.hpp" |
| 31 | |
| 32 | #include "tests/test-common.hpp" |
| 33 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 34 | |
| 35 | namespace ndn { |
| 36 | namespace chunks { |
| 37 | namespace tests { |
| 38 | |
| 39 | using namespace ndn::tests; |
| 40 | |
| 41 | class PipelineInterestsFixture : public UnitTestTimeFixture |
| 42 | { |
| 43 | public: |
| 44 | PipelineInterestsFixture() |
| 45 | : face(io) |
| 46 | , name("/ndn/chunks/test") |
| 47 | , nDataSegments(0) |
| 48 | , nReceivedSegments(0) |
| 49 | , hasFailed(false) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | protected: |
| 54 | void |
| 55 | setPipeline(unique_ptr<PipelineInterests> pline) |
| 56 | { |
| 57 | pipeline = std::move(pline); |
| 58 | } |
| 59 | |
| 60 | shared_ptr<Data> |
| 61 | makeDataWithSegment(uint64_t segmentNo, bool setFinalBlockId = true) const |
| 62 | { |
| 63 | auto data = make_shared<Data>(Name(name).appendVersion(0).appendSegment(segmentNo)); |
| 64 | if (setFinalBlockId) |
| 65 | data->setFinalBlockId(name::Component::fromSegment(nDataSegments - 1)); |
| 66 | return signData(data); |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | runWithData(const Data& data) |
| 71 | { |
| 72 | pipeline->run(data, |
| 73 | bind(&PipelineInterestsFixture::onData, this, _1, _2), |
| 74 | bind(&PipelineInterestsFixture::onFailure, this, _1)); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | void |
| 79 | onData(const Interest& interest, const Data& data) |
| 80 | { |
| 81 | nReceivedSegments++; |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | onFailure(const std::string& reason) |
| 86 | { |
| 87 | hasFailed = true; |
| 88 | } |
| 89 | |
| 90 | protected: |
| 91 | boost::asio::io_service io; |
| 92 | util::DummyClientFace face; |
| 93 | Name name; |
| 94 | unique_ptr<PipelineInterests> pipeline; |
| 95 | uint64_t nDataSegments; |
| 96 | uint64_t nReceivedSegments; |
| 97 | bool hasFailed; |
| 98 | }; |
| 99 | |
| 100 | } // namespace tests |
| 101 | } // namespace chunks |
| 102 | } // namespace ndn |
| 103 | |
| 104 | #endif // NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP |