blob: c9979fd6b2d4dcf547730ab74951a3da6ac2c9bc [file] [log] [blame]
Weiwei Liue4765012016-06-01 00:10:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe9c69852017-11-04 18:08:37 -04002/*
Davide Pesavento969cd5a2018-04-20 16:27:47 -04003 * Copyright (c) 2016-2018, Regents of the University of California,
Davide Pesaventoe9c69852017-11-04 18:08:37 -04004 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Weiwei Liue4765012016-06-01 00:10:29 -07006 *
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
Davide Pesaventoe9c69852017-11-04 18:08:37 -040024 * @author Davide Pesavento
Weiwei Liue4765012016-06-01 00:10:29 -070025 * @author Weiwei Liu
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000026 * @author Chavoosh Ghasemi
Weiwei Liue4765012016-06-01 00:10:29 -070027 */
28
29#ifndef NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP
30#define NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP
31
32#include "tools/chunks/catchunks/pipeline-interests.hpp"
33
34#include "tests/test-common.hpp"
Davide Pesaventoe9c69852017-11-04 18:08:37 -040035
Weiwei Liue4765012016-06-01 00:10:29 -070036#include <ndn-cxx/util/dummy-client-face.hpp>
37
38namespace ndn {
39namespace chunks {
40namespace tests {
41
42using namespace ndn::tests;
43
44class PipelineInterestsFixture : public UnitTestTimeFixture
45{
Weiwei Liue4765012016-06-01 00:10:29 -070046protected:
47 void
48 setPipeline(unique_ptr<PipelineInterests> pline)
49 {
50 pipeline = std::move(pline);
51 }
52
53 shared_ptr<Data>
54 makeDataWithSegment(uint64_t segmentNo, bool setFinalBlockId = true) const
55 {
56 auto data = make_shared<Data>(Name(name).appendVersion(0).appendSegment(segmentNo));
57 if (setFinalBlockId)
Davide Pesavento969cd5a2018-04-20 16:27:47 -040058 data->setFinalBlock(name::Component::fromSegment(nDataSegments - 1));
Weiwei Liue4765012016-06-01 00:10:29 -070059 return signData(data);
60 }
61
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000062 shared_ptr<Data>
Davide Pesaventodc4cb4b2017-11-21 13:40:22 -050063 makeDataWithSegmentAndCongMark(uint64_t segmentNo,
64 uint64_t congestionMark = 1,
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000065 bool setFinalBlockId = true) const
66 {
67 auto data = makeDataWithSegment(segmentNo, setFinalBlockId);
68 data->setCongestionMark(congestionMark);
69 return data;
70 }
71
Weiwei Liue4765012016-06-01 00:10:29 -070072 void
73 runWithData(const Data& data)
74 {
75 pipeline->run(data,
Davide Pesaventodc4cb4b2017-11-21 13:40:22 -050076 [] (const Data&) {},
Davide Pesaventoe9c69852017-11-04 18:08:37 -040077 [this] (const std::string&) { hasFailed = true; });
Weiwei Liue4765012016-06-01 00:10:29 -070078 }
79
80protected:
81 boost::asio::io_service io;
Davide Pesaventodc4cb4b2017-11-21 13:40:22 -050082 util::DummyClientFace face{io};
Weiwei Liue4765012016-06-01 00:10:29 -070083 unique_ptr<PipelineInterests> pipeline;
Davide Pesaventodc4cb4b2017-11-21 13:40:22 -050084 Name name{"/ndn/chunks/test"};
85 uint64_t nDataSegments = 0;
86 bool hasFailed = false;
Weiwei Liue4765012016-06-01 00:10:29 -070087};
88
89} // namespace tests
90} // namespace chunks
91} // namespace ndn
92
93#endif // NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP