1 /*
2  * Copyright (c) 2022 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 <functional>
17 #include <gtest/gtest.h>
18 
19 #include "os_account_manager_helper.h"
20 #include "accesstoken_kit.h"
21 
22 
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace Notification {
26 class OsAccountManagerHelperTest : public testing::Test {
27 public:
SetUpTestSuite()28     static void SetUpTestSuite() {};
TearDownTestSuite()29     static void TearDownTestSuite() {};
SetUp()30     void SetUp() override {};
TearDown()31     void TearDown() override {};
32 };
33 
34 /**
35  * @tc.number    : GetCurrentCallingUserId_00100
36  * @tc.name      : GetCurrentCallingUserId_00100
37  * @tc.desc      : test GetCurrentCallingUserId function
38  */
39 HWTEST_F(OsAccountManagerHelperTest, GetCurrentCallingUserId_00100, Function | SmallTest | Level1)
40 {
41     int32_t userId = -1;
42     ASSERT_EQ(ERR_OK, OsAccountManagerHelper::GetInstance().GetCurrentCallingUserId(userId));
43 }
44 
45 /**
46  * @tc.number    : GetOsAccountLocalIdFromUid_00100
47  * @tc.name      : GetOsAccountLocalIdFromUid_00100
48  * @tc.desc      : test GetOsAccountLocalIdFromUid function
49  */
50 HWTEST_F(OsAccountManagerHelperTest, GetOsAccountLocalIdFromUid_00100, Function | SmallTest | Level1)
51 {
52     int32_t userId = -1;
53     const int uid = 0;
54     ASSERT_EQ(ERR_OK, OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uid, userId));
55 }
56 
57 /**
58  * @tc.number    : GetCurrentActiveUserId_00100
59  * @tc.name      : GetCurrentActiveUserId_00100
60  * @tc.desc      : test GetCurrentActiveUserId function
61  */
62 HWTEST_F(OsAccountManagerHelperTest, GetCurrentActiveUserId_00100, Function | SmallTest | Level1)
63 {
64     int32_t userId = -1;
65     ASSERT_EQ(ERR_OK, OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId));
66 }
67 
68 /**
69  * @tc.number    : CheckUserExists_00100
70  * @tc.name      : CheckUserExists_00100
71  * @tc.desc      : test CheckUserExists function
72  */
73 HWTEST_F(OsAccountManagerHelperTest, CheckUserExists_00100, Function | SmallTest | Level1)
74 {
75     int32_t userId = 100;
76     ASSERT_EQ(true, OsAccountManagerHelper::GetInstance().CheckUserExists(userId));
77 }
78 
79 /**
80  * @tc.number    : CheckUserExists_00200
81  * @tc.name      : CheckUserExists_00200
82  * @tc.desc      : test CheckUserExists function
83  */
84 HWTEST_F(OsAccountManagerHelperTest, CheckUserExists_00200, Function | SmallTest | Level1)
85 {
86     int32_t userId = 1099;
87     ASSERT_EQ(false, OsAccountManagerHelper::GetInstance().CheckUserExists(userId));
88 }
89 
90 /**
91  * @tc.number    : IsSystemAccount_0100
92  * @tc.name      : IsSystemAccount_0100
93  * @tc.desc      : test IsSystemAccount function, 100 is true(100 <= userId <= 10736)
94  */
95 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0100, Function | SmallTest | Level1)
96 {
97     int32_t userId = 100;
98     ASSERT_EQ(true, OsAccountManagerHelper::IsSystemAccount(userId));
99 }
100 
101 /**
102  * @tc.number    : IsSystemAccount_0200
103  * @tc.name      : IsSystemAccount_0200
104  * @tc.desc      : test IsSystemAccount function, 1100 is false(100 <= userId <= 10736)
105  */
106 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0200, Function | SmallTest | Level1)
107 {
108     int32_t userId = 10737;
109     ASSERT_EQ(false, OsAccountManagerHelper::IsSystemAccount(userId));
110 }
111 
112 /**
113  * @tc.number    : IsSystemAccount_0300
114  * @tc.name      : IsSystemAccount_0300
115  * @tc.desc      : test IsSystemAccount function, 0 is false(100 <= userId <= 10736)
116  */
117 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0300, Function | SmallTest | Level1)
118 {
119     int32_t userId = 0;
120     ASSERT_EQ(false, OsAccountManagerHelper::IsSystemAccount(userId));
121 }
122 
123 /**
124  * @tc.number    : IsSystemAccount_0400
125  * @tc.name      : IsSystemAccount_0400
126  * @tc.desc      : test IsSystemAccount function, 1099 is true(100 <= userId <= 10736)
127  */
128 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0400, Function | SmallTest | Level1)
129 {
130     int32_t userId = 10736;
131     ASSERT_EQ(true, OsAccountManagerHelper::IsSystemAccount(userId));
132 }
133 }
134 }