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