• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 "template_cache_manager_test.h"
17 
18 #include "iam_common_defines.h"
19 #include "template_cache_manager.h"
20 #include "os_account_manager.h"
21 #include "system_ability_definition.h"
22 #include "system_ability_status_change_stub.h"
23 
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
27 using namespace testing;
28 using namespace testing::ext;
29 
SetUpTestCase()30 void TemplateCacheManagerTest::SetUpTestCase()
31 {
32 }
33 
TearDownTestCase()34 void TemplateCacheManagerTest::TearDownTestCase()
35 {
36 }
37 
SetUp()38 void TemplateCacheManagerTest::SetUp()
39 {
40 }
41 
TearDown()42 void TemplateCacheManagerTest::TearDown()
43 {
44 }
45 
46 using OsAccountSubscriber = AccountSA::OsAccountSubscriber;
47 using OsAccountSubscribeInfo = AccountSA::OsAccountSubscribeInfo;
48 using OS_ACCOUNT_SUBSCRIBE_TYPE = AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE;
49 
50 class ServiceStatusListener : public OHOS::SystemAbilityStatusChangeStub, public NoCopyable {
51 public:
52     static sptr<ServiceStatusListener> GetInstance();
53     static void Subscribe();
54 
55     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
56     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
57 
58 private:
ServiceStatusListener()59     ServiceStatusListener() {};
~ServiceStatusListener()60     ~ServiceStatusListener() override {};
61 };
62 
63 class OsAccountIdSubscriber : public OsAccountSubscriber, public NoCopyable {
64 public:
65     explicit OsAccountIdSubscriber(const OsAccountSubscribeInfo &subscribeInfo);
66     ~OsAccountIdSubscriber() = default;
67 
68     static std::shared_ptr<OsAccountIdSubscriber> GetInstance();
69     static void Subscribe();
70     static void Unsubscribe();
71     void OnAccountsChanged(const int& id) override;
72 };
73 
74 HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTest_001, TestSize.Level0)
75 {
76     EXPECT_NO_THROW({
77         TemplateCacheManager::GetInstance().UpdateTemplateCache(PIN);
78         TemplateCacheManager::GetInstance().ProcessUserIdChange(1);
79         TemplateCacheManager::GetInstance().ProcessUserIdChange(1);
80         TemplateCacheManager::GetInstance().UpdateTemplateCache(PIN);
81     });
82 }
83 
84 HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnAddSystemAbility, TestSize.Level0)
85 {
86     int32_t systemAbilityId = 1;
87     const std::string deviceId = "123";
88     EXPECT_NO_THROW({
89         ServiceStatusListener::GetInstance()->OnAddSystemAbility(systemAbilityId, deviceId);
90     });
91 }
92 
93 HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnRemoveSystemAbility_001, TestSize.Level0)
94 {
95     int32_t systemAbilityId = 1;
96     const std::string deviceId = "123";
97     EXPECT_NO_THROW({
98         ServiceStatusListener::GetInstance()->OnRemoveSystemAbility(systemAbilityId, deviceId);
99     });
100 }
101 
102 HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnRemoveSystemAbility_002, TestSize.Level0)
103 {
104     int32_t systemAbilityId = 200;
105     const std::string deviceId = "123";
106     EXPECT_NO_THROW({
107         ServiceStatusListener::GetInstance()->OnAddSystemAbility(systemAbilityId, deviceId);
108     });
109 }
110 
111 HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestUnsubscribe, TestSize.Level0)
112 {
113     EXPECT_NO_THROW({
114         OsAccountIdSubscriber::GetInstance()->Unsubscribe();
115     });
116 }
117 
118 HWTEST_F(TemplateCacheManagerTest, TemplateCacheManagerTestOnAccountsChanged, TestSize.Level0)
119 {
120     const int id = 1;
121     EXPECT_NO_THROW({
122         OsAccountIdSubscriber::GetInstance()->OnAccountsChanged(id);
123     });
124 }
125 } // namespace UserAuth
126 } // namespace UserIam
127 } // namespace OHOS