blob: f4d51caad91899584f6871f5e817ae076707ac03 [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"
Junxiao Shid9ee45c2014-02-27 15:38:11 -07008#include "tests/face/dummy-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07009
Junxiao Shid9ee45c2014-02-27 15:38:11 -070010#include "tests/test-common.hpp"
Steve DiBenedetto5b433982014-01-29 17:14:27 -070011
12namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070013namespace tests {
Steve DiBenedetto5b433982014-01-29 17:14:27 -070014
Steve DiBenedetto3970c892014-01-31 23:31:13 -070015NFD_LOG_INIT("InternalFaceTest");
16
Junxiao Shid9ee45c2014-02-27 15:38:11 -070017class InternalFaceFixture : protected BaseFixture
Steve DiBenedetto3970c892014-01-31 23:31:13 -070018{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070019public:
Steve DiBenedetto3970c892014-01-31 23:31:13 -070020
Steve DiBenedettobdedce92014-02-02 22:49:39 -070021 InternalFaceFixture()
22 : m_onInterestFired(false),
23 m_noOnInterestFired(false)
24 {
25
26 }
27
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070028 void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070029 validateOnInterestCallback(const Name& name, const Interest& interest)
30 {
31 m_onInterestFired = true;
32 }
33
34 void
35 validateNoOnInterestCallback(const Name& name, const Interest& interest)
36 {
37 m_noOnInterestFired = true;
38 }
39
40 void
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070041 addFace(shared_ptr<Face> face)
42 {
43 m_faces.push_back(face);
44 }
Steve DiBenedetto3970c892014-01-31 23:31:13 -070045
Steve DiBenedettobdedce92014-02-02 22:49:39 -070046 bool
47 didOnInterestFire()
48 {
49 return m_onInterestFired;
50 }
51
52 bool
53 didNoOnInterestFire()
54 {
55 return m_noOnInterestFired;
56 }
57
58 void
59 resetOnInterestFired()
60 {
61 m_onInterestFired = false;
62 }
63
64 void
65 resetNoOnInterestFired()
66 {
67 m_noOnInterestFired = false;
68 }
69
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070070private:
71 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -070072 bool m_onInterestFired;
73 bool m_noOnInterestFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070074};
Steve DiBenedetto3970c892014-01-31 23:31:13 -070075
Junxiao Shid9ee45c2014-02-27 15:38:11 -070076BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture)
Steve DiBenedetto5b433982014-01-29 17:14:27 -070077
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070078void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070079validatePutData(bool& called, const Name& expectedName, const Data& data)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070080{
Steve DiBenedettobdedce92014-02-02 22:49:39 -070081 called = true;
82 BOOST_CHECK_EQUAL(expectedName, data.getName());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070083}
84
Junxiao Shid9ee45c2014-02-27 15:38:11 -070085BOOST_AUTO_TEST_CASE(PutData)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070086{
Steve DiBenedettobdedce92014-02-02 22:49:39 -070087 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070088
Steve DiBenedetto3970c892014-01-31 23:31:13 -070089 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070090
Steve DiBenedettobdedce92014-02-02 22:49:39 -070091 bool didPutData = false;
92 Name dataName("/hello");
93 face->onReceiveData += bind(&validatePutData, boost::ref(didPutData), dataName, _1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070094
Steve DiBenedettobdedce92014-02-02 22:49:39 -070095 Data testData(dataName);
96 face->sign(testData);
97 face->put(testData);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070098
Steve DiBenedettobdedce92014-02-02 22:49:39 -070099 BOOST_REQUIRE(didPutData);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800100
101 BOOST_CHECK_THROW(face->close(), InternalFace::Error);
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700102}
103
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700104BOOST_AUTO_TEST_CASE(SendInterestHitEnd)
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700105{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700106 addFace(make_shared<DummyFace>());
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700107
108 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700109
110 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700111 bind(&InternalFaceFixture::validateOnInterestCallback,
112 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700113
114 // generate command whose name is canonically
115 // ordered after /localhost/nfd/fib so that
116 // we hit the end of the std::map
117
118 Name commandName("/localhost/nfd/fib/end");
119 Interest command(commandName);
120 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700121
122 BOOST_REQUIRE(didOnInterestFire());
123 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700124}
125
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700126BOOST_AUTO_TEST_CASE(SendInterestHitBegin)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700127{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700128 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700129
130 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700131
132 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700133 bind(&InternalFaceFixture::validateNoOnInterestCallback,
134 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700135
136 // generate command whose name is canonically
137 // ordered before /localhost/nfd/fib so that
138 // we hit the beginning of the std::map
139
140 Name commandName("/localhost/nfd");
141 Interest command(commandName);
142 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700143
144 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700145}
146
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700147BOOST_AUTO_TEST_CASE(SendInterestHitExact)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700148{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700149 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700150
151 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700152
153 face->setInterestFilter("/localhost/nfd/eib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700154 bind(&InternalFaceFixture::validateNoOnInterestCallback,
155 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700156
157 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700158 bind(&InternalFaceFixture::validateOnInterestCallback,
159 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700160
161 face->setInterestFilter("/localhost/nfd/gib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700162 bind(&InternalFaceFixture::validateNoOnInterestCallback,
163 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700164
165 // generate command whose name exactly matches
166 // /localhost/nfd/fib
167
168 Name commandName("/localhost/nfd/fib");
169 Interest command(commandName);
170 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700171
172 BOOST_REQUIRE(didOnInterestFire());
173 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700174}
175
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700176BOOST_AUTO_TEST_CASE(SendInterestHitPrevious)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700177{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700178 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700179
180 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700181
182 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700183 bind(&InternalFaceFixture::validateOnInterestCallback,
184 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700185
186 face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700187 bind(&InternalFaceFixture::validateNoOnInterestCallback,
188 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700189
190 // generate command whose name exactly matches
191 // an Interest filter
192
193 Name commandName("/localhost/nfd/fib/previous");
194 Interest command(commandName);
195 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700196
197 BOOST_REQUIRE(didOnInterestFire());
198 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700199}
200
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700201BOOST_AUTO_TEST_SUITE_END()
202
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700203} // namespace tests
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700204} // namespace nfd