blob: a4c9e5009381e3c87bcf50119befef57da76a5bf [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/*
3 * Copyright (c) 2016-2017, Regents of the University of California,
4 * 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{
46public:
47 PipelineInterestsFixture()
48 : face(io)
49 , name("/ndn/chunks/test")
50 , nDataSegments(0)
Weiwei Liue4765012016-06-01 00:10:29 -070051 , hasFailed(false)
52 {
53 }
54
55protected:
56 void
57 setPipeline(unique_ptr<PipelineInterests> pline)
58 {
59 pipeline = std::move(pline);
60 }
61
62 shared_ptr<Data>
63 makeDataWithSegment(uint64_t segmentNo, bool setFinalBlockId = true) const
64 {
65 auto data = make_shared<Data>(Name(name).appendVersion(0).appendSegment(segmentNo));
66 if (setFinalBlockId)
67 data->setFinalBlockId(name::Component::fromSegment(nDataSegments - 1));
68 return signData(data);
69 }
70
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000071 shared_ptr<Data>
72 makeDataWithSegmentAndCongMark(uint64_t segmentNo, uint64_t congestionMark = 1,
73 bool setFinalBlockId = true) const
74 {
75 auto data = makeDataWithSegment(segmentNo, setFinalBlockId);
76 data->setCongestionMark(congestionMark);
77 return data;
78 }
79
Weiwei Liue4765012016-06-01 00:10:29 -070080 void
81 runWithData(const Data& data)
82 {
83 pipeline->run(data,
Davide Pesaventoe9c69852017-11-04 18:08:37 -040084 [this] (const Data&) {},
85 [this] (const std::string&) { hasFailed = true; });
Weiwei Liue4765012016-06-01 00:10:29 -070086 }
87
88protected:
89 boost::asio::io_service io;
90 util::DummyClientFace face;
91 Name name;
92 unique_ptr<PipelineInterests> pipeline;
93 uint64_t nDataSegments;
Weiwei Liue4765012016-06-01 00:10:29 -070094 bool hasFailed;
95};
96
97} // namespace tests
98} // namespace chunks
99} // namespace ndn
100
101#endif // NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP