1 /*
2  * Copyright (c) 2021-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 "mock_inner_app_account_manager.h"
17 
18 #include "account_log_wrapper.h"
19 
20 namespace {
21 const std::string STRING_NAME = "name";
22 const std::string STRING_EXTRA_INFO = "extra_info";
23 const std::string STRING_OWNER = "com.example.owner";
24 }  // namespace
25 
26 namespace OHOS {
27 namespace AccountSA {
MockInnerAppAccountManager()28 MockInnerAppAccountManager::MockInnerAppAccountManager()
29 {
30     ACCOUNT_LOGI("mock enter");
31 }
32 
~MockInnerAppAccountManager()33 MockInnerAppAccountManager::~MockInnerAppAccountManager()
34 {
35     ACCOUNT_LOGI("mock enter");
36 }
37 
AddAccount(const std::string & name,const std::string & extraInfo,const std::string & bundleName,const uint32_t & appIndex)38 ErrCode MockInnerAppAccountManager::AddAccount(
39     const std::string &name, const std::string &extraInfo, const std::string &bundleName, const uint32_t &appIndex)
40 {
41     ACCOUNT_LOGI("mock enter");
42 
43     ACCOUNT_LOGI("mock name = %{public}s", name.c_str());
44     ACCOUNT_LOGI("mock extraInfo = %{public}s", extraInfo.c_str());
45 
46     if (name != STRING_NAME) {
47         return ERR_APPACCOUNT_SERVICE_OTHER;
48     }
49 
50     if (extraInfo != STRING_EXTRA_INFO) {
51         return ERR_APPACCOUNT_SERVICE_OTHER;
52     }
53 
54     return ERR_OK;
55 }
56 
DeleteAccount(const std::string & name,const std::string & bundleName,const uint32_t & appIndex)57 ErrCode MockInnerAppAccountManager::DeleteAccount(
58     const std::string &name, const std::string &bundleName, const uint32_t &appIndex)
59 {
60     ACCOUNT_LOGI("mock enter");
61 
62     ACCOUNT_LOGI("mock name = %{public}s", name.c_str());
63 
64     if (name != STRING_NAME) {
65         return ERR_APPACCOUNT_SERVICE_OTHER;
66     }
67 
68     return ERR_OK;
69 }
70 
SubscribeAppAccount(const AppAccountSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & eventListener,const std::string & bundleName,const uint32_t & appIndex)71 ErrCode MockInnerAppAccountManager::SubscribeAppAccount(const AppAccountSubscribeInfo &subscribeInfo,
72     const sptr<IRemoteObject> &eventListener, const std::string &bundleName, const uint32_t &appIndex)
73 {
74     ACCOUNT_LOGI("mock enter");
75 
76     std::vector<std::string> owners;
77     if (subscribeInfo.GetOwners(owners) != ERR_OK) {
78         ACCOUNT_LOGE("mock failed to get owners");
79         return ERR_APPACCOUNT_SERVICE_OTHER;
80     }
81 
82     if (owners.size() == 0) {
83         ACCOUNT_LOGE("mock owners.size() = %{public}zu", owners.size());
84         return ERR_APPACCOUNT_SERVICE_OTHER;
85     }
86 
87     auto owner = owners.front();
88     if (owner != STRING_OWNER) {
89         return ERR_APPACCOUNT_SERVICE_OTHER;
90     }
91 
92     return ERR_OK;
93 }
94 
UnsubscribeAppAccount(const sptr<IRemoteObject> & eventListener)95 ErrCode MockInnerAppAccountManager::UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener)
96 {
97     ACCOUNT_LOGI("mock enter");
98 
99     return ERR_OK;
100 }
101 }  // namespace AccountSA
102 }  // namespace OHOS
103