• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <string>
20 #include <vector>
21 #include <iostream>
22 
23 #include "multi_user_manager.h"
24 #include "distributed_device_profile_errors.h"
25 
26 namespace OHOS {
27 namespace DistributedDeviceProfile {
28 using namespace testing::ext;
29 using namespace std;
30 namespace {
31     const std::string TAG = "MultiUserManagerTest";
32 }
33 class MultiUserManagerTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase()41 void MultiUserManagerTest::SetUpTestCase()
42 {
43 }
44 
TearDownTestCase()45 void MultiUserManagerTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void MultiUserManagerTest::SetUp()
50 {
51 }
52 
TearDown()53 void MultiUserManagerTest::TearDown()
54 {
55 }
56 
57 /*
58  * @tc.name: init
59  * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD
60  * @tc.type: FUNC
61  */
62 HWTEST_F(MultiUserManagerTest, init_001, TestSize.Level1)
63 {
64     int32_t ret = MultiUserManager::GetInstance().Init();
65     EXPECT_EQ(ret, DP_SUCCESS);
66 }
67 
68 /*
69  * @tc.name: UnInit
70  * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD
71  * @tc.type: FUNC
72  */
73 HWTEST_F(MultiUserManagerTest, UnInit_001, TestSize.Level1)
74 {
75     int32_t ret = MultiUserManager::GetInstance().UnInit();
76     EXPECT_EQ(ret, DP_SUCCESS);
77 }
78 
79 /*
80  * @tc.name: UnInit
81  * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD
82  * @tc.type: FUNC
83  */
84 HWTEST_F(MultiUserManagerTest, SetCurrentForegroundUserID_001, TestSize.Level1)
85 {
86     int32_t userId = 0;
87     MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId);
88     EXPECT_EQ(MultiUserManager::GetInstance().foregroundUserId_, userId);
89 }
90 
91 /*
92  * @tc.name: GetCurrentForegroundUserID
93  * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD
94  * @tc.type: FUNC
95  */
96 HWTEST_F(MultiUserManagerTest, GetCurrentForegroundUserID_001, TestSize.Level1)
97 {
98     int32_t userId = 0;
99     MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId);
100     int32_t ret = MultiUserManager::GetInstance().GetCurrentForegroundUserID();
101     EXPECT_EQ(ret, MultiUserManager::GetInstance().foregroundUserId_);
102 }
103 
104 /*
105  * @tc.name: GetForegroundUserIDFromOs
106  * @tc.desc: Normal testCase of MultiUserManagerTest for CRUD
107  * @tc.type: FUNC
108  */
109 HWTEST_F(MultiUserManagerTest, GetForegroundUserIDFromOs_001, TestSize.Level1)
110 {
111     int32_t foregroundId = 0;
112     int32_t userId = 0;
113     MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId);
114     int32_t ret = MultiUserManager::GetInstance().GetForegroundUserIDFromOs(foregroundId);
115     EXPECT_EQ(ret, DP_SUCCESS);
116 }
117 } // namespace DistributedDeviceProfile
118 } // namespace OHOS