blob: 4e4222392ef9381af6c7a6ca16c4531dd9c01ce5 [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 Pesavento5748e822024-01-26 18:40:22 -05003 * Copyright (c) 2016-2024, 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 Pesavento66777622020-10-09 18:46:03 -040035#include "tests/io-fixture.hpp"
Davide Pesaventoe9c69852017-11-04 18:08:37 -040036
Weiwei Liue4765012016-06-01 00:10:29 -070037#include <ndn-cxx/util/dummy-client-face.hpp>
38
Davide Pesaventob3570c62022-02-19 19:19:00 -050039namespace ndn::chunks::tests {
Weiwei Liue4765012016-06-01 00:10:29 -070040
41using namespace ndn::tests;
42
Davide Pesavento66777622020-10-09 18:46:03 -040043class PipelineInterestsFixture : public IoFixture
Weiwei Liue4765012016-06-01 00:10:29 -070044{
Weiwei Liue4765012016-06-01 00:10:29 -070045protected:
46 void
Davide Pesavento5748e822024-01-26 18:40:22 -050047 setPipeline(std::unique_ptr<PipelineInterests> pline)
Weiwei Liue4765012016-06-01 00:10:29 -070048 {
schneiderklausd8197df2019-03-16 11:31:40 -070049 m_pipeline = std::move(pline);
Weiwei Liue4765012016-06-01 00:10:29 -070050 }
51
Davide Pesavento5748e822024-01-26 18:40:22 -050052 std::shared_ptr<Data>
Weiwei Liue4765012016-06-01 00:10:29 -070053 makeDataWithSegment(uint64_t segmentNo, bool setFinalBlockId = true) const
54 {
Davide Pesavento5748e822024-01-26 18:40:22 -050055 auto data = std::make_shared<Data>(Name(name).appendVersion(0).appendSegment(segmentNo));
Weiwei Liue4765012016-06-01 00:10:29 -070056 if (setFinalBlockId)
Davide Pesavento969cd5a2018-04-20 16:27:47 -040057 data->setFinalBlock(name::Component::fromSegment(nDataSegments - 1));
Weiwei Liue4765012016-06-01 00:10:29 -070058 return signData(data);
59 }
60
Davide Pesavento5748e822024-01-26 18:40:22 -050061 std::shared_ptr<Data>
Davide Pesaventodc4cb4b2017-11-21 13:40:22 -050062 makeDataWithSegmentAndCongMark(uint64_t segmentNo,
63 uint64_t congestionMark = 1,
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000064 bool setFinalBlockId = true) const
65 {
66 auto data = makeDataWithSegment(segmentNo, setFinalBlockId);
67 data->setCongestionMark(congestionMark);
68 return data;
69 }
70
Weiwei Liue4765012016-06-01 00:10:29 -070071 void
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080072 run(const Name& name, uint64_t version = 0)
Weiwei Liue4765012016-06-01 00:10:29 -070073 {
schneiderklausd8197df2019-03-16 11:31:40 -070074 m_pipeline->run(Name(name).appendVersion(version),
75 [] (const Data&) {},
76 [this] (const std::string&) { hasFailed = true; });
Weiwei Liue4765012016-06-01 00:10:29 -070077 }
78
79protected:
Junxiao Shi869d73e2023-08-10 22:52:26 +000080 DummyClientFace face{m_io};
Davide Pesaventodc4cb4b2017-11-21 13:40:22 -050081 Name name{"/ndn/chunks/test"};
82 uint64_t nDataSegments = 0;
83 bool hasFailed = false;
schneiderklausd8197df2019-03-16 11:31:40 -070084
85private:
Davide Pesavento5748e822024-01-26 18:40:22 -050086 std::unique_ptr<PipelineInterests> m_pipeline;
Weiwei Liue4765012016-06-01 00:10:29 -070087};
88
Davide Pesaventob3570c62022-02-19 19:19:00 -050089} // namespace ndn::chunks::tests
Weiwei Liue4765012016-06-01 00:10:29 -070090
91#endif // NDN_TOOLS_TESTS_CHUNKS_PIPELINE_INTERESTS_FIXTURE_HPP