blob: 373a8cabb8b3d7008a7ad7cd909effa2fd855e12 [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"
Davide Pesaventof91d1df2020-11-25 14:50:41 -050023#include "tests/io-fixture.hpp"
Davide Pesavento5b3cf762020-04-03 16:20:04 -040024
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 Pesaventof91d1df2020-11-25 14:50:41 -050058BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070059{
Davide Pesaventof91d1df2020-11-25 14:50:41 -050060 util::DummyClientFace face(m_io, {true, true});
Ashlesh Gawande584e1202019-05-19 16:15:33 -070061 Consumer consumer(Name("/psync"), face,
Davide Pesavento5b3cf762020-04-03 16:20:04 -040062 [] (const auto&) {},
63 [] (const auto&) {},
Davide Pesaventof91d1df2020-11-25 14:50:41 -050064 40, 0.001, 4_s, 4_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070065
66 consumer.sendHelloInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070067 advanceClocks(4_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070068 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
69 face.sentInterests.clear();
70 consumer.stop();
71
Davide Pesaventof91d1df2020-11-25 14:50:41 -050072 consumer.m_iblt = Name("test");
Ashlesh Gawande584e1202019-05-19 16:15:33 -070073 consumer.sendSyncInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070074 advanceClocks(3999_ms);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070075 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
76 consumer.stop();
77}
78
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050079BOOST_AUTO_TEST_SUITE_END()
80
Davide Pesavento5b3cf762020-04-03 16:20:04 -040081} // namespace psync