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 <sm_user_request.h>
19 #include <dpl/test/test_runner.h>
21 namespace SecurityManagerTest {
23 UserRequest::UserRequest()
26 , m_utype(false, static_cast<security_manager_user_type>(0))
28 int result = security_manager_user_req_new(&m_req);
29 RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
30 "creation of new request failed. Result: " << result);
31 RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
34 UserRequest::~UserRequest()
36 security_manager_user_req_free(m_req);
39 void UserRequest::setUid(const uid_t uid, lib_retcode expectedResult)
41 int result = security_manager_user_req_set_uid(m_req, uid);
42 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
43 "setting uid returned wrong value."
44 << " Uid: " << uid << ";"
45 << " Result: " << result << ";"
46 << " Expected result: " << expectedResult);
51 void UserRequest::setUserType(const security_manager_user_type utype, lib_retcode expectedResult)
53 int result = security_manager_user_req_set_user_type(m_req, utype);
54 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
55 "setting user type returned wrong value."
56 << " User type: " << utype << ";"
57 << " Result: " << result << ";"
58 << " Expected result: " << expectedResult);
60 m_utype.second = utype;
63 std::ostream& operator<<(std::ostream &os, const UserRequest &request)
65 if (request.m_uid.first)
66 os << "uid: " << request.m_uid.second << "; ";
68 if (request.m_utype.first)
69 os << "utype: " << request.m_utype.second << "; ";
74 } // namespace SecurityManagerTest