blob: 1d45910f7d485d1a0a7d57080c32ca9292c7ff90 [file] [log] [blame]
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -07001/* -*- 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"
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -070024
25#include "boost-test.hpp"
Junxiao Shia60d9362014-11-12 09:38:21 -070026#include "util/dummy-client-face.hpp"
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -070027
28namespace ndn {
29namespace tests {
30
Junxiao Shia60d9362014-11-12 09:38:21 -070031using ndn::util::DummyClientFace;
32using ndn::util::makeDummyClientFace;
33
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -070034BOOST_AUTO_TEST_SUITE(TestsFace)
35
36class Fixture
37{
38public:
39 Fixture()
40 : face(makeDummyClientFace())
41 , nData(0)
42 , nTimeouts(0)
43 {
44 }
45
46 void
47 onData()
48 {
49 ++nData;
50 }
51
52 void
53 onTimeout()
54 {
55 ++nTimeouts;
56 }
57
58public:
59 shared_ptr<DummyClientFace> face;
60 uint32_t nData;
61 uint32_t nTimeouts;
62};
63
64BOOST_FIXTURE_TEST_CASE(ExpressInterest, Fixture)
65{
66 face->expressInterest(Interest("/test/interest", time::seconds(10)),
67 bind(&Fixture::onData, this),
68 bind(&Fixture::onTimeout, this));
69 face->processEvents(time::milliseconds(100));
70
Junxiao Shia60d9362014-11-12 09:38:21 -070071 BOOST_CHECK_EQUAL(face->sentInterests.size(), 1);
72 BOOST_CHECK_EQUAL(face->sentDatas.size(), 0);
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -070073}
74
75BOOST_FIXTURE_TEST_CASE(RemovePendingInterest, Fixture)
76{
77 const PendingInterestId* interestId =
78 face->expressInterest(Interest("/test/interest", time::seconds(10)),
79 bind(&Fixture::onData, this),
80 bind(&Fixture::onTimeout, this));
81
82 shared_ptr<Data> data = make_shared<Data>("/test/interest/replied");
83 const uint8_t buffer[] = "Hello, world!";
84 data->setContent(buffer, sizeof(buffer));
85 KeyChain keyChain;
86 keyChain.sign(*data);
87 face->receive(*data);
88
89 face->removePendingInterest(interestId);
90 face->processEvents(time::milliseconds(100));
91 BOOST_CHECK_EQUAL(nData, 0);
92 BOOST_CHECK_EQUAL(nTimeouts, 0);
93}
94
95BOOST_AUTO_TEST_SUITE_END()
96
97} // namespace tests
98} // namespace ndn