Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Ashlesh Gawande | 5a89547 | 2020-01-25 18:07:32 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | * |
| 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 9 | * of the GNU Lesser General Public License as published by the Free Software Foundation, |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 10 | * 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 14 | * PURPOSE. See the GNU Lesser General Public License for more details. |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 15 | * |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public License along with |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 18 | */ |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/consumer.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 21 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 22 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 23 | #include "tests/io-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 24 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 25 | #include <ndn-cxx/name.hpp> |
| 26 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 27 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 28 | namespace psync { |
| 29 | |
| 30 | using namespace ndn; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(TestConsumer) |
| 33 | |
| 34 | BOOST_AUTO_TEST_CASE(Constructor) |
| 35 | { |
| 36 | util::DummyClientFace face({true, true}); |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 37 | BOOST_REQUIRE_NO_THROW(Consumer(Name("/psync"), face, |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 38 | [] (const auto&) {}, |
| 39 | [] (const auto&) {}, |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 40 | 40, 0.001)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | BOOST_AUTO_TEST_CASE(AddSubscription) |
| 44 | { |
| 45 | util::DummyClientFace face({true, true}); |
| 46 | Consumer consumer(Name("/psync"), face, |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 47 | [] (const auto&) {}, |
| 48 | [] (const auto&) {}, |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 49 | 40, 0.001); |
| 50 | |
| 51 | Name subscription("test"); |
| 52 | |
| 53 | BOOST_CHECK(!consumer.isSubscribed(subscription)); |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 54 | BOOST_CHECK(consumer.addSubscription(subscription, 0)); |
| 55 | BOOST_CHECK(!consumer.addSubscription(subscription, 0)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 58 | BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture) |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 59 | { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 60 | util::DummyClientFace face(m_io, {true, true}); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 61 | Consumer consumer(Name("/psync"), face, |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 62 | [] (const auto&) {}, |
| 63 | [] (const auto&) {}, |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 64 | 40, 0.001, 4_s, 4_s); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 65 | |
| 66 | consumer.sendHelloInterest(); |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 67 | advanceClocks(4_s); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 69 | face.sentInterests.clear(); |
| 70 | consumer.stop(); |
| 71 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 72 | consumer.m_iblt = Name("test"); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 73 | consumer.sendSyncInterest(); |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 74 | advanceClocks(3999_ms); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 76 | consumer.stop(); |
| 77 | } |
| 78 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 79 | BOOST_AUTO_TEST_SUITE_END() |
| 80 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 81 | } // namespace psync |