blob: 9b08d5310517a9863c1a39f2487469583ffdf525 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Ashlesh Gawande5a895472020-01-25 18:07:32 -08003 * Copyright (c) 2014-2020, The University of Memphis
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -06009 * of the GNU Lesser General Public License as published by the Free Software Foundation,
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050010 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060014 * PURPOSE. See the GNU Lesser General Public License for more details.
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050015 *
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060016 * You should have received a copy of the GNU Lesser General Public License along with
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/consumer.hpp"
Ashlesh Gawande584e1202019-05-19 16:15:33 -070021#include "unit-test-time-fixture.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050022
23#include <boost/test/unit_test.hpp>
24#include <ndn-cxx/name.hpp>
25#include <ndn-cxx/util/dummy-client-face.hpp>
26
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050027namespace psync {
28
29using namespace ndn;
30using namespace std;
31
32BOOST_AUTO_TEST_SUITE(TestConsumer)
33
34BOOST_AUTO_TEST_CASE(Constructor)
35{
36 util::DummyClientFace face({true, true});
37 BOOST_REQUIRE_NO_THROW(Consumer(Name("/psync"),
38 face,
Ashlesh Gawandea9296472018-08-04 08:21:39 -050039 [] (const vector<Name>&) {},
40 [] (const vector<MissingDataInfo>&) {},
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050041 40,
42 0.001));
43}
44
45BOOST_AUTO_TEST_CASE(AddSubscription)
46{
47 util::DummyClientFace face({true, true});
48 Consumer consumer(Name("/psync"), face,
Ashlesh Gawandea9296472018-08-04 08:21:39 -050049 [] (const vector<Name>&) {},
50 [] (const vector<MissingDataInfo>&) {},
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050051 40, 0.001);
52
53 Name subscription("test");
54
55 BOOST_CHECK(!consumer.isSubscribed(subscription));
56 BOOST_CHECK(consumer.addSubscription(subscription));
57 BOOST_CHECK(!consumer.addSubscription(subscription));
58}
59
Ashlesh Gawande584e1202019-05-19 16:15:33 -070060BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, ndn::tests::UnitTestTimeFixture)
61{
62 util::DummyClientFace face(io, {true, true});
63 Consumer consumer(Name("/psync"), face,
64 [] (const vector<Name>&) {},
65 [] (const vector<MissingDataInfo>&) {},
66 40, 0.001,
67 ndn::time::milliseconds(4000),
68 ndn::time::milliseconds(4000));
69
70 consumer.sendHelloInterest();
71 advanceClocks(ndn::time::milliseconds(4000));
72 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
73 face.sentInterests.clear();
74 consumer.stop();
75
76 consumer.m_iblt = ndn::Name("test");
77 consumer.sendSyncInterest();
78 advanceClocks(ndn::time::milliseconds(4000));
79 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
80 consumer.stop();
81}
82
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050083BOOST_AUTO_TEST_SUITE_END()
84
85} // namespace psync