blob: 52eaa23499560a2070e77a35e6cdee4153ea9ee3 [file] [log] [blame]
Steve DiBenedetto5b433982014-01-29 17:14:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "mgmt/internal-face.hpp"
Steve DiBenedetto3970c892014-01-31 23:31:13 -07008#include "../face/dummy-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07009
Steve DiBenedetto5b433982014-01-29 17:14:27 -070010#include <boost/test/unit_test.hpp>
11
12namespace nfd {
13
Steve DiBenedetto3970c892014-01-31 23:31:13 -070014NFD_LOG_INIT("InternalFaceTest");
15
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070016class InternalFaceFixture
Steve DiBenedetto3970c892014-01-31 23:31:13 -070017{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070018public:
Steve DiBenedetto3970c892014-01-31 23:31:13 -070019
Steve DiBenedettobdedce92014-02-02 22:49:39 -070020 InternalFaceFixture()
21 : m_onInterestFired(false),
22 m_noOnInterestFired(false)
23 {
24
25 }
26
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070027 void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070028 validateOnInterestCallback(const Name& name, const Interest& interest)
29 {
30 m_onInterestFired = true;
31 }
32
33 void
34 validateNoOnInterestCallback(const Name& name, const Interest& interest)
35 {
36 m_noOnInterestFired = true;
37 }
38
39 void
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070040 addFace(shared_ptr<Face> face)
41 {
42 m_faces.push_back(face);
43 }
Steve DiBenedetto3970c892014-01-31 23:31:13 -070044
Steve DiBenedettobdedce92014-02-02 22:49:39 -070045 bool
46 didOnInterestFire()
47 {
48 return m_onInterestFired;
49 }
50
51 bool
52 didNoOnInterestFire()
53 {
54 return m_noOnInterestFired;
55 }
56
57 void
58 resetOnInterestFired()
59 {
60 m_onInterestFired = false;
61 }
62
63 void
64 resetNoOnInterestFired()
65 {
66 m_noOnInterestFired = false;
67 }
68
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070069private:
70 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -070071 bool m_onInterestFired;
72 bool m_noOnInterestFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070073};
Steve DiBenedetto3970c892014-01-31 23:31:13 -070074
Steve DiBenedetto5b433982014-01-29 17:14:27 -070075BOOST_AUTO_TEST_SUITE(MgmtInternalFace)
76
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070077void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070078validatePutData(bool& called, const Name& expectedName, const Data& data)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070079{
Steve DiBenedettobdedce92014-02-02 22:49:39 -070080 called = true;
81 BOOST_CHECK_EQUAL(expectedName, data.getName());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070082}
83
Steve DiBenedettobdedce92014-02-02 22:49:39 -070084BOOST_FIXTURE_TEST_CASE(PutData, InternalFaceFixture)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070085{
Steve DiBenedettobdedce92014-02-02 22:49:39 -070086 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070087
Steve DiBenedetto3970c892014-01-31 23:31:13 -070088 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070089
Steve DiBenedettobdedce92014-02-02 22:49:39 -070090 bool didPutData = false;
91 Name dataName("/hello");
92 face->onReceiveData += bind(&validatePutData, boost::ref(didPutData), dataName, _1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070093
Steve DiBenedettobdedce92014-02-02 22:49:39 -070094 Data testData(dataName);
95 face->sign(testData);
96 face->put(testData);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070097
Steve DiBenedettobdedce92014-02-02 22:49:39 -070098 BOOST_REQUIRE(didPutData);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080099
100 BOOST_CHECK_THROW(face->close(), InternalFace::Error);
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700101}
102
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700103BOOST_FIXTURE_TEST_CASE(SendInterestHitEnd, InternalFaceFixture)
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700104{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700105 addFace(make_shared<DummyFace>());
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700106
107 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700108
109 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700110 bind(&InternalFaceFixture::validateOnInterestCallback,
111 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700112
113 // generate command whose name is canonically
114 // ordered after /localhost/nfd/fib so that
115 // we hit the end of the std::map
116
117 Name commandName("/localhost/nfd/fib/end");
118 Interest command(commandName);
119 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700120
121 BOOST_REQUIRE(didOnInterestFire());
122 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700123}
124
125
126
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700127BOOST_FIXTURE_TEST_CASE(SendInterestHitBegin, InternalFaceFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700128{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700129 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700130
131 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700132
133 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700134 bind(&InternalFaceFixture::validateNoOnInterestCallback,
135 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700136
137 // generate command whose name is canonically
138 // ordered before /localhost/nfd/fib so that
139 // we hit the beginning of the std::map
140
141 Name commandName("/localhost/nfd");
142 Interest command(commandName);
143 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700144
145 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700146}
147
148
149
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700150BOOST_FIXTURE_TEST_CASE(SendInterestHitExact, InternalFaceFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700151{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700152 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700153
154 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700155
156 face->setInterestFilter("/localhost/nfd/eib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700157 bind(&InternalFaceFixture::validateNoOnInterestCallback,
158 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700159
160 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700161 bind(&InternalFaceFixture::validateOnInterestCallback,
162 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700163
164 face->setInterestFilter("/localhost/nfd/gib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700165 bind(&InternalFaceFixture::validateNoOnInterestCallback,
166 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700167
168 // generate command whose name exactly matches
169 // /localhost/nfd/fib
170
171 Name commandName("/localhost/nfd/fib");
172 Interest command(commandName);
173 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700174
175 BOOST_REQUIRE(didOnInterestFire());
176 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700177}
178
179
180
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700181BOOST_FIXTURE_TEST_CASE(SendInterestHitPrevious, InternalFaceFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700182{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700183 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700184
185 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700186
187 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700188 bind(&InternalFaceFixture::validateOnInterestCallback,
189 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700190
191 face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700192 bind(&InternalFaceFixture::validateNoOnInterestCallback,
193 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700194
195 // generate command whose name exactly matches
196 // an Interest filter
197
198 Name commandName("/localhost/nfd/fib/previous");
199 Interest command(commandName);
200 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700201
202 BOOST_REQUIRE(didOnInterestFire());
203 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700204}
205
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700206BOOST_AUTO_TEST_SUITE_END()
207
208} // namespace nfd