blob: 4811ebe1a4500043569d0aed99261a13b33fdb27 [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/>.
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070018 */
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050019
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/consumer.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050021
Davide Pesavento5b3cf762020-04-03 16:20:04 -040022#include "tests/boost-test.hpp"
23#include "tests/unit-test-time-fixture.hpp"
24
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050025#include <ndn-cxx/name.hpp>
26#include <ndn-cxx/util/dummy-client-face.hpp>
27
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050028namespace psync {
29
30using namespace ndn;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050031
32BOOST_AUTO_TEST_SUITE(TestConsumer)
33
34BOOST_AUTO_TEST_CASE(Constructor)
35{
36 util::DummyClientFace face({true, true});
Davide Pesavento5b3cf762020-04-03 16:20:04 -040037 BOOST_REQUIRE_NO_THROW(Consumer(Name("/psync"), face,
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070038 [] (const auto&) {},
39 [] (const auto&) {},
Davide Pesavento5b3cf762020-04-03 16:20:04 -040040 40, 0.001));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050041}
42
43BOOST_AUTO_TEST_CASE(AddSubscription)
44{
45 util::DummyClientFace face({true, true});
46 Consumer consumer(Name("/psync"), face,
Davide Pesavento5b3cf762020-04-03 16:20:04 -040047 [] (const auto&) {},
48 [] (const auto&) {},
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050049 40, 0.001);
50
51 Name subscription("test");
52
53 BOOST_CHECK(!consumer.isSubscribed(subscription));
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070054 BOOST_CHECK(consumer.addSubscription(subscription, 0));
55 BOOST_CHECK(!consumer.addSubscription(subscription, 0));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050056}
57
Davide Pesavento5b3cf762020-04-03 16:20:04 -040058BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::UnitTestTimeFixture)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070059{
60 util::DummyClientFace face(io, {true, true});
61 Consumer consumer(Name("/psync"), face,
Davide Pesavento5b3cf762020-04-03 16:20:04 -040062 [] (const auto&) {},
63 [] (const auto&) {},
Ashlesh Gawande584e1202019-05-19 16:15:33 -070064 40, 0.001,
65 ndn::time::milliseconds(4000),
66 ndn::time::milliseconds(4000));
67
68 consumer.sendHelloInterest();
69 advanceClocks(ndn::time::milliseconds(4000));
70 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
71 face.sentInterests.clear();
72 consumer.stop();
73
74 consumer.m_iblt = ndn::Name("test");
75 consumer.sendSyncInterest();
76 advanceClocks(ndn::time::milliseconds(4000));
77 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
78 consumer.stop();
79}
80
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050081BOOST_AUTO_TEST_SUITE_END()
82
Davide Pesavento5b3cf762020-04-03 16:20:04 -040083} // namespace psync