blob: 44f5e7b5ad01c6cdc0975b1d26f1b48d369393ee [file] [log] [blame]
Yanbiao Li4ee73d42015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "face/internal-face.hpp"
27#include "tests/test-common.hpp"
28
29namespace nfd {
30namespace tests {
31
32class InternalFaceFixture : protected BaseFixture
33{
34public:
35 InternalFaceFixture()
36 {
37 m_face.onReceiveInterest.connect([this] (const Interest& interest) {
38 inInterests.push_back(interest);
39 });
40 m_face.onSendInterest.connect([this] (const Interest& interest) {
41 outInterests.push_back(interest);
42 });
43 m_face.onReceiveData.connect([this] (const Data& data) {
44 inData.push_back(data);
45 });
46 m_face.onSendData.connect([this] (const Data& data) {
47 outData.push_back(data);
48 });
49 }
50
51protected:
52 InternalFace m_face;
53 std::vector<Interest> inInterests;
54 std::vector<Interest> outInterests;
55 std::vector<Data> inData;
56 std::vector<Data> outData;
57};
58
59BOOST_FIXTURE_TEST_SUITE(FaceInternalFace, InternalFaceFixture)
60
61BOOST_AUTO_TEST_CASE(SendInterest)
62{
63 BOOST_CHECK(outInterests.empty());
64
65 auto interest = makeInterest("/test/send/interest");
66 Block expectedBlock = interest->wireEncode(); // assign a value to nonce
67 m_face.sendInterest(*interest);
68
69 BOOST_CHECK_EQUAL(outInterests.size(), 1);
70 BOOST_CHECK(outInterests[0].wireEncode() == expectedBlock);
71}
72
73BOOST_AUTO_TEST_CASE(SendData)
74{
75 BOOST_CHECK(outData.empty());
76
77 auto data = makeData("/test/send/data");
78 m_face.sendData(*data);
79
80 BOOST_CHECK_EQUAL(outData.size(), 1);
81 BOOST_CHECK(outData[0].wireEncode() == data->wireEncode());
82}
83
84BOOST_AUTO_TEST_CASE(ReceiveInterest)
85{
86 BOOST_CHECK(inInterests.empty());
87
88 auto interest = makeInterest("/test/receive/interest");
89 Block expectedBlock = interest->wireEncode(); // assign a value to nonce
90 m_face.receiveInterest(*interest);
91
92 BOOST_CHECK_EQUAL(inInterests.size(), 1);
93 BOOST_CHECK(inInterests[0].wireEncode() == expectedBlock);
94}
95
96BOOST_AUTO_TEST_CASE(ReceiveData)
97{
98 BOOST_CHECK(inData.empty());
99
100 auto data = makeData("/test/send/data");
101 m_face.receiveData(*data);
102
103 BOOST_CHECK_EQUAL(inData.size(), 1);
104 BOOST_CHECK(inData[0].wireEncode() == data->wireEncode());
105}
106
107BOOST_AUTO_TEST_CASE(ReceiveBlock)
108{
109 BOOST_CHECK(inInterests.empty());
110 BOOST_CHECK(inData.empty());
111
112 Block interestBlock = makeInterest("test/receive/interest")->wireEncode();
113 m_face.receive(interestBlock);
114 BOOST_CHECK_EQUAL(inInterests.size(), 1);
115 BOOST_CHECK(inInterests[0].wireEncode() == interestBlock);
116
117 Block dataBlock = makeData("test/receive/data")->wireEncode();
118 m_face.receive(dataBlock);
119 BOOST_CHECK_EQUAL(inData.size(), 1);
120 BOOST_CHECK(inData[0].wireEncode() == dataBlock);
121}
122
123BOOST_AUTO_TEST_CASE(ExtractPacketFromBlock)
124{
125 {
126 Block block = makeInterest("/test/interest")->wireEncode();
127 const Block& payload = ndn::nfd::LocalControlHeader::getPayload(block);
128 auto interest = m_face.extractPacketFromBlock<Interest>(block, payload);
129 BOOST_CHECK(interest->wireEncode() == block);
130 }
131
132 {
133 Block block = makeData("/test/data")->wireEncode();
134 const Block& payload = ndn::nfd::LocalControlHeader::getPayload(block);
135 auto data = m_face.extractPacketFromBlock<Data>(block, payload);
136 BOOST_CHECK(data->wireEncode() == block);
137 }
138}
139
140BOOST_AUTO_TEST_SUITE_END()
141
142} // namespace tests
143} // namespace nfd