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