Alexander Afanasyev | 6fcdde2 | 2014-08-22 19:03:36 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "face.hpp" |
| 23 | #include "security/key-chain.hpp" |
| 24 | #include "dummy-client-face.hpp" |
| 25 | |
| 26 | #include "boost-test.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace tests { |
| 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(TestsFace) |
| 32 | |
| 33 | class Fixture |
| 34 | { |
| 35 | public: |
| 36 | Fixture() |
| 37 | : face(makeDummyClientFace()) |
| 38 | , nData(0) |
| 39 | , nTimeouts(0) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | onData() |
| 45 | { |
| 46 | ++nData; |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | onTimeout() |
| 51 | { |
| 52 | ++nTimeouts; |
| 53 | } |
| 54 | |
| 55 | public: |
| 56 | shared_ptr<DummyClientFace> face; |
| 57 | uint32_t nData; |
| 58 | uint32_t nTimeouts; |
| 59 | }; |
| 60 | |
| 61 | BOOST_FIXTURE_TEST_CASE(ExpressInterest, Fixture) |
| 62 | { |
| 63 | face->expressInterest(Interest("/test/interest", time::seconds(10)), |
| 64 | bind(&Fixture::onData, this), |
| 65 | bind(&Fixture::onTimeout, this)); |
| 66 | face->processEvents(time::milliseconds(100)); |
| 67 | |
| 68 | BOOST_CHECK_EQUAL(face->m_sentInterests.size(), 1); |
| 69 | BOOST_CHECK_EQUAL(face->m_sentDatas.size(), 0); |
| 70 | } |
| 71 | |
| 72 | BOOST_FIXTURE_TEST_CASE(RemovePendingInterest, Fixture) |
| 73 | { |
| 74 | const PendingInterestId* interestId = |
| 75 | face->expressInterest(Interest("/test/interest", time::seconds(10)), |
| 76 | bind(&Fixture::onData, this), |
| 77 | bind(&Fixture::onTimeout, this)); |
| 78 | |
| 79 | shared_ptr<Data> data = make_shared<Data>("/test/interest/replied"); |
| 80 | const uint8_t buffer[] = "Hello, world!"; |
| 81 | data->setContent(buffer, sizeof(buffer)); |
| 82 | KeyChain keyChain; |
| 83 | keyChain.sign(*data); |
| 84 | face->receive(*data); |
| 85 | |
| 86 | face->removePendingInterest(interestId); |
| 87 | face->processEvents(time::milliseconds(100)); |
| 88 | BOOST_CHECK_EQUAL(nData, 0); |
| 89 | BOOST_CHECK_EQUAL(nTimeouts, 0); |
| 90 | } |
| 91 | |
| 92 | BOOST_AUTO_TEST_SUITE_END() |
| 93 | |
| 94 | } // namespace tests |
| 95 | } // namespace ndn |