PageRenderTime 75ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/test/common/protocols/monitor/getentriesresponse.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 403 lines | 185 code | 50 blank | 168 comment | 2 complexity | 88332057006995780e5efacdba4477b4 MD5 | raw file
  1. /*
  2. * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file test/common/protocols/monitor/getentriesresponse.cpp
  18. * @author Zofia Abramowska <z.abramowska@samsung.com>
  19. * @version 1.0
  20. * @brief Tests for Cynara::MonitorGetEntriesResponse usage in
  21. * Cynara::ProtocolMonitorGet
  22. */
  23. #include <limits>
  24. #include <vector>
  25. #include <gtest/gtest.h>
  26. #include <cynara-limits.h>
  27. #include <protocol/ProtocolMonitorGet.h>
  28. #include <response/MonitorGetEntriesResponse.h>
  29. #include <types/Policy.h>
  30. #include <cynara-error.h>
  31. #include "../../helpers.h"
  32. #include <ResponseTestHelper.h>
  33. #include <TestDataCollection.h>
  34. namespace {
  35. template <class T, class M> M get_member_type(M T:: *);
  36. const int64_t TV_SEC_MIN = 0;
  37. const int64_t TV_SEC_1 = 1;
  38. const int64_t TV_SEC_MAX = std::numeric_limits<decltype(get_member_type(&timespec::tv_sec))>::max();
  39. const int64_t TV_SEC_HALF = (TV_SEC_MAX - TV_SEC_MIN) / 2;
  40. const int64_t TV_NSEC_MIN = 0;
  41. const int64_t TV_NSEC_1 = 1;
  42. const int64_t TV_NSEC_MAX =
  43. std::numeric_limits<decltype(get_member_type(&timespec::tv_nsec))>::max();
  44. const int64_t TV_NSEC_HALF = (TV_SEC_MAX - TV_SEC_MIN) / 2;
  45. template<>
  46. void compare(const Cynara::MonitorGetEntriesResponse &req1,
  47. const Cynara::MonitorGetEntriesResponse &req2) {
  48. EXPECT_EQ(req1.entries(), req2.entries());
  49. }
  50. } /* namespace anonymous */
  51. using namespace Cynara;
  52. using namespace ResponseTestHelper;
  53. using namespace TestDataCollection;
  54. /* *** compare by objects test cases *** */
  55. /**
  56. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  57. * PolicyKey, result is allowed and timespec consist of minimum values
  58. * @test Expected result:
  59. * - policy key contains {c, u, p}
  60. * - result is allowed
  61. * - sec is minimal, nsec is minimal
  62. */
  63. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse01) {
  64. std::vector<MonitorEntry> entries = {
  65. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MIN, TV_NSEC_MIN})
  66. };
  67. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min);
  68. auto protocol = std::make_shared<ProtocolMonitorGet>();
  69. testResponse(response, protocol);
  70. }
  71. /**
  72. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  73. * PolicyKey, result is denied and timespec consist of medium sec and minimal nsec
  74. * @test Expected result:
  75. * - policy key contains {c, u, p}
  76. * - result is denied
  77. * - sec is medium, nsec is minimal
  78. */
  79. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse02) {
  80. std::vector<MonitorEntry> entries = {
  81. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_HALF, TV_NSEC_MIN})
  82. };
  83. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_1);
  84. auto protocol = std::make_shared<ProtocolMonitorGet>();
  85. testResponse(response, protocol);
  86. }
  87. /**
  88. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  89. * PolicyKey, result is allowed and timespec consist of medium values
  90. * @test Expected result:
  91. * - policy key contains {c, u, p}
  92. * - result is allowed
  93. * - sec is medium, nsec is medium
  94. */
  95. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse03) {
  96. std::vector<MonitorEntry> entries = {
  97. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_HALF, TV_NSEC_HALF})
  98. };
  99. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
  100. auto protocol = std::make_shared<ProtocolMonitorGet>();
  101. testResponse(response, protocol);
  102. }
  103. /**
  104. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  105. * PolicyKey, result is denied and timespec consist of maxium sec and medium nsec
  106. * @test Expected result:
  107. * - policy key contains {amanda, to, troll}
  108. * - result is denied
  109. * - sec is maximum, nsec is medium
  110. */
  111. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse04) {
  112. std::vector<MonitorEntry> entries = {
  113. MonitorEntry(Keys::k_cup2, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_HALF})
  114. };
  115. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::mid);
  116. auto protocol = std::make_shared<ProtocolMonitorGet>();
  117. testResponse(response, protocol);
  118. }
  119. /**
  120. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  121. * PolicyKey, result is allowed and timespec consist of maxium values
  122. * @test Expected result:
  123. * - policy key contains {c, u, p}
  124. * - result is allowed
  125. * - sec is maxium, nsec is maxium
  126. */
  127. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse05) {
  128. std::vector<MonitorEntry> entries = {
  129. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MAX, TV_NSEC_MAX})
  130. };
  131. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_1);
  132. auto protocol = std::make_shared<ProtocolMonitorGet>();
  133. testResponse(response, protocol);
  134. }
  135. /**
  136. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  137. * PolicyKey, result is denied and timespec consist of maxium sec and minimum nsec
  138. * @test Expected result:
  139. * - policy key contains {c, u, p}
  140. * - result is denied
  141. * - sec is maxium, nsec is minimum
  142. */
  143. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse06) {
  144. std::vector<MonitorEntry> entries = {
  145. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_MIN})
  146. };
  147. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_2);
  148. auto protocol = std::make_shared<ProtocolMonitorGet>();
  149. testResponse(response, protocol);
  150. }
  151. /**
  152. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  153. * PolicyKey, result is allowed and timespec consist of minimum sec and maximum nsec
  154. * @test Expected result:
  155. * - policy key contains {c, u, p}
  156. * - result is allowed
  157. * - sec is minimum, nsec is maxium
  158. */
  159. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse07) {
  160. std::vector<MonitorEntry> entries = {
  161. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MIN, TV_SEC_MAX})
  162. };
  163. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
  164. auto protocol = std::make_shared<ProtocolMonitorGet>();
  165. testResponse(response, protocol);
  166. }
  167. /**
  168. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while
  169. * entries vector is empty
  170. * @test Expected result:
  171. * - entries are empty
  172. */
  173. TEST(ProtocolMonitorGet, MonitorGetEntriesResponseEmptyEntries) {
  174. std::vector<MonitorEntry> entries;
  175. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
  176. auto protocol = std::make_shared<ProtocolMonitorGet>();
  177. testResponse(response, protocol);
  178. }
  179. /**
  180. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while
  181. * entries vector has maximum allowed elements
  182. * @test Expected result:
  183. * - entries contain max value of elements
  184. */
  185. TEST(ProtocolMonitorGet, MonitorGetEntriesResponseMultipleEntries) {
  186. std::vector<MonitorEntry> entries;
  187. entries.reserve(CYNARA_MAX_VECTOR_SIZE);
  188. for (uint16_t i = 0; i < CYNARA_MAX_VECTOR_SIZE; i++) {
  189. entries.emplace_back(MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED,
  190. {TV_SEC_MIN, TV_SEC_MAX}));
  191. }
  192. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
  193. auto protocol = std::make_shared<ProtocolMonitorGet>();
  194. testResponse(response, protocol);
  195. }
  196. /* *** compare by serialized data test cases *** */
  197. /**
  198. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  199. * PolicyKey, result is allowed and timespec consist of minimum values
  200. * @test Expected result:
  201. * - policy key contains {c, u, p}
  202. * - result is allowed
  203. * - sec is minimal + 1, nsec is minimal
  204. */
  205. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse08) {
  206. std::vector<MonitorEntry> entries = {
  207. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_1, TV_NSEC_MIN})
  208. };
  209. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min);
  210. auto protocol = std::make_shared<ProtocolMonitorGet>();
  211. binaryTestResponse(response, protocol);
  212. }
  213. /**
  214. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  215. * PolicyKey, result is denied and timespec consist of medium sec and minimal nsec
  216. * @test Expected result:
  217. * - policy key contains {c, u, p}
  218. * - result is denied
  219. * - sec is medium, nsec is minimal
  220. */
  221. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse09) {
  222. std::vector<MonitorEntry> entries = {
  223. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_HALF, TV_NSEC_MIN})
  224. };
  225. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_1);
  226. auto protocol = std::make_shared<ProtocolMonitorGet>();
  227. binaryTestResponse(response, protocol);
  228. }
  229. /**
  230. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  231. * PolicyKey, result is allowed and timespec consist of medium values
  232. * @test Expected result:
  233. * - policy key contains {c, u, p}
  234. * - result is allowed
  235. * - sec is medium, nsec is medium
  236. */
  237. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse10) {
  238. std::vector<MonitorEntry> entries = {
  239. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_HALF, TV_NSEC_HALF})
  240. };
  241. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
  242. auto protocol = std::make_shared<ProtocolMonitorGet>();
  243. binaryTestResponse(response, protocol);
  244. }
  245. /**
  246. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  247. * PolicyKey, result is denied and timespec consist of maxium sec and medium nsec
  248. * @test Expected result:
  249. * - policy key contains {c, u, p}
  250. * - result is denied
  251. * - sec is maximum, nsec is medium
  252. */
  253. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse11) {
  254. std::vector<MonitorEntry> entries = {
  255. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_HALF})
  256. };
  257. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::mid);
  258. auto protocol = std::make_shared<ProtocolMonitorGet>();
  259. binaryTestResponse(response, protocol);
  260. }
  261. /**
  262. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  263. * PolicyKey, result is allowed and timespec consist of maxium values
  264. * @test Expected result:
  265. * - policy key contains {c, u, p}
  266. * - result is allowed
  267. * - sec is maxium, nsec is maxium
  268. */
  269. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse12) {
  270. std::vector<MonitorEntry> entries = {
  271. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MAX, TV_NSEC_MAX})
  272. };
  273. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_1);
  274. auto protocol = std::make_shared<ProtocolMonitorGet>();
  275. binaryTestResponse(response, protocol);
  276. }
  277. /**
  278. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  279. * PolicyKey, result is denied and timespec consist of maxium sec and minimum + 1 nsec
  280. * @test Expected result:
  281. * - policy key contains {c, u, p}
  282. * - result is denied
  283. * - sec is maxium, nsec is minimum + 1
  284. */
  285. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse13) {
  286. std::vector<MonitorEntry> entries = {
  287. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_1})
  288. };
  289. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_2);
  290. auto protocol = std::make_shared<ProtocolMonitorGet>();
  291. binaryTestResponse(response, protocol);
  292. }
  293. /**
  294. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  295. * PolicyKey, result is allowed and timespec consist of minimum sec and maximum nsec
  296. * @test Expected result:
  297. * - policy key contains {c, u, p}
  298. * - result is allowed
  299. * - sec is minimum, nsec is maxium
  300. */
  301. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse14) {
  302. std::vector<MonitorEntry> entries = {
  303. MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MIN, TV_SEC_MAX})
  304. };
  305. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
  306. auto protocol = std::make_shared<ProtocolMonitorGet>();
  307. binaryTestResponse(response, protocol);
  308. }
  309. /**
  310. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
  311. * PolicyKey, result is denied and timespec consist of maxium sec and medium nsec
  312. * @test Expected result:
  313. * - policy key contains {amanda, to, troll}
  314. * - result is denied
  315. * - sec is maximum, nsec is medium
  316. */
  317. TEST(ProtocolMonitorGet, MonitorGetEntriesResponse15) {
  318. std::vector<MonitorEntry> entries = {
  319. MonitorEntry(Keys::k_cup2, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_HALF})
  320. };
  321. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::mid);
  322. auto protocol = std::make_shared<ProtocolMonitorGet>();
  323. binaryTestResponse(response, protocol);
  324. }
  325. /**
  326. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while
  327. * entries vector is empty
  328. * @test Expected result:
  329. * - entries are empty
  330. */
  331. TEST(ProtocolMonitorGet, MonitorGetEntriesResponseEmptyEntries2) {
  332. std::vector<MonitorEntry> entries;
  333. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
  334. auto protocol = std::make_shared<ProtocolMonitorGet>();
  335. binaryTestResponse(response, protocol);
  336. }
  337. /**
  338. * @brief Verify if MonitorGetEntriesResponse is properly (de)serialized while
  339. * entries vector has maximum allowed elements
  340. * @test Expected result:
  341. * - entries contain max value of elements
  342. */
  343. TEST(ProtocolMonitorGet, MonitorGetEntriesResponseMultipleEntries2) {
  344. std::vector<MonitorEntry> entries;
  345. entries.reserve(std::numeric_limits<uint16_t>::max());
  346. for (uint16_t i = 0; i < std::numeric_limits<uint16_t>::max(); i++) {
  347. entries.emplace_back(MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED,
  348. {TV_SEC_MIN, TV_SEC_MAX}));
  349. }
  350. auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
  351. auto protocol = std::make_shared<ProtocolMonitorGet>();
  352. binaryTestResponse(response, protocol);
  353. }