blob: 79ee495ad5ef12f528ce469a04e4bf2f556a1181 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento03426ef2022-09-23 19:49:10 -04003 * Copyright (c) 2014-2022, 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/util/dummy-client-face.hpp>
26
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050027namespace psync {
28
29using namespace ndn;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050030
31BOOST_AUTO_TEST_SUITE(TestConsumer)
32
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050033BOOST_AUTO_TEST_CASE(AddSubscription)
34{
Davide Pesavento03426ef2022-09-23 19:49:10 -040035 util::DummyClientFace face;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050036 Consumer consumer(Name("/psync"), face,
Davide Pesavento5b3cf762020-04-03 16:20:04 -040037 [] (const auto&) {},
38 [] (const auto&) {},
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050039 40, 0.001);
40
41 Name subscription("test");
42
43 BOOST_CHECK(!consumer.isSubscribed(subscription));
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070044 BOOST_CHECK(consumer.addSubscription(subscription, 0));
45 BOOST_CHECK(!consumer.addSubscription(subscription, 0));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050046}
47
Davide Pesaventof91d1df2020-11-25 14:50:41 -050048BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070049{
Davide Pesavento03426ef2022-09-23 19:49:10 -040050 util::DummyClientFace face(m_io);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070051 Consumer consumer(Name("/psync"), face,
Davide Pesavento5b3cf762020-04-03 16:20:04 -040052 [] (const auto&) {},
53 [] (const auto&) {},
Davide Pesaventof91d1df2020-11-25 14:50:41 -050054 40, 0.001, 4_s, 4_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070055
56 consumer.sendHelloInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070057 advanceClocks(4_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070058 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
59 face.sentInterests.clear();
60 consumer.stop();
61
Davide Pesaventof91d1df2020-11-25 14:50:41 -050062 consumer.m_iblt = Name("test");
Ashlesh Gawande584e1202019-05-19 16:15:33 -070063 consumer.sendSyncInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070064 advanceClocks(3999_ms);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070065 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
66 consumer.stop();
67}
68
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050069BOOST_AUTO_TEST_SUITE_END()
70
Davide Pesavento5b3cf762020-04-03 16:20:04 -040071} // namespace psync