Redo unit tests for AdminCheckResponse in ProtocolAdmin 27/238727/7
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 16 Jul 2020 13:52:47 +0000 (15:52 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 12 Aug 2020 09:00:54 +0000 (11:00 +0200)
* squash positive test cases
* add invalid protocol test case

Change-Id: I2a3e46e2df2942e091aa0620345c91c4e7d10bbb

test/common/protocols/TestDataCollection.h
test/common/protocols/admin/admincheckresponse.cpp

index 3212d0b1d10f47f6584aac67e9aca707f34f5126..9ad08d610ab6fc917719ced4cea1cc5543ba4e8a 100644 (file)
@@ -187,6 +187,26 @@ const bool all[] = {
 
 } /* namespace Recursive */
 
+namespace BucketStatus {
+
+const bool valid = true;
+const bool no_bucket = false;
+const bool all[] = {
+    valid, no_bucket
+};
+
+} /* namespace Bucket */
+
+namespace DBStatus {
+
+const bool ok = true;
+const bool corrupted = false;
+const bool all[] = {
+    ok, corrupted
+};
+
+} /* namespace DB */
+
 } /* namespace Admin */
 
 } /* namespace TestDataCollection */
index 2d1983b160759aec9084fcd504306aedadb94dd4..e1f1d4316fdcf27ef3b981359e3c1e0e27bff0bb 100644 (file)
 
 #include <gtest/gtest.h>
 
+#include <cynara-limits.h>
 #include <protocol/ProtocolAdmin.h>
 #include <response/AdminCheckResponse.h>
 
+#include <NegativeTestHelper.h>
 #include <ResponseTestHelper.h>
 #include <TestDataCollection.h>
 
@@ -43,143 +45,53 @@ void compare(const Cynara::AdminCheckResponse &resp1, const Cynara::AdminCheckRe
     EXPECT_EQ(resp1.isDbCorrupted(), resp2.isDbCorrupted());
 }
 
-static const bool VALID_BUCKET = true;
-static const bool NO_BUCKET = false;
-static const bool DB_OK = false;
-static const bool DB_CORRUPTED = true;
-
 } /* anonymous namespace */
 
 using namespace Cynara;
+using namespace NegativeTestHelper;
 using namespace ResponseTestHelper;
 using namespace TestDataCollection;
 
-/* *** compare by objects test cases *** */
-
-TEST(ProtocolAdmin, AdminCheckResponse01) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, DB_OK,
-                                                         SN::min);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponse02) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_OK,
-                                                         SN::min_1);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponse03) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET, DB_OK,
-                                                         SN::min_2);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponse04) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
-                                                         DB_OK, SN::max);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponse05) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, DB_OK,
-                                                         SN::max_1);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
-}
+TEST(ProtocolAdmin, AdminCheckResponsePositive) {
+    for (auto &result : Results::all) {
+        for (auto &bucket : Admin::BucketStatus::all) {
+            for (auto &db : Admin::DBStatus::all) {
+                for (auto &sequenceNumber : SN::all) {
+                    auto response = std::make_shared<AdminCheckResponse>
+                        (result, bucket, db, sequenceNumber);
+                    auto protocol = std::make_shared<ProtocolAdmin>();
+                    testResponse(response, protocol);
+                }
+            }
+        }
+    }
+}
+
+TEST(ProtocolAdmin, AdminCheckResponseBinaryPositive) {
+    for (auto &result : Results::all) {
+        for (auto &bucket : Admin::BucketStatus::all) {
+            for (auto &db : Admin::DBStatus::all) {
+                for (auto &sequenceNumber : SN::all) {
+                    auto response = std::make_shared<AdminCheckResponse>
+                        (result, bucket, db, sequenceNumber);
+                    auto protocol = std::make_shared<ProtocolAdmin>();
+                    binaryTestResponse(response, protocol);
+                }
+            }
+        }
+    }
+}
+
+TEST(ProtocolAdmin, AdminCheckResponseTooLongMetadataNegative) {
+    PolicyResult result(Types::plugin_type, std::string(CYNARA_MAX_ID_LENGTH + 1, 'm'));
+    for (auto &bucket : Admin::BucketStatus::all) {
+        for (auto &db : Admin::DBStatus::all) {
+            for (auto &sequenceNumber : SN::all) {
+                testInvalidProtocol<ProtocolAdmin, AdminCheckResponse>
+                    (result, bucket, db, sequenceNumber);
+            }
+        }
+    }
 
-TEST(ProtocolAdmin, AdminCheckResponse06) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, DB_OK,
-                                                         SN::max_2);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
 }
 
-TEST(ProtocolAdmin, AdminCheckResponse07) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, DB_OK,
-                                                         SN::mid);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if AdminCheckResponse is properly (de)serialized while database is corrupted
- * @test    Expected result:
- * - PolicyResult set to DENY
- * - bucketValid flag set to false (NO_BUCKET)
- * - dbCorrupted flag set to true (DB_CORRUPTED)
- */
-TEST(ProtocolAdmin, AdminCheckResponse08) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_CORRUPTED,
-                                                         SN::max);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    testResponse(response, protocol);
-}
-
-/* *** compare by serialized data test cases *** */
-
-TEST(ProtocolAdmin, AdminCheckResponseBinary01) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, DB_OK,
-                                                         SN::min);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponseBinary02) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_OK,
-                                                         SN::min_1);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponseBinary03) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET, DB_OK,
-                                                         SN::min_2);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponseBinary04) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
-                                                         DB_OK, SN::max);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponseBinary05) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, DB_OK,
-                                                         SN::max_1);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponseBinary06) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, DB_OK,
-                                                         SN::max_2);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}
-
-TEST(ProtocolAdmin, AdminCheckResponseBinary07) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, DB_OK,
-                                                         SN::mid);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}
-
-/**
- * @brief   Verify if AdminCheckResponse is properly (de)serialized while database is corrupted
- * @test    Expected result:
- * - PolicyResult set to DENY
- * - bucketValid flag set to false (NO_BUCKET)
- * - dbCorrupted flag set to true (DB_CORRUPTED)
- */
-TEST(ProtocolAdmin, AdminCheckResponseBinary08) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_CORRUPTED,
-                                                         SN::max);
-    auto protocol = std::make_shared<ProtocolAdmin>();
-    binaryTestResponse(response, protocol);
-}