blob: 92dc680207845b02e641dcc59c8bc915e2c29444 [file] [log] [blame]
Steve DiBenedettoabe9e972014-02-20 15:37:04 -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/face-manager.hpp"
8#include "mgmt/internal-face.hpp"
9#include "face/face.hpp"
10#include "../face/dummy-face.hpp"
11#include "fw/face-table.hpp"
12#include "fw/forwarder.hpp"
13
14#include "common.hpp"
15#include "tests/test-common.hpp"
16
17namespace nfd {
18namespace tests {
19
20NFD_LOG_INIT("FaceManagerTest");
21
22class TestDummyFace : public DummyFace
23{
24public:
25
26 TestDummyFace()
27 : m_closeFired(false)
28 {
29
30 }
31
32 virtual
33 ~TestDummyFace()
34 {
35
36 }
37
38 virtual void
39 close()
40 {
41 m_closeFired = true;
42 }
43
44 bool
45 didCloseFire() const
46 {
47 return m_closeFired;
48 }
49
50private:
51 bool m_closeFired;
52};
53
54class TestFaceTable : public FaceTable
55{
56public:
57 TestFaceTable(Forwarder& forwarder)
58 : FaceTable(forwarder),
59 m_addFired(false),
60 m_removeFired(false),
61 m_getFired(false),
62 m_dummy(make_shared<TestDummyFace>())
63 {
64
65 }
66
67 virtual
68 ~TestFaceTable()
69 {
70
71 }
72
73 virtual void
74 add(shared_ptr<Face> face)
75 {
76 m_addFired = true;
77 }
78
79 virtual void
80 remove(shared_ptr<Face> face)
81 {
82 m_removeFired = true;
83 }
84
85 virtual shared_ptr<Face>
86 get(FaceId id) const
87 {
88 m_getFired = true;
89 return m_dummy;
90 }
91
92 bool
93 didAddFire() const
94 {
95 return m_addFired;
96 }
97
98 bool
99 didRemoveFire() const
100 {
101 return m_removeFired;
102 }
103
104 bool
105 didGetFire() const
106 {
107 return m_getFired;
108 }
109
110 void
111 reset()
112 {
113 m_addFired = false;
114 m_removeFired = false;
115 m_getFired = false;
116 }
117
118 shared_ptr<TestDummyFace>&
119 getDummyFace()
120 {
121 return m_dummy;
122 }
123
124private:
125 bool m_addFired;
126 bool m_removeFired;
127 mutable bool m_getFired;
128 shared_ptr<TestDummyFace> m_dummy;
129};
130
131
132class TestFaceTableFixture : public BaseFixture
133{
134public:
135 TestFaceTableFixture()
136 : m_faceTable(m_forwarder)
137 {
138
139 }
140
141 virtual
142 ~TestFaceTableFixture()
143 {
144
145 }
146
147protected:
148 Forwarder m_forwarder;
149 TestFaceTable m_faceTable;
150};
151
152class TestFaceManagerCommon
153{
154public:
155 TestFaceManagerCommon()
156 : m_face(make_shared<InternalFace>()),
157 m_callbackFired(false)
158 {
159
160 }
161
162 virtual
163 ~TestFaceManagerCommon()
164 {
165
166 }
167
168 shared_ptr<InternalFace>&
169 getFace()
170 {
171 return m_face;
172 }
173
174 void
175 validateControlResponseCommon(const Data& response,
176 const Name& expectedName,
177 uint32_t expectedCode,
178 const std::string& expectedText,
179 ControlResponse& control)
180 {
181 m_callbackFired = true;
182 Block controlRaw = response.getContent().blockFromValue();
183
184 control.wireDecode(controlRaw);
185
186 // NFD_LOG_DEBUG("received control response"
187 // << " Name: " << response.getName()
188 // << " code: " << control.getCode()
189 // << " text: " << control.getText());
190
191 BOOST_CHECK_EQUAL(response.getName(), expectedName);
192 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
193 BOOST_CHECK_EQUAL(control.getText(), expectedText);
194 }
195
196 void
197 validateControlResponse(const Data& response,
198 const Name& expectedName,
199 uint32_t expectedCode,
200 const std::string& expectedText)
201 {
202 ControlResponse control;
203 validateControlResponseCommon(response, expectedName,
204 expectedCode, expectedText, control);
205
206 if (!control.getBody().empty())
207 {
208 BOOST_FAIL("found unexpected control response body");
209 }
210 }
211
212 void
213 validateControlResponse(const Data& response,
214 const Name& expectedName,
215 uint32_t expectedCode,
216 const std::string& expectedText,
217 const Block& expectedBody)
218 {
219 ControlResponse control;
220 validateControlResponseCommon(response, expectedName,
221 expectedCode, expectedText, control);
222
223 BOOST_REQUIRE(!control.getBody().empty());
224 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
225
226 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
227 expectedBody.value_size()) == 0);
228
229 }
230
231 bool
232 didCallbackFire() const
233 {
234 return m_callbackFired;
235 }
236
237 void
238 resetCallbackFired()
239 {
240 m_callbackFired = false;
241 }
242
243protected:
244 shared_ptr<InternalFace> m_face;
245
246private:
247 bool m_callbackFired;
248};
249
250class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon
251{
252public:
253 FaceManagerFixture()
254 : m_manager(m_faceTable, m_face)
255 {
256 m_manager.setConfigFile(m_config);
257 }
258
259 void
260 parseConfig(const std::string configuration, bool isDryRun)
261 {
262 m_config.parse(configuration, isDryRun);
263 }
264
265 virtual
266 ~FaceManagerFixture()
267 {
268
269 }
270
271 FaceManager&
272 getManager()
273 {
274 return m_manager;
275 }
276
277 bool
278 didFaceTableAddFire() const
279 {
280 return m_faceTable.didAddFire();
281 }
282
283 bool
284 didFaceTableRemoveFire() const
285 {
286 return m_faceTable.didRemoveFire();
287 }
288
289 bool
290 didFaceTableGetFire() const
291 {
292 return m_faceTable.didGetFire();
293 }
294
295 void
296 resetFaceTable()
297 {
298 m_faceTable.reset();
299 }
300
301private:
302 FaceManager m_manager;
303 ConfigFile m_config;
304};
305
306BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture)
307
308bool
309isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage)
310{
311 if (error.what() != expectedMessage)
312 {
313 NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what());
314 }
315 return error.what() == expectedMessage;
316}
317
318BOOST_AUTO_TEST_CASE(TestProcessSectionUnix)
319{
320 const std::string CONFIG =
321 "face_system\n"
322 "{\n"
323 " unix\n"
324 " {\n"
325 " listen yes\n"
326 " path /tmp/nfd.sock\n"
327 " }\n"
328 "}\n";
329 BOOST_TEST_CHECKPOINT("Calling parse");
330 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
331}
332
333BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun)
334{
335 const std::string CONFIG =
336 "face_system\n"
337 "{\n"
338 " unix\n"
339 " {\n"
340 " listen yes\n"
341 " path /var/run/nfd.sock\n"
342 " }\n"
343 "}\n";
344
345 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
346}
347
348BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen)
349{
350 const std::string CONFIG =
351 "face_system\n"
352 "{\n"
353 " unix\n"
354 " {\n"
355 " listen hello\n"
356 " }\n"
357 "}\n";
358 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
359 bind(&isExpectedException, _1,
360 "Invalid value for option \"listen\" in \"unix\" section"));
361}
362
363BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption)
364{
365 const std::string CONFIG =
366 "face_system\n"
367 "{\n"
368 " unix\n"
369 " {\n"
370 " hello\n"
371 " }\n"
372 "}\n";
373 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
374 bind(&isExpectedException, _1,
375 "Unrecognized option \"hello\" in \"unix\" section"));
376}
377
378
379
380BOOST_AUTO_TEST_CASE(TestProcessSectionTcp)
381{
382 const std::string CONFIG =
383 "face_system\n"
384 "{\n"
385 " tcp\n"
386 " {\n"
387 " listen yes\n"
388 " port 6363\n"
389 " }\n"
390 "}\n";
391 try
392 {
393 parseConfig(CONFIG, false);
394 }
395 catch (const std::runtime_error& e)
396 {
397 const std::string reason = e.what();
398 if (reason.find("Address in use") != std::string::npos)
399 {
400 BOOST_FAIL(reason);
401 }
402 }
403}
404
405BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun)
406{
407 const std::string CONFIG =
408 "face_system\n"
409 "{\n"
410 " tcp\n"
411 " {\n"
412 " listen yes\n"
413 " port 6363\n"
414 " }\n"
415 "}\n";
416 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
417}
418
419BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen)
420{
421 const std::string CONFIG =
422 "face_system\n"
423 "{\n"
424 " tcp\n"
425 " {\n"
426 " listen hello\n"
427 " }\n"
428 "}\n";
429 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
430 bind(&isExpectedException, _1,
431 "Invalid value for option \"listen\" in \"tcp\" section"));
432}
433
434BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption)
435{
436 const std::string CONFIG =
437 "face_system\n"
438 "{\n"
439 " tcp\n"
440 " {\n"
441 " hello\n"
442 " }\n"
443 "}\n";
444 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
445 bind(&isExpectedException, _1,
446 "Unrecognized option \"hello\" in \"tcp\" section"));
447}
448
449BOOST_AUTO_TEST_CASE(TestProcessSectionUdp)
450{
451 const std::string CONFIG =
452 "face_system\n"
453 "{\n"
454 " udp\n"
455 " {\n"
456 " port 6363\n"
457 " idle_timeout 30\n"
458 " keep_alive_interval 25\n"
459 " mcast yes\n"
460 " mcast_port 56363\n"
461 " mcast_group 224.0.23.170\n"
462 " }\n"
463 "}\n";
464 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
465}
466
467BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun)
468{
469 const std::string CONFIG =
470 "face_system\n"
471 "{\n"
472 " udp\n"
473 " {\n"
474 " port 6363\n"
475 " idle_timeout 30\n"
476 " keep_alive_interval 25\n"
477 " mcast yes\n"
478 " mcast_port 56363\n"
479 " mcast_group 224.0.23.170\n"
480 " }\n"
481 "}\n";
482 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
483}
484
485BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout)
486{
487 const std::string CONFIG =
488 "face_system\n"
489 "{\n"
490 " udp\n"
491 " {\n"
492 " idle_timeout hello\n"
493 " }\n"
494 "}\n";
495
496 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
497 bind(&isExpectedException, _1,
498 "Invalid value for option \"idle_timeout\" in \"udp\" section"));
499}
500
501BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast)
502{
503 const std::string CONFIG =
504 "face_system\n"
505 "{\n"
506 " udp\n"
507 " {\n"
508 " mcast hello\n"
509 " }\n"
510 "}\n";
511
512 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
513 bind(&isExpectedException, _1,
514 "Invalid value for option \"mcast\" in \"udp\" section"));
515}
516
517BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup)
518{
519 const std::string CONFIG =
520 "face_system\n"
521 "{\n"
522 " udp\n"
523 " {\n"
524 " mcast no\n"
525 " mcast_port 50\n"
526 " mcast_group hello\n"
527 " }\n"
528 "}\n";
529
530 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
531 bind(&isExpectedException, _1,
532 "Invalid value for option \"mcast_group\" in \"udp\" section"));
533}
534
535BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6)
536{
537 const std::string CONFIG =
538 "face_system\n"
539 "{\n"
540 " udp\n"
541 " {\n"
542 " mcast no\n"
543 " mcast_port 50\n"
544 " mcast_group ::1\n"
545 " }\n"
546 "}\n";
547
548 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
549 bind(&isExpectedException, _1,
550 "Invalid value for option \"mcast_group\" in \"udp\" section"));
551}
552
553BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption)
554{
555 const std::string CONFIG =
556 "face_system\n"
557 "{\n"
558 " udp\n"
559 " {\n"
560 " hello\n"
561 " }\n"
562 "}\n";
563 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
564 bind(&isExpectedException, _1,
565 "Unrecognized option \"hello\" in \"udp\" section"));
566}
567
568BOOST_AUTO_TEST_CASE(TestProcessSectionEther)
569{
570 const std::string CONFIG =
571 "face_system\n"
572 "{\n"
573 " ether\n"
574 " {\n"
575 " mcast yes\n"
576 " mcast_group 01:00:5E:00:17:AA\n"
577 " }\n"
578 "}\n";
579
580 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
581}
582
583BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun)
584{
585 const std::string CONFIG =
586 "face_system\n"
587 "{\n"
588 " ether\n"
589 " {\n"
590 " mcast yes\n"
591 " mcast_group 01:00:5E:00:17:AA\n"
592 " }\n"
593 "}\n";
594
595 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
596}
597
598BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast)
599{
600 const std::string CONFIG =
601 "face_system\n"
602 "{\n"
603 " ether\n"
604 " {\n"
605 " mcast hello\n"
606 " }\n"
607 "}\n";
608
609 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
610 bind(&isExpectedException, _1,
611 "Invalid value for option \"mcast\" in \"ether\" section"));
612}
613
614BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup)
615{
616 const std::string CONFIG =
617 "face_system\n"
618 "{\n"
619 " ether\n"
620 " {\n"
621 " mcast yes\n"
622 " mcast_group\n"
623 " }\n"
624 "}\n";
625
626 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
627 bind(&isExpectedException, _1,
628 "Invalid value for option \"mcast_group\" in \"ether\" section"));
629}
630
631BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption)
632{
633 const std::string CONFIG =
634 "face_system\n"
635 "{\n"
636 " ether\n"
637 " {\n"
638 " hello\n"
639 " }\n"
640 "}\n";
641 BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error,
642 bind(&isExpectedException, _1,
643 "Unrecognized option \"hello\" in \"ether\" section"));
644}
645
646BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
647{
648 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
649
650 getFace()->onReceiveData +=
651 bind(&FaceManagerFixture::validateControlResponse, this, _1,
652 command->getName(), 400, "Malformed command");
653
654 getFace()->sendInterest(*command);
655
656 BOOST_REQUIRE(didCallbackFire());
657}
658
659BOOST_AUTO_TEST_CASE(MalformedCommmand)
660{
661 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces"));
662
663 getFace()->onReceiveData +=
664 bind(&FaceManagerFixture::validateControlResponse, this, _1,
665 command->getName(), 400, "Malformed command");
666
667 getManager().onFaceRequest(*command);
668
669 BOOST_REQUIRE(didCallbackFire());
670}
671
672/// \todo add tests for unsigned and unauthorized commands
673
674BOOST_AUTO_TEST_CASE(UnsupportedVerb)
675{
676 ndn::nfd::FaceManagementOptions options;
677
678 Block encodedOptions(options.wireEncode());
679
680 Name commandName("/localhost/nfd/faces");
681 commandName.append("unsupported");
682 commandName.append(encodedOptions);
683
684 shared_ptr<Interest> command(make_shared<Interest>(commandName));
685
686 getFace()->onReceiveData +=
687 bind(&FaceManagerFixture::validateControlResponse, this, _1,
688 command->getName(), 501, "Unsupported command");
689
690 getManager().onFaceRequest(*command);
691
692 BOOST_REQUIRE(didCallbackFire());
693}
694
695class ValidatedFaceRequestFixture : public TestFaceTableFixture,
696 public TestFaceManagerCommon,
697 public FaceManager
698{
699public:
700
701 ValidatedFaceRequestFixture()
702 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face),
703 m_createFaceFired(false),
704 m_destroyFaceFired(false)
705 {
706
707 }
708
709 virtual void
710 createFace(const Name& requestName,
711 ndn::nfd::FaceManagementOptions& options)
712 {
713 m_createFaceFired = true;
714 }
715
716 virtual void
717 destroyFace(const Name& requestName,
718 ndn::nfd::FaceManagementOptions& options)
719 {
720 m_destroyFaceFired = true;
721 }
722
723 virtual
724 ~ValidatedFaceRequestFixture()
725 {
726
727 }
728
729 bool
730 didCreateFaceFire() const
731 {
732 return m_createFaceFired;
733 }
734
735 bool
736 didDestroyFaceFire() const
737 {
738 return m_destroyFaceFired;
739 }
740
741private:
742 bool m_createFaceFired;
743 bool m_destroyFaceFired;
744};
745
746BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse, ValidatedFaceRequestFixture)
747{
748 Name commandName("/localhost/nfd/faces");
749 commandName.append("create");
750 commandName.append("NotReallyOptions");
751
752 shared_ptr<Interest> command(make_shared<Interest>(commandName));
753
754 getFace()->onReceiveData +=
755 bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1,
756 command->getName(), 400, "Malformed command");
757
758 onValidatedFaceRequest(command);
759
760 BOOST_REQUIRE(didCallbackFire());
761}
762
763BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace, ValidatedFaceRequestFixture)
764{
765 ndn::nfd::FaceManagementOptions options;
766 options.setUri("tcp://127.0.0.1");
767
768 Block encodedOptions(options.wireEncode());
769
770 Name commandName("/localhost/nfd/faces");
771 commandName.append("create");
772 commandName.append(encodedOptions);
773
774 shared_ptr<Interest> command(make_shared<Interest>(commandName));
775
776 onValidatedFaceRequest(command);
777 BOOST_CHECK(didCreateFaceFire());
778}
779
780BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace, ValidatedFaceRequestFixture)
781{
782 ndn::nfd::FaceManagementOptions options;
783 options.setUri("tcp://127.0.0.1");
784
785 Block encodedOptions(options.wireEncode());
786
787 Name commandName("/localhost/nfd/faces");
788 commandName.append("destroy");
789 commandName.append(encodedOptions);
790
791 shared_ptr<Interest> command(make_shared<Interest>(commandName));
792
793 onValidatedFaceRequest(command);
794 BOOST_CHECK(didDestroyFaceFire());
795}
796
797class FaceFixture : public TestFaceTableFixture,
798 public TestFaceManagerCommon,
799 public FaceManager
800{
801public:
802 FaceFixture()
803 : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face)
804 {
805
806 }
807
808 virtual
809 ~FaceFixture()
810 {
811
812 }
813};
814
815BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, FaceFixture)
816{
817 ndn::nfd::FaceManagementOptions options;
818 options.setUri("tcp:/127.0.0.1");
819
820 Block encodedOptions(options.wireEncode());
821
822 Name commandName("/localhost/nfd/faces");
823 commandName.append("create");
824 commandName.append(encodedOptions);
825
826 getFace()->onReceiveData +=
827 bind(&FaceFixture::validateControlResponse, this, _1,
828 commandName, 400, "Malformed command");
829
830 createFace(commandName, options);
831
832 BOOST_REQUIRE(didCallbackFire());
833}
834
835BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, FaceFixture)
836{
837 ndn::nfd::FaceManagementOptions options;
838 // this will be an unsupported protocol because no factories have been
839 // added to the face manager
840 options.setUri("tcp://127.0.0.1");
841
842 Block encodedOptions(options.wireEncode());
843
844 Name commandName("/localhost/nfd/faces");
845 commandName.append("create");
846 commandName.append(encodedOptions);
847
848 getFace()->onReceiveData +=
849 bind(&FaceFixture::validateControlResponse, this, _1,
850 commandName, 501, "Unsupported protocol");
851
852 createFace(commandName, options);
853
854 BOOST_REQUIRE(didCallbackFire());
855}
856
857BOOST_FIXTURE_TEST_CASE(OnCreated, FaceFixture)
858{
859 ndn::nfd::FaceManagementOptions options;
860 options.setUri("tcp://127.0.0.1");
861
862 Block encodedOptions(options.wireEncode());
863
864 Name commandName("/localhost/nfd/faces");
865 commandName.append("create");
866 commandName.append(encodedOptions);
867
868 ndn::nfd::FaceManagementOptions resultOptions;
869 resultOptions.setUri("tcp://127.0.0.1");
870 resultOptions.setFaceId(-1);
871
872 Block encodedResultOptions(resultOptions.wireEncode());
873
874 getFace()->onReceiveData +=
875 bind(&FaceFixture::validateControlResponse, this, _1,
876 commandName, 200, "Success", encodedResultOptions);
877
878 onCreated(commandName, options, make_shared<DummyFace>());
879
880 BOOST_REQUIRE(didCallbackFire());
881 BOOST_CHECK(TestFaceTableFixture::m_faceTable.didAddFire());
882}
883
884BOOST_FIXTURE_TEST_CASE(OnConnectFailed, FaceFixture)
885{
886 ndn::nfd::FaceManagementOptions options;
887 options.setUri("tcp://127.0.0.1");
888
889 Block encodedOptions(options.wireEncode());
890
891 Name commandName("/localhost/nfd/faces");
892 commandName.append("create");
893 commandName.append(encodedOptions);
894
895 getFace()->onReceiveData +=
896 bind(&FaceFixture::validateControlResponse, this, _1,
897 commandName, 400, "Failed to create face");
898
899 onConnectFailed(commandName, "unit-test-reason");
900
901 BOOST_REQUIRE(didCallbackFire());
902 BOOST_CHECK_EQUAL(TestFaceTableFixture::m_faceTable.didAddFire(), false);
903}
904
905
906BOOST_FIXTURE_TEST_CASE(DestroyFace, FaceFixture)
907{
908 ndn::nfd::FaceManagementOptions options;
909 options.setUri("tcp://127.0.0.1");
910
911 Block encodedOptions(options.wireEncode());
912
913 Name commandName("/localhost/nfd/faces");
914 commandName.append("destroy");
915 commandName.append(encodedOptions);
916
917 getFace()->onReceiveData +=
918 bind(&FaceFixture::validateControlResponse, this, _1,
919 commandName, 200, "Success");
920
921 destroyFace(commandName, options);
922
923 BOOST_REQUIRE(didCallbackFire());
924 BOOST_CHECK(TestFaceTableFixture::m_faceTable.didRemoveFire());
925 BOOST_CHECK(TestFaceTableFixture::m_faceTable.getDummyFace()->didCloseFire());
926}
927
928BOOST_AUTO_TEST_SUITE_END()
929
930} // namespace tests
931} // namespace nfd
932