blob: feca0da28945f6f1b43c9d787cfbec66a3f5c368 [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
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070010#include <boost/test/unit_test.hpp>
11
12namespace nfd {
13
14NFD_LOG_INIT("ManagerBaseTest");
15
16BOOST_AUTO_TEST_SUITE(MgmtManagerBase)
17
18class ManagerBaseTest : public ManagerBase
19{
20
21public:
22
23 ManagerBaseTest()
24 : ManagerBase(make_shared<InternalFace>()),
25 m_callbackFired(false)
26 {
27
28 }
29
30 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080031 testSetResponse(ControlResponse& response,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070032 uint32_t code,
33 const std::string& text)
34 {
35 setResponse(response, code, text);
36 }
37
38 void
39 testSendResponse(const Name& name,
40 uint32_t code,
41 const std::string& text)
42 {
43 sendResponse(name, code, text);
44 }
45
46 void
47 testSendResponse(const Name& name,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080048 const ControlResponse& response)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070049 {
50 sendResponse(name, response);
51 }
52
53 shared_ptr<InternalFace>
54 getInternalFace()
55 {
56 return ndn::ptr_lib::static_pointer_cast<InternalFace>(m_face);
57 }
58
59 void
60 validateControlResponse(const Data& response,
61 const Name& expectedName,
62 uint32_t expectedCode,
63 const std::string& expectedText)
64 {
65 m_callbackFired = true;
66 Block controlRaw = response.getContent().blockFromValue();
67
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080068 ControlResponse control;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070069 control.wireDecode(controlRaw);
70
71 NFD_LOG_DEBUG("received control response"
72 << " name: " << response.getName()
73 << " code: " << control.getCode()
74 << " text: " << control.getText());
75
76 BOOST_REQUIRE(response.getName() == expectedName);
77 BOOST_REQUIRE(control.getCode() == expectedCode);
78 BOOST_REQUIRE(control.getText() == expectedText);
79 }
80
81 bool
82 didCallbackFire()
83 {
84 return m_callbackFired;
85 }
86
87private:
88
89 bool m_callbackFired;
90
91};
92
93BOOST_FIXTURE_TEST_CASE(SetResponse, ManagerBaseTest)
94{
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080095 ControlResponse response(200, "OK");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070096
97 BOOST_CHECK_EQUAL(response.getCode(), 200);
98 BOOST_CHECK_EQUAL(response.getText(), "OK");
99
100 testSetResponse(response, 100, "test");
101
102 BOOST_CHECK_EQUAL(response.getCode(), 100);
103 BOOST_CHECK_EQUAL(response.getText(), "test");
104}
105
106
107BOOST_FIXTURE_TEST_CASE(SendResponse3Arg, ManagerBaseTest)
108{
109 getInternalFace()->onReceiveData +=
110 bind(&ManagerBaseTest::validateControlResponse, this, _1,
111 "/response", 100, "test");
112
113 testSendResponse("/response", 100, "test");
114 BOOST_REQUIRE(didCallbackFire());
115}
116
117
118BOOST_FIXTURE_TEST_CASE(SendResponse2Arg, ManagerBaseTest)
119{
120 getInternalFace()->onReceiveData +=
121 bind(&ManagerBaseTest::validateControlResponse, this, _1,
122 "/response", 100, "test");
123
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800124 ControlResponse response(100, "test");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700125
126 testSendResponse("/response", 100, "test");
127 BOOST_REQUIRE(didCallbackFire());
128}
129
130BOOST_AUTO_TEST_SUITE_END()
131
132} // namespace nfd
133
134
135
136
137
138
139