PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/test/common/protocols/monitor/getentriesrequest.cpp

https://gitlab.com/github-cloud-corporation/cynara
C++ | 155 lines | 63 code | 20 blank | 72 comment | 0 complexity | 2d2402d81802478552b85e9886364d6f 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/getentriesrequest.cpp
  18. * @author Zofia Abramowska <z.abramowska@samsung.com>
  19. * @version 1.0
  20. * @brief Tests for Cynara::MonitorGetEntriesRequest usage in
  21. * Cynara::ProtocolMonitorGet
  22. */
  23. #include <vector>
  24. #include <gtest/gtest.h>
  25. #include <cynara-limits.h>
  26. #include <protocol/ProtocolMonitorGet.h>
  27. #include <request/MonitorGetEntriesRequest.h>
  28. #include <types/Policy.h>
  29. #include <RequestTestHelper.h>
  30. #include <TestDataCollection.h>
  31. namespace {
  32. template<>
  33. void compare(const Cynara::MonitorGetEntriesRequest &req1,
  34. const Cynara::MonitorGetEntriesRequest &req2) {
  35. EXPECT_EQ(req1.bufferSize(), req2.bufferSize());
  36. EXPECT_EQ(req1.sequenceNumber(), req2.sequenceNumber());
  37. }
  38. static const uint64_t BUFF_SIZE_MIN = 0;
  39. static const uint64_t BUFF_SIZE_1 = 1;
  40. static const uint64_t BUFF_SIZE_MAX = CYNARA_MAX_MONITOR_BUFFER_SIZE;
  41. static const uint64_t BUFF_SIZE_HALF = (BUFF_SIZE_MAX + BUFF_SIZE_MIN) / 2;
  42. } /* namespace anonymous */
  43. using namespace Cynara;
  44. using namespace RequestTestHelper;
  45. using namespace TestDataCollection;
  46. /* *** compare by objects test cases *** */
  47. /**
  48. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  49. * to 0
  50. * @test Expected result:
  51. * - buffer size is 0
  52. */
  53. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest01) {
  54. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_MIN, SN::min);
  55. auto protocol = std::make_shared<ProtocolMonitorGet>();
  56. testRequest(request, protocol);
  57. }
  58. /**
  59. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  60. * to 1
  61. * @test Expected result:
  62. * - buffer size is 1
  63. */
  64. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest02) {
  65. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_1, SN::min_1);
  66. auto protocol = std::make_shared<ProtocolMonitorGet>();
  67. testRequest(request, protocol);
  68. }
  69. /**
  70. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  71. * to half max value
  72. * @test Expected result:
  73. * - buffer size is half max value
  74. */
  75. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest03) {
  76. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_HALF, SN::mid);
  77. auto protocol = std::make_shared<ProtocolMonitorGet>();
  78. testRequest(request, protocol);
  79. }
  80. /**
  81. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  82. * to max value
  83. * @test Expected result:
  84. * - buffer size is max value
  85. */
  86. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest04) {
  87. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_MAX, SN::max);
  88. auto protocol = std::make_shared<ProtocolMonitorGet>();
  89. testRequest(request, protocol);
  90. }
  91. /* *** compare by serialized data test cases *** */
  92. /**
  93. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  94. * to 0
  95. * @test Expected result:
  96. * - buffer size is 0
  97. */
  98. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest05) {
  99. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_MIN, SN::min);
  100. auto protocol = std::make_shared<ProtocolMonitorGet>();
  101. binaryTestRequest(request, protocol);
  102. }
  103. /**
  104. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  105. * to 1
  106. * @test Expected result:
  107. * - buffer size is 1
  108. */
  109. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest06) {
  110. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_1, SN::min_1);
  111. auto protocol = std::make_shared<ProtocolMonitorGet>();
  112. binaryTestRequest(request, protocol);
  113. }
  114. /**
  115. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  116. * to half max value
  117. * @test Expected result:
  118. * - buffer size is half max value
  119. */
  120. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest07) {
  121. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_HALF, SN::mid);
  122. auto protocol = std::make_shared<ProtocolMonitorGet>();
  123. binaryTestRequest(request, protocol);
  124. }
  125. /**
  126. * @brief Verify if MonitorGetEntriesRequest is properly (de)serialized with buffer size set
  127. * to max value
  128. * @test Expected result:
  129. * - buffer size is max value
  130. */
  131. TEST(ProtocolMonitorGet, MonitorGetEntriesRequest08) {
  132. auto request = std::make_shared<MonitorGetEntriesRequest>(BUFF_SIZE_MAX, SN::max);
  133. auto protocol = std::make_shared<ProtocolMonitorGet>();
  134. binaryTestRequest(request, protocol);
  135. }