2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <cynara_test_agent_request.h>
19 #include <dpl/test/test_runner.h>
21 namespace CynaraTestAgent {
23 std::ostream& operator<<(std::ostream& os, const AgentRequest &request)
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;
37 void AgentRequest::set(cynara_agent_msg_type type, cynara_agent_req_id id,
38 const void *data, size_t dataSize)
42 m_data = Cynara::PluginData(static_cast<const char*>(data), dataSize);
47 if (m_type == CYNARA_MSG_TYPE_ACTION) {
48 CynaraTestPlugins::AgentDataVector parsedData;
50 bool unwrapSuccess = CynaraTestPlugins::unwrapAgentData(m_data, parsedData);
51 RUNNER_ASSERT_MSG(unwrapSuccess,
52 "Format error. Cannot succesfully unwrap request. "
55 RUNNER_ASSERT_MSG(parsedData.size() == 3,
56 "Received unexpected [" << parsedData.size() << "] number of units,"
57 << " while expecting 3."
58 << " Cannot succesfully unwrap request. "
61 m_client = parsedData[0];
62 m_user = parsedData[1];
63 m_privilege = parsedData[2];
68 void AgentRequest::assertAction(std::string client, std::string user, std::string privilege)
70 RUNNER_ASSERT_MSG(m_valid,
71 "assertAction failed: request is not valid. "
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 << ". "
77 RUNNER_ASSERT_MSG(!m_data.empty(),
78 "assertAction failed: m_data is empty. "
80 RUNNER_ASSERT_MSG(m_client == client,
81 "assertAction failed: unexpected client value " << m_client
82 << ", expected value is " << client << ". "
84 RUNNER_ASSERT_MSG(m_user == user,
85 "assertAction failed: unexpected user value " << m_user
86 << ", expected value is " << user << ". "
88 RUNNER_ASSERT_MSG(m_privilege == privilege,
89 "assertAction failed: unexpected privilege value " << m_privilege
90 << ", expected value is " << privilege << ". "
94 void AgentRequest::assertCancel()
96 RUNNER_ASSERT_MSG(m_valid,
97 "assertCancel failed: request is not valid. "
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 << ". "
103 RUNNER_ASSERT_MSG(m_data.empty(),
104 "assertCancel failed: m_data is not empty. "
106 RUNNER_ASSERT_MSG(m_client.empty(),
107 "assertCancel failed: m_client is not empty. "
109 RUNNER_ASSERT_MSG(m_user.empty(),
110 "assertCancel failed: m_user is not empty. "
112 RUNNER_ASSERT_MSG(m_privilege.empty(),
113 "assertCancel failed: m_privilege is not empty. "
117 } // namespace CynaraTestAgent