Fix casting from and to void*
[platform/core/test/security-tests.git] / src / cynara-tests / common / cynara_test_agent_request.cpp
1 /*
2  * Copyright (c) 2015 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 #include <cynara_test_agent_request.h>
18 #include <plugins.h>
19 #include <dpl/test/test_runner.h>
20
21 namespace CynaraTestAgent {
22
23 std::ostream& operator<<(std::ostream& os, const AgentRequest &request)
24 {
25     os << "{";
26     os << " valid = " << request.m_valid << ",";
27     os << " type = " << request.m_type << ",";
28     os << " id = " << request.m_id << ",";
29     os << " data = " << request.m_data << ",";
30     os << " client = " << request.m_client << ",";
31     os << " user = " << request.m_user << ",";
32     os << " privilege = " << request.m_privilege;
33     os << " }";
34     return os;
35 }
36
37 void AgentRequest::set(cynara_agent_msg_type type, cynara_agent_req_id id,
38                        const void *data, size_t dataSize)
39 {
40     m_type = type;
41     m_id = id;
42     m_data = Cynara::PluginData(static_cast<const char*>(data), dataSize);
43     m_client.clear();
44     m_user.clear();
45     m_privilege.clear();
46
47     if (m_type == CYNARA_MSG_TYPE_ACTION) {
48         CynaraTestPlugins::AgentDataVector parsedData;
49
50         bool unwrapSuccess = CynaraTestPlugins::unwrapAgentData(m_data, parsedData);
51         RUNNER_ASSERT_MSG(unwrapSuccess,
52                              "Format error. Cannot succesfully unwrap request. "
53                                  << *this);
54
55         RUNNER_ASSERT_MSG(parsedData.size() == 3,
56                              "Received unexpected [" << parsedData.size() << "] number of units,"
57                                  << " while expecting 3."
58                                  << " Cannot succesfully unwrap request. "
59                                  << *this);
60
61         m_client = parsedData[0];
62         m_user = parsedData[1];
63         m_privilege = parsedData[2];
64     }
65     m_valid = true;
66 }
67
68 void AgentRequest::assertAction(std::string client, std::string user, std::string privilege)
69 {
70     RUNNER_ASSERT_MSG(m_valid,
71                          "assertAction failed: request is not valid. "
72                              << *this);
73     RUNNER_ASSERT_MSG(m_type == CYNARA_MSG_TYPE_ACTION,
74                          "assertAction failed: request's type is " << m_type
75                              << ", expected type is " << CYNARA_MSG_TYPE_ACTION << ". "
76                              << *this);
77     RUNNER_ASSERT_MSG(!m_data.empty(),
78                          "assertAction failed: m_data is empty. "
79                              << *this);
80     RUNNER_ASSERT_MSG(m_client == client,
81                          "assertAction failed: unexpected client value " << m_client
82                              << ", expected value is " << client << ". "
83                              << *this);
84     RUNNER_ASSERT_MSG(m_user == user,
85                          "assertAction failed: unexpected user value " << m_user
86                              << ", expected value is " << user << ". "
87                              << *this);
88     RUNNER_ASSERT_MSG(m_privilege == privilege,
89                          "assertAction failed: unexpected privilege value " << m_privilege
90                              << ", expected value is " << privilege << ". "
91                              << *this);
92 }
93
94 void AgentRequest::assertCancel()
95 {
96     RUNNER_ASSERT_MSG(m_valid,
97                          "assertCancel failed: request is not valid. "
98                              << *this);
99     RUNNER_ASSERT_MSG(m_type == CYNARA_MSG_TYPE_CANCEL,
100                          "assertCancel failed: request's type is " << m_type
101                              << ", expected type is " << CYNARA_MSG_TYPE_CANCEL << ". "
102                              << *this);
103     RUNNER_ASSERT_MSG(m_data.empty(),
104                          "assertCancel failed: m_data is not empty. "
105                              << *this);
106     RUNNER_ASSERT_MSG(m_client.empty(),
107                          "assertCancel failed: m_client is not empty. "
108                              << *this);
109     RUNNER_ASSERT_MSG(m_user.empty(),
110                          "assertCancel failed: m_user is not empty. "
111                              << *this);
112     RUNNER_ASSERT_MSG(m_privilege.empty(),
113                          "assertCancel failed: m_privilege is not empty. "
114                              << *this);
115 }
116
117 } // namespace CynaraTestAgent