Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 1 | /* -*- 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 Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 8 | #include "tests/face/dummy-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 9 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 10 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 11 | |
| 12 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 13 | namespace tests { |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 14 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 15 | NFD_LOG_INIT("InternalFaceTest"); |
| 16 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 17 | class InternalFaceFixture : protected BaseFixture |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 18 | { |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 19 | public: |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 20 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 21 | InternalFaceFixture() |
| 22 | : m_onInterestFired(false), |
| 23 | m_noOnInterestFired(false) |
| 24 | { |
| 25 | |
| 26 | } |
| 27 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 28 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 29 | 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 DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 41 | addFace(shared_ptr<Face> face) |
| 42 | { |
| 43 | m_faces.push_back(face); |
| 44 | } |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 45 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 46 | 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 DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 70 | private: |
| 71 | std::vector<shared_ptr<Face> > m_faces; |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 72 | bool m_onInterestFired; |
| 73 | bool m_noOnInterestFired; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 74 | }; |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 75 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 76 | BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture) |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 77 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 78 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 79 | validatePutData(bool& called, const Name& expectedName, const Data& data) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 80 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 81 | called = true; |
| 82 | BOOST_CHECK_EQUAL(expectedName, data.getName()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 85 | BOOST_AUTO_TEST_CASE(PutData) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 86 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 87 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 88 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 89 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 90 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 91 | bool didPutData = false; |
| 92 | Name dataName("/hello"); |
| 93 | face->onReceiveData += bind(&validatePutData, boost::ref(didPutData), dataName, _1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 94 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 95 | Data testData(dataName); |
| 96 | face->sign(testData); |
| 97 | face->put(testData); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 98 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 99 | BOOST_REQUIRE(didPutData); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 100 | |
| 101 | BOOST_CHECK_THROW(face->close(), InternalFace::Error); |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 104 | BOOST_AUTO_TEST_CASE(SendInterestHitEnd) |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 105 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 106 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 107 | |
| 108 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 109 | |
| 110 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 111 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 112 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 113 | |
| 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 DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 121 | |
| 122 | BOOST_REQUIRE(didOnInterestFire()); |
| 123 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 126 | BOOST_AUTO_TEST_CASE(SendInterestHitBegin) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 127 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 128 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 129 | |
| 130 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 131 | |
| 132 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 133 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 134 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 135 | |
| 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 DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 143 | |
| 144 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 147 | BOOST_AUTO_TEST_CASE(SendInterestHitExact) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 148 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 149 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 150 | |
| 151 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 152 | |
| 153 | face->setInterestFilter("/localhost/nfd/eib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 154 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 155 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 156 | |
| 157 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 158 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 159 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 160 | |
| 161 | face->setInterestFilter("/localhost/nfd/gib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 162 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 163 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 164 | |
| 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 DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 171 | |
| 172 | BOOST_REQUIRE(didOnInterestFire()); |
| 173 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 176 | BOOST_AUTO_TEST_CASE(SendInterestHitPrevious) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 177 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 178 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 179 | |
| 180 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 181 | |
| 182 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 183 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 184 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 185 | |
| 186 | face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 187 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 188 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 189 | |
| 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 DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 196 | |
| 197 | BOOST_REQUIRE(didOnInterestFire()); |
| 198 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 201 | BOOST_AUTO_TEST_SUITE_END() |
| 202 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 203 | } // namespace tests |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 204 | } // namespace nfd |