blob: ed18235201a860c1684016a91a178e56ee3e7400 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento969cd5a2018-04-20 16:27:47 -04002/*
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -08003 * Copyright (c) 2016-2019, Regents of the University of California,
Davide Pesavento969cd5a2018-04-20 16:27:47 -04004 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Andrea Tosatto672b9a72016-01-05 16:18:20 +01006 *
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 */
25
26#ifndef NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
27#define NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
28
29#include "tools/chunks/catchunks/discover-version.hpp"
30
31#include "tests/test-common.hpp"
32#include <ndn-cxx/util/dummy-client-face.hpp>
33
34namespace ndn {
35namespace chunks {
36namespace tests {
37
Weiwei Liue4765012016-06-01 00:10:29 -070038using namespace ndn::tests;
39
40class DiscoverVersionFixture : public UnitTestTimeFixture, virtual protected Options
Andrea Tosatto672b9a72016-01-05 16:18:20 +010041{
42public:
43 DiscoverVersionFixture(const Options& options)
44 : Options(options)
45 , face(io)
46 , name("/ndn/chunks/test")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010047 , discoveredVersion(0)
Weiwei Liue4765012016-06-01 00:10:29 -070048 , isDiscoveryFinished(false)
49 {
50 }
51
52 virtual
Davide Pesavento969cd5a2018-04-20 16:27:47 -040053 ~DiscoverVersionFixture() = default;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010054
55protected:
Weiwei Liue4765012016-06-01 00:10:29 -070056 void
57 setDiscover(unique_ptr<DiscoverVersion> disc)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010058 {
59 discover = std::move(disc);
60 discover->onDiscoverySuccess.connect(bind(&DiscoverVersionFixture::onSuccess, this, _1));
61 discover->onDiscoveryFailure.connect(bind(&DiscoverVersionFixture::onFailure, this, _1));
62 }
63
64 shared_ptr<Data>
Weiwei Liue4765012016-06-01 00:10:29 -070065 makeDataWithVersion(uint64_t version) const
Andrea Tosatto672b9a72016-01-05 16:18:20 +010066 {
67 auto data = make_shared<Data>(Name(name).appendVersion(version).appendSegment(0));
Davide Pesavento969cd5a2018-04-20 16:27:47 -040068 data->setFinalBlock(name::Component::fromSegment(0));
Weiwei Liue4765012016-06-01 00:10:29 -070069 return signData(data);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010070 }
71
72 static Options
73 makeOptions()
74 {
75 Options options;
76 options.isVerbose = false;
77 options.interestLifetime = time::seconds(1);
78 options.maxRetriesOnTimeoutOrNack = 3;
79 return options;
80 }
81
82 virtual void
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080083 onSuccess(const Name& versionedName)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010084 {
85 isDiscoveryFinished = true;
86
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080087 BOOST_REQUIRE(!versionedName.empty() && versionedName[-1].isVersion());
88 discoveredVersion = versionedName[-1].toVersion();
Andrea Tosatto672b9a72016-01-05 16:18:20 +010089 }
90
91 virtual void
92 onFailure(const std::string& reason)
93 {
94 isDiscoveryFinished = true;
95 }
96
97protected:
98 boost::asio::io_service io;
99 util::DummyClientFace face;
100 Name name;
101 unique_ptr<DiscoverVersion> discover;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100102 uint64_t discoveredVersion;
Weiwei Liue4765012016-06-01 00:10:29 -0700103 bool isDiscoveryFinished;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100104};
105
106} // namespace tests
107} // namespace chunks
108} // namespace ndn
109
110#endif // NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP