Add tests for cynara-creds-dbus
[platform/core/test/security-tests.git] / src / cynara-tests / common / cynara_test_helpers.cpp
1 /*
2  * Copyright (c) 2015-2016 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        cynara_test_helpers.cpp
18  * @author      Aleksander Zdyb <a.zdyb@samsung.com>
19  * @version     1.0
20  * @brief       Helpers for cynara-helpers
21  */
22
23 #include <dpl/test/test_runner.h>
24
25 #include <cynara-creds-dbus.h>
26 #include <cynara-creds-socket.h>
27
28 #include "cynara_test_helpers.h"
29
30 namespace CynaraHelperCredentials {
31
32 char *socketGetClient(int sock, cynara_client_creds method, int expectedResult) {
33     char *buff;
34     auto ret = cynara_creds_socket_get_client(sock, method, &buff);
35     RUNNER_ASSERT_MSG(ret == expectedResult,
36                       "cynara_creds_socket_get_client failed, ret = " << ret
37                       << "; expected = " << expectedResult);
38     return buff;
39 }
40
41 char *socketGetUser(int sock, cynara_user_creds method, int expectedResult) {
42     char *buff;
43     auto ret = cynara_creds_socket_get_user(sock, method, &buff);
44     RUNNER_ASSERT_MSG(ret == expectedResult,
45                       "cynara_creds_socket_get_user failed, ret = " << ret
46                       << "; expected = " << expectedResult);
47     return buff;
48 }
49
50 pid_t socketGetPid(int sock, int expectedResult) {
51     pid_t pid;
52     auto ret = cynara_creds_socket_get_pid(sock, &pid);
53     RUNNER_ASSERT_MSG(ret == expectedResult,
54                       "cynara_creds_socket_get_pid failed, ret = " << ret << "; expected = "
55                       << expectedResult);
56     return pid;
57 }
58
59 char *dbusGetClient(DBusConnectionPtr connection, const char *uniqueName,
60                     cynara_client_creds method, int expectedResult) {
61     char *buff;
62     auto ret = cynara_creds_dbus_get_client(connection.get(), uniqueName, method, &buff);
63     RUNNER_ASSERT_MSG(ret == expectedResult,
64                       "cynara_creds_dbus_get_client failed, ret = " << ret
65                       << "; expected = " << expectedResult);
66     return buff;
67 }
68
69 char *dbusGetUser(DBusConnectionPtr connection, const char *uniqueName, cynara_user_creds method,
70                   int expectedResult) {
71     char *buff;
72     auto ret = cynara_creds_dbus_get_user(connection.get(), uniqueName, method, &buff);
73     RUNNER_ASSERT_MSG(ret == expectedResult,
74                       "cynara_creds_dbus_get_user failed, ret = " << ret
75                       << "; expected = " << expectedResult);
76     return buff;
77 }
78
79 pid_t dbusGetPid(DBusConnectionPtr connection, const char *uniqueName, int expectedResult) {
80     pid_t pid;
81     auto ret = cynara_creds_dbus_get_pid(connection.get(), uniqueName, &pid);
82     RUNNER_ASSERT_MSG(ret == expectedResult, "cynara_creds_dbus_get_pid failed, ret = " << ret
83                                              << "; expected = " << expectedResult);
84     return pid;
85 }
86
87 } //namespace CynaraHelperCredentials