• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #include "account_error_no.h"
19 #include "os_account_manager_wrapper.h"
20 #include "mock_sa_call.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace {
28 const int32_t UID = 0;
29 const int32_t ACCOUNT_ID = 0;
30 const int32_t ACCOUNT_VALUE = -1;
31 const int32_t RESULT_OK = 0;
32 const std::string ACCOUNT_NAME = "ACCOUNT";
33 }  // namespace
34 class OsAccountManagerWrapperTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40 };
41 
SetUpTestCase()42 void OsAccountManagerWrapperTest::SetUpTestCase()
43 {}
44 
TearDownTestCase()45 void OsAccountManagerWrapperTest::TearDownTestCase()
46 {}
47 
SetUp()48 void OsAccountManagerWrapperTest::SetUp()
49 {}
50 
TearDown()51 void OsAccountManagerWrapperTest::TearDown()
52 {}
53 
54 /**
55  * @tc.name: GetOsAccountLocalIdFromUid_0100
56  * @tc.desc: get os account local Id from Uid.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(OsAccountManagerWrapperTest, GetOsAccountLocalIdFromUid_0100, TestSize.Level1)
60 {
61     int account = ACCOUNT_VALUE;
62     int ret = DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->GetOsAccountLocalIdFromUid(UID, account);
63     EXPECT_EQ(account, ACCOUNT_ID);
64     EXPECT_EQ(ret, RESULT_OK);
65 }
66 
67 /**
68  * @tc.name: GetOsAccountLocalIdFromProcess_0100
69  * @tc.desc: get os account local Id from process.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(OsAccountManagerWrapperTest, GetOsAccountLocalIdFromProcess_0100, TestSize.Level1)
73 {
74     int account = ACCOUNT_VALUE;
75     int ret = DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->GetOsAccountLocalIdFromProcess(account);
76     EXPECT_EQ(ret, RESULT_OK);
77 }
78 
79 /**
80  * @tc.name: IsOsAccountExists_0100
81  * @tc.desc: Is os account exists.
82  * @tc.type: FUNC
83  */
84 HWTEST_F(OsAccountManagerWrapperTest, IsOsAccountExists_0100, TestSize.Level2)
85 {
86     bool isOsAccountExists = false;
87     DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->IsOsAccountExists(ACCOUNT_VALUE, isOsAccountExists);
88     EXPECT_EQ(isOsAccountExists, false);
89 }
90 
91 /**
92  * @tc.name: CreateOsAccount_0100
93  * @tc.desc: Create os account.
94  * @tc.type: FUNC
95  */
96 HWTEST_F(OsAccountManagerWrapperTest, CreateOsAccount_0100, TestSize.Level1)
97 {
98     AAFwk::IsMockSaCall::IsMockSpecificSystemAbilityAccessPermission();
99     int account = ACCOUNT_VALUE;
100     int ret = DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->CreateOsAccount(ACCOUNT_NAME, account);
101     EXPECT_NE(ret, ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR);
102 }
103 
104 /**
105  * @tc.name: RemoveOsAccount_0100
106  * @tc.desc: Remove os account.
107  * @tc.type: FUNC
108  */
109 HWTEST_F(OsAccountManagerWrapperTest, RemoveOsAccount_0100, TestSize.Level1)
110 {
111     AAFwk::IsMockSaCall::IsMockSpecificSystemAbilityAccessPermission();
112     int account = ACCOUNT_VALUE;
113     int ret = DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->CreateOsAccount(ACCOUNT_NAME, account);
114     EXPECT_EQ(ret, ERR_ACCOUNT_COMMON_NAME_HAD_EXISTED);
115     ret = DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->RemoveOsAccount(account);
116     EXPECT_EQ(ret, ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR);
117 }
118 
119 /**
120  * @tc.name: GetCurrentActiveAccountId_0100
121  * @tc.desc: Get current accountId.
122  * @tc.type: FUNC
123  */
124 HWTEST_F(OsAccountManagerWrapperTest, GetCurrentActiveAccountId_0100, TestSize.Level1)
125 {
126     int ret = DelayedSingleton<OsAccountManagerWrapper>::GetInstance()->GetCurrentActiveAccountId();
127     EXPECT_EQ(ret, 100);
128 }
129 }  // namespace AAFwk
130 }  // namespace OHOS
131