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); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 121 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 122 | |
| 123 | BOOST_REQUIRE(didOnInterestFire()); |
| 124 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 127 | BOOST_AUTO_TEST_CASE(SendInterestHitBegin) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 128 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 129 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 130 | |
| 131 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 132 | |
| 133 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 134 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 135 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 136 | |
| 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 Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 144 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 145 | |
| 146 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 149 | BOOST_AUTO_TEST_CASE(SendInterestHitExact) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 150 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 151 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 152 | |
| 153 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 154 | |
| 155 | face->setInterestFilter("/localhost/nfd/eib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 156 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 157 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 158 | |
| 159 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 160 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 161 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 162 | |
| 163 | face->setInterestFilter("/localhost/nfd/gib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 164 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 165 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 166 | |
| 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 Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 173 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 174 | |
| 175 | BOOST_REQUIRE(didOnInterestFire()); |
| 176 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 179 | BOOST_AUTO_TEST_CASE(SendInterestHitPrevious) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 180 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 181 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 182 | |
| 183 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 184 | |
| 185 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 186 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 187 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 188 | |
| 189 | face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 190 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 191 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 192 | |
| 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 Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 199 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 200 | |
| 201 | BOOST_REQUIRE(didOnInterestFire()); |
| 202 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 205 | BOOST_AUTO_TEST_SUITE_END() |
| 206 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 207 | } // namespace tests |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 208 | } // namespace nfd |