1 /*
2 * Copyright (c) 2024 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 "lnn_ohos_account_adapter_mock.h"
17
GetInstance()18 OHOS::AccountSA::OhosAccountKits &OHOS::AccountSA::OhosAccountKits::GetInstance()
19 {
20 static OhosAccountKits ohosAccountKits;
21 return ohosAccountKits;
22 }
23
QueryOhosAccountInfo()24 std::pair<bool, OHOS::AccountSA::OhosAccountInfo> OHOS::AccountSA::OhosAccountKits::QueryOhosAccountInfo()
25 {
26 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
27 if (mock == nullptr) {
28 std::pair<bool, OHOS::AccountSA::OhosAccountInfo> account_info = {};
29 return account_info;
30 }
31 return mock->QueryOhosAccountInfo();
32 }
33
IsSameAccountGroupDevice()34 bool OHOS::AccountSA::OhosAccountKits::IsSameAccountGroupDevice()
35 {
36 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
37 if (mock == nullptr) {
38 return false;
39 }
40 return mock->IsSameAccountGroupDevice();
41 }
42
43 namespace OHOS::AccountSA {
OhosAccountKitsMock()44 OhosAccountKitsMock::OhosAccountKitsMock()
45 {
46 mock.store(this);
47 }
48
~OhosAccountKitsMock()49 OhosAccountKitsMock::~OhosAccountKitsMock()
50 {
51 mock.store(nullptr);
52 }
53
54 extern "C" {
IsSameAccountGroupDevice(void)55 bool IsSameAccountGroupDevice(void)
56 {
57 auto mock = OHOS::AccountSA::OhosAccountKitsMock::GetMock();
58 if (mock == nullptr) {
59 return false;
60 }
61 return mock->IsSameAccountGroupDevice();
62 }
63 }
64
65 } // namespace OHOS::AccountSA
66
QueryActiveOsAccountIds(std::vector<int32_t> & ids)67 OHOS::ErrCode OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t> &ids)
68 {
69 auto mock = OHOS::AccountSA::OsAccountManagerMock::GetMock();
70 if (mock == nullptr) {
71 return -1;
72 }
73 return mock->QueryActiveOsAccountIds(ids);
74 }
75
IsOsAccountVerified(const int32_t id,bool & isVerified)76 OHOS::ErrCode OHOS::AccountSA::OsAccountManager::IsOsAccountVerified(const int32_t id, bool &isVerified)
77 {
78 auto mock = OHOS::AccountSA::OsAccountManagerMock::GetMock();
79 if (mock == nullptr) {
80 return -1;
81 }
82 return mock->IsOsAccountVerified(id, isVerified);
83 }
84
85 namespace OHOS::AccountSA {
OsAccountManagerMock()86 OsAccountManagerMock::OsAccountManagerMock()
87 {
88 mock.store(this);
89 }
90
~OsAccountManagerMock()91 OsAccountManagerMock::~OsAccountManagerMock()
92 {
93 mock.store(nullptr);
94 }
95 } // namespace OHOS::AccountSA