Test usage of AdminCheck Req/Resp by ProtocolAdmin 69/31569/7
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Sat, 6 Dec 2014 00:25:25 +0000 (01:25 +0100)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 15 Dec 2014 14:38:18 +0000 (15:38 +0100)
Test serialization and deserialization of AdminCheckRequest
and AdminCheckResponse objects by ProtocolAdmin.

Change-Id: Ia8923dbeaf0d03c29fd77bde3758375df59e1bc6

test/CMakeLists.txt
test/common/protocols/admin/admincheckrequest.cpp [new file with mode: 0644]
test/common/protocols/admin/admincheckresponse.cpp [new file with mode: 0644]

index 5bb0a7e..82f26cd 100644 (file)
@@ -57,6 +57,8 @@ SET(CYNARA_SOURCES_FOR_TESTS
 SET(CYNARA_TESTS_SOURCES
     TestEventListenerProxy.cpp
     common/exceptions/bucketrecordcorrupted.cpp
+    common/protocols/admin/admincheckrequest.cpp
+    common/protocols/admin/admincheckresponse.cpp
     common/protocols/admin/listrequest.cpp
     common/protocols/admin/listresponse.cpp
     common/types/policybucket.cpp
diff --git a/test/common/protocols/admin/admincheckrequest.cpp b/test/common/protocols/admin/admincheckrequest.cpp
new file mode 100644 (file)
index 0000000..d5f1103
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        test/common/protocols/admin/admincheckrequest.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::AdminCheckRequest usage in Cynara::ProtocolAdmin
+ */
+
+#include <gtest/gtest.h>
+
+#include <protocol/ProtocolAdmin.h>
+#include <request/AdminCheckRequest.h>
+
+#include <RequestTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::AdminCheckRequest &req1, const Cynara::AdminCheckRequest &req2) {
+    EXPECT_EQ(req1.key(), req2.key());
+    EXPECT_EQ(req1.startBucket(), req2.startBucket());
+    EXPECT_EQ(req1.recursive(), req2.recursive());
+}
+
+static const bool RECURSIVE = true;
+static const bool NON_RECURSIVE = false;
+
+} /* anonymous namespace */
+
+using namespace Cynara;
+using namespace RequestTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAdmin, AdminCheckRequest01) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_nun, Buckets::empty, RECURSIVE,
+                                                       SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequest02) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_cup, Buckets::not_empty, RECURSIVE,
+                                                       SN::min_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequest03) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_www, Buckets::empty, NON_RECURSIVE,
+                                                       SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequest04) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_wuw, Buckets::not_empty,
+                                                       NON_RECURSIVE, SN::max);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequest05) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_aaa, Buckets::empty, RECURSIVE,
+                                                       SN::max_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequest06) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_wua, Buckets::not_empty, RECURSIVE,
+                                                       SN::max_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequest07) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_nua, Buckets::empty, NON_RECURSIVE,
+                                                       SN::mid);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+/* *** compare by serialized data test cases *** */
+
+TEST(ProtocolAdmin, AdminCheckRequestBinary01) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_nun, Buckets::empty, RECURSIVE,
+                                                       SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequestBinary02) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_cup, Buckets::not_empty, RECURSIVE,
+                                                       SN::min_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequestBinary03) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_www, Buckets::empty, NON_RECURSIVE,
+                                                       SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequestBinary04) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_wuw, Buckets::not_empty,
+                                                       NON_RECURSIVE, SN::max);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequestBinary05) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_aaa, Buckets::empty, RECURSIVE,
+                                                       SN::max_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequestBinary06) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_wua, Buckets::not_empty, RECURSIVE,
+                                                       SN::max_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckRequestBinary07) {
+    auto request = std::make_shared<AdminCheckRequest>(Keys::k_nua, Buckets::empty, NON_RECURSIVE,
+                                                       SN::mid);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
diff --git a/test/common/protocols/admin/admincheckresponse.cpp b/test/common/protocols/admin/admincheckresponse.cpp
new file mode 100644 (file)
index 0000000..666f65e
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        test/common/protocols/admin/admincheckresponse.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::AdminCheckResponse usage in Cynara::ProtocolAdmin
+ */
+
+#include <gtest/gtest.h>
+
+#include <protocol/ProtocolAdmin.h>
+#include <response/AdminCheckResponse.h>
+
+#include <ResponseTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::AdminCheckResponse &resp1, const Cynara::AdminCheckResponse &resp2) {
+    EXPECT_EQ(resp1.result(), resp2.result());
+    EXPECT_EQ(resp1.isBucketValid(), resp2.isBucketValid());
+}
+
+static const bool VALID_BUCKET = true;
+static const bool NO_BUCKET = false;
+
+} /* anonymous namespace */
+
+using namespace Cynara;
+using namespace ResponseTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAdmin, AdminCheckResponse01) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckResponse02) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, 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,
+                                                         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,
+                                                         SN::max);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckResponse05) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, SN::max_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckResponse06) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, 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, SN::mid);
+    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, SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckResponseBinary02) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, 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,
+                                                         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,
+                                                         SN::max);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, AdminCheckResponseBinary05) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, 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, 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, SN::mid);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}