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 constexpr int32_t ERR_ACCOUNT_COMMON_PERMISSION_DENIED = 0x400008; 27 class OsAccountManagerHelperTest : public testing::Test { 28 public: SetUpTestSuite()29 static void SetUpTestSuite() {}; TearDownTestSuite()30 static void TearDownTestSuite() {}; SetUp()31 void SetUp() override {}; TearDown()32 void TearDown() override {}; 33 }; 34 35 /** 36 * @tc.number : GetCurrentCallingUserId_00100 37 * @tc.name : GetCurrentCallingUserId_00100 38 * @tc.desc : test GetCurrentCallingUserId function 39 */ 40 HWTEST_F(OsAccountManagerHelperTest, GetCurrentCallingUserId_00100, Function | SmallTest | Level1) 41 { 42 int32_t userId = -1; 43 ASSERT_EQ(ERR_OK, OsAccountManagerHelper::GetInstance().GetCurrentCallingUserId(userId)); 44 } 45 46 /** 47 * @tc.number : GetOsAccountLocalIdFromUid_00100 48 * @tc.name : GetOsAccountLocalIdFromUid_00100 49 * @tc.desc : test GetOsAccountLocalIdFromUid function 50 */ 51 HWTEST_F(OsAccountManagerHelperTest, GetOsAccountLocalIdFromUid_00100, Function | SmallTest | Level1) 52 { 53 int32_t userId = -1; 54 const int uid = 0; 55 ASSERT_EQ(ERR_OK, OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uid, userId)); 56 } 57 58 /** 59 * @tc.number : GetCurrentActiveUserId_00100 60 * @tc.name : GetCurrentActiveUserId_00100 61 * @tc.desc : test GetCurrentActiveUserId function 62 */ 63 HWTEST_F(OsAccountManagerHelperTest, GetCurrentActiveUserId_00100, Function | SmallTest | Level1) 64 { 65 int32_t userId = -1; 66 ASSERT_EQ(ERR_OK, OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId)); 67 } 68 69 /** 70 * @tc.number : CheckUserExists_00100 71 * @tc.name : CheckUserExists_00100 72 * @tc.desc : test CheckUserExists function 73 */ 74 HWTEST_F(OsAccountManagerHelperTest, CheckUserExists_00100, Function | SmallTest | Level1) 75 { 76 int32_t userId = 100; 77 ASSERT_EQ(true, OsAccountManagerHelper::GetInstance().CheckUserExists(userId)); 78 } 79 80 /** 81 * @tc.number : CheckUserExists_00200 82 * @tc.name : CheckUserExists_00200 83 * @tc.desc : test CheckUserExists function 84 */ 85 HWTEST_F(OsAccountManagerHelperTest, CheckUserExists_00200, Function | SmallTest | Level1) 86 { 87 int32_t userId = 1099; 88 ASSERT_EQ(false, OsAccountManagerHelper::GetInstance().CheckUserExists(userId)); 89 } 90 91 /** 92 * @tc.number : IsSystemAccount_0100 93 * @tc.name : IsSystemAccount_0100 94 * @tc.desc : test IsSystemAccount function, 100 is true(100 <= userId <= 10736) 95 */ 96 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0100, Function | SmallTest | Level1) 97 { 98 int32_t userId = 100; 99 ASSERT_EQ(true, OsAccountManagerHelper::IsSystemAccount(userId)); 100 } 101 102 /** 103 * @tc.number : IsSystemAccount_0200 104 * @tc.name : IsSystemAccount_0200 105 * @tc.desc : test IsSystemAccount function, 1100 is false(100 <= userId <= 10736) 106 */ 107 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0200, Function | SmallTest | Level1) 108 { 109 int32_t userId = 10737; 110 ASSERT_EQ(false, OsAccountManagerHelper::IsSystemAccount(userId)); 111 } 112 113 /** 114 * @tc.number : IsSystemAccount_0300 115 * @tc.name : IsSystemAccount_0300 116 * @tc.desc : test IsSystemAccount function, 0 is false(100 <= userId <= 10736) 117 */ 118 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0300, Function | SmallTest | Level1) 119 { 120 int32_t userId = 0; 121 ASSERT_EQ(false, OsAccountManagerHelper::IsSystemAccount(userId)); 122 } 123 124 /** 125 * @tc.number : IsSystemAccount_0400 126 * @tc.name : IsSystemAccount_0400 127 * @tc.desc : test IsSystemAccount function, 1099 is true(100 <= userId <= 10736) 128 */ 129 HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0400, Function | SmallTest | Level1) 130 { 131 int32_t userId = 10736; 132 ASSERT_EQ(true, OsAccountManagerHelper::IsSystemAccount(userId)); 133 } 134 135 /** 136 * @tc.number : GetAllOsAccount_001 137 * @tc.name : GetAllOsAccount_001 138 * @tc.desc : test GetAllOsAccount function. 139 */ 140 HWTEST_F(OsAccountManagerHelperTest, GetAllOsAccount_001, Function | SmallTest | Level1) 141 { 142 std::vector<int32_t> userIds; 143 ASSERT_EQ(OsAccountManagerHelper::GetInstance().GetAllOsAccount(userIds), false); 144 } 145 146 /** 147 * @tc.number : GetOsAccountPrivateStatus_Test_001 148 * @tc.name : GetOsAccountPrivateStatus_Test_001 149 * @tc.desc : test GetAllOsAccount function. 150 */ 151 HWTEST_F(OsAccountManagerHelperTest, GetOsAccountPrivateStatus_Test_001, Function | SmallTest | Level1) 152 { 153 bool isPrivate = false; 154 ASSERT_EQ(OsAccountManagerHelper::GetInstance().GetOsAccountPrivateStatus(isPrivate), false); 155 } 156 } 157 }