Merge branch 'ckm' into tizen
[platform/core/test/security-tests.git] / src / common / sm_sharing_request.cpp
1 /*
2  * Copyright (c) 2014-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 #include <sm_sharing_request.h>
18
19 #include <dpl/test/test_runner.h>
20
21 namespace SecurityManagerTest {
22
23 SharingRequest::SharingRequest()
24     : m_req(nullptr)
25 {
26     int result = security_manager_private_sharing_req_new(&m_req);
27     RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
28                       "creation of new request failed. Result: " << result);
29     RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
30 }
31
32 SharingRequest::~SharingRequest()
33 {
34     security_manager_private_sharing_req_free(m_req);
35 }
36
37 void SharingRequest::setOwnerAppId(const std::string &appId, lib_retcode expectedResult)
38 {
39     int result = security_manager_private_sharing_req_set_owner_appid(m_req, appId.c_str());
40     RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
41                       "setting app id returned wrong value."
42                           << " App id: " << appId << ";"
43                           << " Result: " << result << ";"
44                           << " Expected result: " << expectedResult);
45     m_appId = appId;
46 }
47
48 void SharingRequest::setTargetAppId(const std::string &appId, lib_retcode expectedResult)
49 {
50     int result = security_manager_private_sharing_req_set_target_appid(m_req, appId.c_str());
51     RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
52                       "setting app id returned wrong value."
53                           << " App id: " << appId << ";"
54                           << " Result: " << result << ";"
55                           << " Expected result: " << expectedResult);
56     m_appId = appId;
57 }
58
59 void SharingRequest::addPaths(const char **paths, size_t pathCount, lib_retcode expectedResult)
60 {
61     int result = security_manager_private_sharing_req_add_paths(m_req, paths, pathCount);
62     RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
63                       "adding path returned wrong value."
64                           << " Result: " << result << ";"
65                           << " Expected result: " << expectedResult);
66     for (size_t i = 0; i < pathCount; i++) {
67         m_paths.push_back(paths[i]);
68     }
69 }
70
71 std::ostream& operator<<(std::ostream &os, const SharingRequest &request)
72 {
73
74     os << "app id: " << request.m_appId << "; ";
75     os << "pkg id: " << request.m_pkgId << "; ";
76
77     if (!request.m_paths.empty()) {
78         os << "paths: [ " << "< " << request.m_paths[0] << ">";
79         for (size_t i=1; i < request.m_paths.size(); ++i) {
80             os << "; < " << request.m_paths[i] << ">";
81         }
82         os << " ]";
83     }
84     return os;
85 }
86
87 } // namespace SecurityManagerTest