2 * Copyright (c) 2014-2016 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 <sm_request.h>
19 #include <dpl/test/test_runner.h>
21 namespace SecurityManagerTest {
23 InstallRequest::InstallRequest()
30 int result = security_manager_app_inst_req_new(&m_req);
31 RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
32 "creation of new request failed. Result: " << result);
33 RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
36 InstallRequest::~InstallRequest()
38 security_manager_app_inst_req_free(m_req);
41 void InstallRequest::setAppTizenVersion(const char * tizenVer, lib_retcode expectedResult)
43 int result = security_manager_app_inst_req_set_target_version(m_req, tizenVer);
44 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
45 "setting app id returned wrong value."
46 << " Tizen version: " << tizenVer << ";"
47 << " Result: " << result << ";"
48 << " Expected result: " << expectedResult);
49 m_tizenVer = std::string(tizenVer);
52 void InstallRequest::setAppId(const char *appId, lib_retcode expectedResult)
54 int result = security_manager_app_inst_req_set_app_id(m_req, appId);
55 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
56 "setting app id returned wrong value."
57 << " App id: " << appId << ";"
58 << " Result: " << result << ";"
59 << " Expected result: " << expectedResult);
63 void InstallRequest::setPkgId(const char *pkgId, lib_retcode expectedResult)
65 int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId);
66 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
67 "setting pkg id returned wrong value."
68 << " Pkg id: " << pkgId << ";"
69 << " Result: " << result << ";"
70 << " Expected result: " << expectedResult);
74 void InstallRequest::addPrivilege(const char *privilege, lib_retcode expectedResult)
76 int result = security_manager_app_inst_req_add_privilege(m_req, privilege);
77 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
78 "adding privilege returned wrong value."
79 << " Privilege: " << privilege << ";"
80 << " Result: " << result << ";"
81 << " Expected result: " << expectedResult);
82 m_privileges.push_back(privilege);
85 void InstallRequest::addPath(const char *path, app_install_path_type pathType, lib_retcode expectedResult)
87 int result = security_manager_app_inst_req_add_path(m_req, path, pathType);
88 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
89 "adding path returned wrong value."
90 << " Path: " << path << ";"
91 << " Path type: " << pathType << ";"
92 << " Result: " << result << ";"
93 << " Expected result: " << expectedResult);
94 m_paths.push_back(std::pair<std::string, app_install_path_type>(path, pathType));
97 void InstallRequest::setUid(const uid_t uid, lib_retcode expectedResult)
99 int result = security_manager_app_inst_req_set_uid(m_req, uid);
100 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
101 "setting uid returned wrong value."
102 << " Uid: " << uid << ";"
103 << " Result: " << result << ";"
104 << " Expected result: " << expectedResult);
109 void InstallRequest::setAuthorId(const char *authorId, lib_retcode expectedResult)
113 m_authorId.assign(authorId);
115 int result = security_manager_app_inst_req_set_author_id(m_req, authorId);
116 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
117 "setting author id returned wrong value."
118 << " Author id: " << m_authorId << ";"
119 << " Result: " << result << ";"
120 << " Expected result: " << expectedResult);
124 std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
126 if (request.m_appId != nullptr)
127 os << "app id: " << request.m_appId << "; ";
128 if (request.m_pkgId != nullptr)
129 os << "pkg id: " << request.m_pkgId << "; ";
130 if (!request.m_privileges.empty()) {
131 os << "privileges: [ " << request.m_privileges[0];
132 for (size_t i=1; i < request.m_privileges.size(); ++i) {
133 os << "; " << request.m_privileges[i];
137 if (!request.m_paths.empty()) {
138 os << "paths: [ " << "< " << request.m_paths[0].first << "; "
139 << request.m_paths[0].second << " >";
140 for (size_t i=1; i < request.m_paths.size(); ++i) {
141 os << "; < " << request.m_paths[i].first << "; "
142 << request.m_paths[i].second << " >";
146 if (request.m_uid.first)
147 os << "uid: " << request.m_uid.second << "; ";
148 if (!request.m_authorId.empty()) {
149 os << "author id: " << request.m_authorId << "; ";
154 } // namespace SecurityManagerTest