Test usage of AdminCheck Req/Resp by ProtocolAdmin
[platform/core/security/cynara.git] / test / common / protocols / admin / admincheckresponse.cpp
1 /*
2  * Copyright (c) 2014 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/admin/admincheckresponse.cpp
18  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19  * @version     1.0
20  * @brief       Tests for Cynara::AdminCheckResponse usage in Cynara::ProtocolAdmin
21  */
22
23 #include <gtest/gtest.h>
24
25 #include <protocol/ProtocolAdmin.h>
26 #include <response/AdminCheckResponse.h>
27
28 #include <ResponseTestHelper.h>
29 #include <TestDataCollection.h>
30
31 namespace {
32
33 template<>
34 void compare(const Cynara::AdminCheckResponse &resp1, const Cynara::AdminCheckResponse &resp2) {
35     EXPECT_EQ(resp1.result(), resp2.result());
36     EXPECT_EQ(resp1.isBucketValid(), resp2.isBucketValid());
37 }
38
39 static const bool VALID_BUCKET = true;
40 static const bool NO_BUCKET = false;
41
42 } /* anonymous namespace */
43
44 using namespace Cynara;
45 using namespace ResponseTestHelper;
46 using namespace TestDataCollection;
47
48 /* *** compare by objects test cases *** */
49
50 TEST(ProtocolAdmin, AdminCheckResponse01) {
51     auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, SN::min);
52     auto protocol = std::make_shared<ProtocolAdmin>();
53     testResponse(response, protocol);
54 }
55
56 TEST(ProtocolAdmin, AdminCheckResponse02) {
57     auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, SN::min_1);
58     auto protocol = std::make_shared<ProtocolAdmin>();
59     testResponse(response, protocol);
60 }
61
62 TEST(ProtocolAdmin, AdminCheckResponse03) {
63     auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET,
64                                                          SN::min_2);
65     auto protocol = std::make_shared<ProtocolAdmin>();
66     testResponse(response, protocol);
67 }
68
69 TEST(ProtocolAdmin, AdminCheckResponse04) {
70     auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
71                                                          SN::max);
72     auto protocol = std::make_shared<ProtocolAdmin>();
73     testResponse(response, protocol);
74 }
75
76 TEST(ProtocolAdmin, AdminCheckResponse05) {
77     auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, SN::max_1);
78     auto protocol = std::make_shared<ProtocolAdmin>();
79     testResponse(response, protocol);
80 }
81
82 TEST(ProtocolAdmin, AdminCheckResponse06) {
83     auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, SN::max_2);
84     auto protocol = std::make_shared<ProtocolAdmin>();
85     testResponse(response, protocol);
86 }
87
88 TEST(ProtocolAdmin, AdminCheckResponse07) {
89     auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, SN::mid);
90     auto protocol = std::make_shared<ProtocolAdmin>();
91     testResponse(response, protocol);
92 }
93
94 /* *** compare by serialized data test cases *** */
95
96 TEST(ProtocolAdmin, AdminCheckResponseBinary01) {
97     auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, SN::min);
98     auto protocol = std::make_shared<ProtocolAdmin>();
99     binaryTestResponse(response, protocol);
100 }
101
102 TEST(ProtocolAdmin, AdminCheckResponseBinary02) {
103     auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, SN::min_1);
104     auto protocol = std::make_shared<ProtocolAdmin>();
105     binaryTestResponse(response, protocol);
106 }
107
108 TEST(ProtocolAdmin, AdminCheckResponseBinary03) {
109     auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET,
110                                                          SN::min_2);
111     auto protocol = std::make_shared<ProtocolAdmin>();
112     binaryTestResponse(response, protocol);
113 }
114
115 TEST(ProtocolAdmin, AdminCheckResponseBinary04) {
116     auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
117                                                          SN::max);
118     auto protocol = std::make_shared<ProtocolAdmin>();
119     binaryTestResponse(response, protocol);
120 }
121
122 TEST(ProtocolAdmin, AdminCheckResponseBinary05) {
123     auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, SN::max_1);
124     auto protocol = std::make_shared<ProtocolAdmin>();
125     binaryTestResponse(response, protocol);
126 }
127
128 TEST(ProtocolAdmin, AdminCheckResponseBinary06) {
129     auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, SN::max_2);
130     auto protocol = std::make_shared<ProtocolAdmin>();
131     binaryTestResponse(response, protocol);
132 }
133
134 TEST(ProtocolAdmin, AdminCheckResponseBinary07) {
135     auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, SN::mid);
136     auto protocol = std::make_shared<ProtocolAdmin>();
137     binaryTestResponse(response, protocol);
138 }