Redo unit tests for MonitorGetEntriesResponse in ProtocolMonitorGet 52/238952/7
authorZofia Abramowska <z.abramowska@samsung.com>
Mon, 20 Jul 2020 13:45:57 +0000 (15:45 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 12 Aug 2020 09:04:47 +0000 (11:04 +0200)
* squash positive test cases
* add invalid protocol test cases

Change-Id: I2172a1a8814a924754411704b1d166df681ba92c

test/common/protocols/CommonsTestHelper.h
test/common/protocols/TestDataCollection.h
test/common/protocols/client/monitorentriesputrequest.cpp
test/common/protocols/monitor/getentriesresponse.cpp

index 8e0d7b9eb53638f48010d12d61cc6003c7fba841..f6aefbd84a3beedf419cfeab4fd5cb5627075e2e 100644 (file)
@@ -64,6 +64,27 @@ inline Cynara::RawBuffer genBuffer(Cynara::RawBuffer::size_type size) {
                });
 }
 
+inline std::vector<Cynara::MonitorEntry> genMonitorEntries(
+    std::vector<Cynara::MonitorEntry>::size_type size)
+{
+    auto &keys = TestDataCollection::Keys::all;
+    auto keysSize = std::size(keys);
+    auto &entryResults = TestDataCollection::Monitor::EntryResult::all;
+    auto entryResultsSize = std::size(entryResults);
+    auto &secs = TestDataCollection::Times::Sec::all;
+    auto secsSize = std::size(secs);
+    auto &nsecs = TestDataCollection::Times::NSec::all;
+    auto nsecsSize = std::size(nsecs);
+    return generate<Cynara::MonitorEntry>
+        (size, [&] (int i, std::vector<Cynara::MonitorEntry>::size_type size){
+                   auto index = size - 1 + i;
+                   return Cynara::MonitorEntry(keys[index % keysSize],
+                                               entryResults[index & entryResultsSize],
+                                               {secs[index % secsSize],
+                                                nsecs[index % nsecsSize]});
+               });
+}
+
 } /* namespace anonymous */
 
 #endif /* TEST_COMMON_PROTOCOLS_COMMONSTESTHELPER_H_ */
