033fbecd0d42dd465c71256a5c6fdf7aa0b80dd2
[platform/core/test/security-tests.git] / src / cynara-tests / common / cynara_test_helpers.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  * @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-socket.h>
26
27 #include "cynara_test_helpers.h"
28
29 namespace CynaraHelperCredentials {
30
31 char *socketGetClient(int sock, cynara_client_creds method, int expectedResult) {
32     char *buff;
33     auto ret = cynara_creds_socket_get_client(sock, method, &buff);
34     RUNNER_ASSERT_MSG(ret == expectedResult,
35                       "cynara_creds_socket_get_client failed, ret = " << ret
36                       << "; expected = " << expectedResult);
37     return buff;
38 }
39
40 char *socketGetUser(int sock, cynara_user_creds method, int expectedResult) {
41     char *buff;
42     auto ret = cynara_creds_socket_get_user(sock, method, &buff);
43     RUNNER_ASSERT_MSG(ret == expectedResult,
44                       "cynara_creds_socket_get_user failed, ret = " << ret
45                       << "; expected = " << expectedResult);
46     return buff;
47 }
48
49 pid_t socketGetPid(int sock, int expectedResult) {
50     pid_t pid;
51     auto ret = cynara_creds_socket_get_pid(sock, &pid);
52     RUNNER_ASSERT_MSG(ret == expectedResult,
53                       "cynara_creds_socket_get_pid failed, ret = " << ret << "; expected = "
54                       << expectedResult);
55     return pid;
56 }
57
58 } //namespace CynaraHelperCredentials