blob: 8f70402fd11417cb44bc8a6830630e946346bfdb [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);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700121 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700122
123 BOOST_REQUIRE(didOnInterestFire());
124 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700125}
126
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700127BOOST_AUTO_TEST_CASE(SendInterestHitBegin)
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);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700144 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700145
146 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700147}
148
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700149BOOST_AUTO_TEST_CASE(SendInterestHitExact)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700150{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700151 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700152
153 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700154
155 face->setInterestFilter("/localhost/nfd/eib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700156 bind(&InternalFaceFixture::validateNoOnInterestCallback,
157 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700158
159 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700160 bind(&InternalFaceFixture::validateOnInterestCallback,
161 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700162
163 face->setInterestFilter("/localhost/nfd/gib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700164 bind(&InternalFaceFixture::validateNoOnInterestCallback,
165 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700166
167 // generate command whose name exactly matches
168 // /localhost/nfd/fib
169
170 Name commandName("/localhost/nfd/fib");
171 Interest command(commandName);
172 face->sendInterest(command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700173 g_io.run_one();
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
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700179BOOST_AUTO_TEST_CASE(SendInterestHitPrevious)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700180{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700181 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700182
183 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700184
185 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700186 bind(&InternalFaceFixture::validateOnInterestCallback,
187 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700188
189 face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700190 bind(&InternalFaceFixture::validateNoOnInterestCallback,
191 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700192
193 // generate command whose name exactly matches
194 // an Interest filter
195
196 Name commandName("/localhost/nfd/fib/previous");
197 Interest command(commandName);
198 face->sendInterest(command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700199 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700200
201 BOOST_REQUIRE(didOnInterestFire());
202 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700203}
204
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700205BOOST_AUTO_TEST_SUITE_END()
206
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700207} // namespace tests
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700208} // namespace nfd