index 7896e879596d367bb5efb1f20d6f3dab98998eee..4c61664233d6a908455b1a9b8e7e9075a57960c9 100644 (file)
@@ -195,6 +195,9 @@ namespace Monitor {
 typedef NumericDataCollection<int> EntryResult;
 typedef NumericDataCollection<std::vector<Cynara::MonitorEntry>::size_type, 0,
                               CYNARA_MAX_VECTOR_SIZE> EntriesSize;
+typedef NumericDataCollection<std::vector<Cynara::MonitorEntry>::size_type, 0,
+                              CYNARA_MAX_MONITOR_BUFFER_SIZE> BufferSize;
+
 } /* namespace Monitor */
 
 namespace Buffer {
index 728eb4c0c6f00d3127cc9f3cb3b6a4a1996f35fa..e4d075bb97dc09c894f9ff24396fcc39d7847965 100644 (file)
 
 namespace {
 
-std::vector<Cynara::MonitorEntry> genMonitorEntries(
-    std::vector<Cynara::MonitorEntry>::size_type size)
-{
-    auto &keys = TestDataCollection::Keys::all;
-    auto keysSize = std::size(keys);
-    auto &entryResults = TestDataCollection::Monitor::EntryResult::all;
-    auto entryResultsSize = std::size(entryResults);
-    auto &secs = TestDataCollection::Times::Sec::all;
-    auto secsSize = std::size(secs);
-    auto &nsecs = TestDataCollection::Times::NSec::all;
-    auto nsecsSize = std::size(nsecs);
-    return generate<Cynara::MonitorEntry>
-        (size, [&] (int i, std::vector<Cynara::MonitorEntry>::size_type size){
-                   auto index = size - 1 + i;
-                   return Cynara::MonitorEntry(keys[index % keysSize],
-                                               entryResults[index & entryResultsSize],
-                                               {secs[index % secsSize],
-                                                nsecs[index % nsecsSize]});
-               });
-}
-
 template<>
 void compare(const Cynara::MonitorEntriesPutRequest &req1,
              const Cynara::MonitorEntriesPutRequest &req2) {
index 4ef0254b332ec074177839c58644200e15d0759b..b510b89034df582b6aa3c23442ac95959abe50c3 100644 (file)
 #include <cynara-error.h>
 
 #include "../../helpers.h"
+#include <CommonsTestHelper.h>
+#include <NegativeTestHelper.h>
 #include <ResponseTestHelper.h>
 #include <TestDataCollection.h>
 
 namespace {
 
-template <class T, class M> M get_member_type(M T:: *);
-
-const int64_t TV_SEC_MIN = 0;
-const int64_t TV_SEC_1 = 1;
-const int64_t TV_SEC_MAX = std::numeric_limits<decltype(get_member_type(&timespec::tv_sec))>::max();
-const int64_t TV_SEC_HALF = (TV_SEC_MAX - TV_SEC_MIN) / 2;
-const int64_t TV_NSEC_MIN = 0;
-const int64_t TV_NSEC_1 = 1;
-const int64_t TV_NSEC_MAX =
-    std::numeric_limits<decltype(get_member_type(&timespec::tv_nsec))>::max();
-const int64_t TV_NSEC_HALF = (TV_SEC_MAX - TV_SEC_MIN) / 2;
-
 template<>
 void compare(const Cynara::MonitorGetEntriesResponse &req1,
-             const Cynara::MonitorGetEntriesResponse &req2) {
+             const Cynara::MonitorGetEntriesResponse &req2)
+{
     EXPECT_EQ(req1.entries(), req2.entries());
+    EXPECT_EQ(req1.sequenceNumber(), req2.sequenceNumber());
 }
 
 } /* namespace anonymous */
 
 using namespace Cynara;
+using namespace NegativeTestHelper;
 using namespace ResponseTestHelper;
 using namespace TestDataCollection;
 
 /* *** compare by objects test cases *** */
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of minimum values
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is minimal, nsec is minimal
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse01) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MIN, TV_NSEC_MIN})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is denied and timespec consist of medium sec and minimal nsec
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is denied
- *          - sec is medium, nsec is minimal
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse02) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_HALF, TV_NSEC_MIN})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_1);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of medium values
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is medium, nsec is medium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse03) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_HALF, TV_NSEC_HALF})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is denied and timespec consist of maxium sec and medium nsec
- * @test    Expected result:
- *          - policy key contains {amanda, to, troll}
- *          - result is denied
- *          - sec is maximum, nsec is medium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse04) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup2, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_HALF})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::mid);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of maxium values
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is maxium, nsec is maxium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse05) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MAX, TV_NSEC_MAX})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_1);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is denied and timespec consist of maxium sec and minimum nsec
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is denied
- *          - sec is maxium, nsec is minimum
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse06) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_MIN})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_2);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of minimum sec and maximum nsec
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is minimum, nsec is maxium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse07) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MIN, TV_SEC_MAX})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while
- *          entries vector is empty
- * @test    Expected result:
- *          - entries are empty
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponseEmptyEntries) {
-    std::vector<MonitorEntry> entries;
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while
- *          entries vector has maximum allowed elements
- * @test    Expected result:
- *          - entries contain max value of elements
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponseMultipleEntries) {
-    std::vector<MonitorEntry> entries;
-    entries.reserve(CYNARA_MAX_VECTOR_SIZE);
-    for (uint16_t i = 0; i < CYNARA_MAX_VECTOR_SIZE; i++) {
-        entries.emplace_back(MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED,
-                                          {TV_SEC_MIN, TV_SEC_MAX}));
+TEST(ProtocolMonitorGet, MonitorGetEntriesResponsePositive) {
+    for (auto &size : Monitor::BufferSize::all) {
+        std::vector<MonitorEntry> entries = genMonitorEntries(size);
+        for (auto &sequenceNumber : SN::all) {
+            auto response = std::make_shared<MonitorGetEntriesResponse>(entries, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolMonitorGet>();
+            testResponse(response, protocol);
+        }
     }
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    testResponse(response, protocol);
 }
 
 /* *** compare by serialized data test cases *** */
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of minimum values
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is minimal + 1, nsec is minimal
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse08) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_1, TV_NSEC_MIN})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
+TEST(ProtocolMonitorGet, MonitorGetEntriesResponseBinaryPositive) {
+    for (auto &size : Monitor::BufferSize::all) {
+        std::vector<MonitorEntry> entries = genMonitorEntries(size);
+        for (auto &sequenceNumber : SN::all) {
+            auto response = std::make_shared<MonitorGetEntriesResponse>(entries, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolMonitorGet>();
+            binaryTestResponse(response, protocol);
+        }
+    }
 }
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is denied and timespec consist of medium sec and minimal nsec
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is denied
- *          - sec is medium, nsec is minimal
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse09) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_HALF, TV_NSEC_MIN})
-    };
+/* *** invalid protocol test cases *** */
 
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_1);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
-}
+TEST(ProtocolMonitorGet, MonitorGetEntriesResponseTooLongEntriesNegative) {
+    std::vector<MonitorEntry> entries = genMonitorEntries(Monitor::BufferSize::max + 1);
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of medium values
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is medium, nsec is medium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse10) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_HALF, TV_NSEC_HALF})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
+    testInvalidProtocol<ProtocolMonitorGet, MonitorGetEntriesResponse>(entries, SN::min_2);
 }
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is denied and timespec consist of maxium sec and medium nsec
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is denied
- *          - sec is maximum, nsec is medium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse11) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_HALF})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::mid);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
-}
+TEST(ProtocolMonitorGet, MonitorGetEntriesResponseTooLongClientNegative) {
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of maxium values
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is maxium, nsec is maxium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse12) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MAX, TV_NSEC_MAX})
-    };
+    std::vector<MonitorEntry> entries = genMonitorEntries(Monitor::EntriesSize::min_1);
+    entries.push_back(MonitorEntry(
+                          PolicyKey(PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'c')),
+                                    Keys::k_aaa.user(), Keys::k_wuw.privilege()),
+                          Monitor::EntryResult::max,
+                          {Times::Sec::min_1, Times::NSec::max_1}));
 
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_1);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
+    testInvalidProtocol<ProtocolMonitorGet, MonitorGetEntriesResponse>(entries, SN::mid);
 }
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is denied and timespec consist of maxium sec and minimum + 1 nsec
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is denied
- *          - sec is maxium, nsec is minimum + 1
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse13) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_1})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max_2);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is allowed and timespec consist of minimum sec and maximum nsec
- * @test    Expected result:
- *          - policy key contains {c, u, p}
- *          - result is allowed
- *          - sec is minimum, nsec is maxium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse14) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED, {TV_SEC_MIN, TV_SEC_MAX})
-    };
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while using standard
- *          PolicyKey, result is denied and timespec consist of maxium sec and medium nsec
- * @test    Expected result:
- *          - policy key contains {amanda, to, troll}
- *          - result is denied
- *          - sec is maximum, nsec is medium
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponse15) {
-    std::vector<MonitorEntry> entries = {
-            MonitorEntry(Keys::k_cup2, CYNARA_API_ACCESS_DENIED, {TV_SEC_MAX, TV_NSEC_HALF})
-    };
+TEST(ProtocolMonitorGet, MonitorGetEntriesResponseTooLongUserNegative) {
+    std::vector<MonitorEntry> entries = genMonitorEntries(Monitor::EntriesSize::min_2);
+    entries.push_back(MonitorEntry(
+                          PolicyKey(Keys::k_cup.client(),
+                                    PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'u')),
+                                    Keys::k_nun.privilege()),
+                          Monitor::EntryResult::max_1,
+                          {Times::Sec::min, Times::NSec::min}));
 
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::mid);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
+    testInvalidProtocol<ProtocolMonitorGet, MonitorGetEntriesResponse>(entries, SN::max_1);
 }
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while
- *          entries vector is empty
- * @test    Expected result:
- *          - entries are empty
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponseEmptyEntries2) {
+TEST(ProtocolMonitorGet, MonitorGetEntriesResponseTooLongPrivilegeNegative) {
     std::vector<MonitorEntry> entries;
+    entries.push_back(MonitorEntry(
+                          PolicyKey(Keys::k_wup.client(), Keys::k_cup2.user(),
+                                    PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'p'))),
+                          Monitor::EntryResult::min_2,
+                          {Times::Sec::mid, Times::NSec::min}));
 
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::max);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
+    testInvalidProtocol<ProtocolMonitorGet, MonitorGetEntriesResponse>(entries, SN::max_2);
 }
 
-/**
- * @brief   Verify if MonitorGetEntriesResponse is properly (de)serialized while
- *          entries vector has maximum allowed elements
- * @test    Expected result:
- *          - entries contain max value of elements
- */
-TEST(ProtocolMonitorGet, MonitorGetEntriesResponseMultipleEntries2) {
-    std::vector<MonitorEntry> entries;
-    entries.reserve(std::numeric_limits<uint16_t>::max());
-    for (uint16_t i = 0; i < std::numeric_limits<uint16_t>::max(); i++) {
-        entries.emplace_back(MonitorEntry(Keys::k_cup, CYNARA_API_ACCESS_ALLOWED,
-                                          {TV_SEC_MIN, TV_SEC_MAX}));
-    }
-
-    auto response = std::make_shared<MonitorGetEntriesResponse>(entries, SN::min_2);
-    auto protocol = std::make_shared<ProtocolMonitorGet>();
-    binaryTestResponse(response, protocol);
-}