blob: f6ddcb77f55b34481fbf9cd3c754067256eb3031 [file] [log] [blame]
Steve DiBenedetto0b73f442014-02-05 22:02:03 -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/manager-base.hpp"
8#include "mgmt/internal-face.hpp"
9
Junxiao Shid9ee45c2014-02-27 15:38:11 -070010#include "tests/test-common.hpp"
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070011
12namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070013namespace tests {
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070014
15NFD_LOG_INIT("ManagerBaseTest");
16
Junxiao Shid9ee45c2014-02-27 15:38:11 -070017class ManagerBaseTest : public ManagerBase, protected BaseFixture
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070018{
19
20public:
21
22 ManagerBaseTest()
23 : ManagerBase(make_shared<InternalFace>()),
24 m_callbackFired(false)
25 {
26
27 }
28
29 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080030 testSetResponse(ControlResponse& response,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070031 uint32_t code,
32 const std::string& text)
33 {
34 setResponse(response, code, text);
35 }
36
37 void
38 testSendResponse(const Name& name,
39 uint32_t code,
40 const std::string& text)
41 {
42 sendResponse(name, code, text);
43 }
44
45 void
46 testSendResponse(const Name& name,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080047 const ControlResponse& response)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070048 {
49 sendResponse(name, response);
50 }
51
52 shared_ptr<InternalFace>
53 getInternalFace()
54 {
55 return ndn::ptr_lib::static_pointer_cast<InternalFace>(m_face);
56 }
57
58 void
59 validateControlResponse(const Data& response,
60 const Name& expectedName,
61 uint32_t expectedCode,
62 const std::string& expectedText)
63 {
64 m_callbackFired = true;
65 Block controlRaw = response.getContent().blockFromValue();
66
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080067 ControlResponse control;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070068 control.wireDecode(controlRaw);
69
70 NFD_LOG_DEBUG("received control response"
71 << " name: " << response.getName()
72 << " code: " << control.getCode()
73 << " text: " << control.getText());
74
75 BOOST_REQUIRE(response.getName() == expectedName);
76 BOOST_REQUIRE(control.getCode() == expectedCode);
77 BOOST_REQUIRE(control.getText() == expectedText);
78 }
79
80 bool
81 didCallbackFire()
82 {
83 return m_callbackFired;
84 }
85
86private:
87
88 bool m_callbackFired;
89
90};
91
Junxiao Shid9ee45c2014-02-27 15:38:11 -070092BOOST_FIXTURE_TEST_SUITE(MgmtManagerBase, ManagerBaseTest)
93
94BOOST_AUTO_TEST_CASE(SetResponse)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070095{
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080096 ControlResponse response(200, "OK");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070097
98 BOOST_CHECK_EQUAL(response.getCode(), 200);
99 BOOST_CHECK_EQUAL(response.getText(), "OK");
100
101 testSetResponse(response, 100, "test");
102
103 BOOST_CHECK_EQUAL(response.getCode(), 100);
104 BOOST_CHECK_EQUAL(response.getText(), "test");
105}
106
107
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700108BOOST_AUTO_TEST_CASE(SendResponse3Arg)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700109{
110 getInternalFace()->onReceiveData +=
111 bind(&ManagerBaseTest::validateControlResponse, this, _1,
112 "/response", 100, "test");
113
114 testSendResponse("/response", 100, "test");
115 BOOST_REQUIRE(didCallbackFire());
116}
117
118
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700119BOOST_AUTO_TEST_CASE(SendResponse2Arg)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700120{
121 getInternalFace()->onReceiveData +=
122 bind(&ManagerBaseTest::validateControlResponse, this, _1,
123 "/response", 100, "test");
124
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800125 ControlResponse response(100, "test");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700126
127 testSendResponse("/response", 100, "test");
128 BOOST_REQUIRE(didCallbackFire());
129}
130
131BOOST_AUTO_TEST_SUITE_END()
132
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700133} // namespace tests
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700134} // namespace nfd