Fix security_manager_02_app_install_uninstall_full test
[platform/core/test/security-tests.git] / tests / common / temp_test_user.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 /*
18  * @file        temp_test_user.cpp
19  * @author      Jan Cybulski (j.cybulski@partner.samsung.com)
20  * @version     1.0
21  * @brief       File with class for users management
22  */
23
24
25 #include <temp_test_user.h>
26 #include <glib-object.h>
27 #include <dpl/test/test_runner.h>
28
29 void TemporaryTestUser::create(void)
30 {
31     if (m_guser) {
32         remove();
33     };
34
35     m_guser = gum_user_create_sync (m_offline);
36     RUNNER_ASSERT_MSG(m_guser != nullptr, "Failed to create gumd user object");
37     g_object_set(G_OBJECT(m_guser), "usertype", m_userType, NULL);
38     g_object_set(G_OBJECT(m_guser), "username", m_userName.c_str(), NULL);
39     gboolean added = gum_user_add_sync(m_guser);
40     RUNNER_ASSERT_MSG(added, "Failed to add user");
41     g_object_get(G_OBJECT(m_guser), "uid", &m_uid, NULL);
42     RUNNER_ASSERT_MSG(m_uid != 0, "Something strange happened during user creation. uid == 0.");
43     g_object_get(G_OBJECT(m_guser), "gid", &m_gid, NULL);
44     RUNNER_ASSERT_MSG(m_gid != 0, "Something strange happened during user creation. gid == 0.");
45 }
46
47 void TemporaryTestUser::remove(void)
48 {
49     if(m_guser){
50         gum_user_delete_sync(m_guser, TRUE);
51         g_object_unref(m_guser);
52         m_guser = nullptr;
53     }
54 }
55
56 TemporaryTestUser::~TemporaryTestUser()
57 {
58     this->remove();
59 }