blob: a7d8f0ba9aa1a7f19169a511af6678ef4d02bab2 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- 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 */
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
53 ~DiscoverVersionFixture()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010054 {
55 }
56
57protected:
Weiwei Liue4765012016-06-01 00:10:29 -070058 void
59 setDiscover(unique_ptr<DiscoverVersion> disc)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010060 {
61 discover = std::move(disc);
62 discover->onDiscoverySuccess.connect(bind(&DiscoverVersionFixture::onSuccess, this, _1));
63 discover->onDiscoveryFailure.connect(bind(&DiscoverVersionFixture::onFailure, this, _1));
64 }
65
66 shared_ptr<Data>
Weiwei Liue4765012016-06-01 00:10:29 -070067 makeDataWithVersion(uint64_t version) const
Andrea Tosatto672b9a72016-01-05 16:18:20 +010068 {
69 auto data = make_shared<Data>(Name(name).appendVersion(version).appendSegment(0));
70 data->setFinalBlockId(name::Component::fromSegment(0));
Weiwei Liue4765012016-06-01 00:10:29 -070071 return signData(data);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010072 }
73
74 static Options
75 makeOptions()
76 {
77 Options options;
78 options.isVerbose = false;
79 options.interestLifetime = time::seconds(1);
80 options.maxRetriesOnTimeoutOrNack = 3;
81 return options;
82 }
83
84 virtual void
85 onSuccess(const Data& data)
86 {
87 isDiscoveryFinished = true;
88
89 if (data.getName()[name.size()].isVersion())
90 discoveredVersion = data.getName()[name.size()].toVersion();
91 }
92
93 virtual void
94 onFailure(const std::string& reason)
95 {
96 isDiscoveryFinished = true;
97 }
98
99protected:
100 boost::asio::io_service io;
101 util::DummyClientFace face;
102 Name name;
103 unique_ptr<DiscoverVersion> discover;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100104 uint64_t discoveredVersion;
Weiwei Liue4765012016-06-01 00:10:29 -0700105 bool isDiscoveryFinished;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100106};
107
108} // namespace tests
109} // namespace chunks
110} // namespace ndn
111
112#endif // NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP