• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #define private public
19 #include "mock_iremote_object.h"
20 #include "on_demand_start_stop_sa.h"
21 #include "system_ability_definition.h"
22 
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace MiscServices {
26 class OnDemandStartStopSaTest : public testing::Test { };
27 
28 /**
29  * @tc.name: OnDemandStartSaTest
30  * @tc.desc:
31  * @tc.type: FUNC
32  * @tc.require:
33  * @tc.author:
34  */
35 HWTEST_F(OnDemandStartStopSaTest, OnDemandStartSaTest, TestSize.Level1)
36 {
37     auto remote = OnDemandStartStopSa::GetInputMethodSystemAbility();
38     EXPECT_NE(nullptr, remote);
39 
40     remote = OnDemandStartStopSa::GetInputMethodSystemAbility(true);
41     EXPECT_NE(nullptr, remote);
42 
43     remote = OnDemandStartStopSa::GetInputMethodSystemAbility(false);
44     EXPECT_NE(nullptr, remote);
45 }
46 
47 /**
48  * @tc.name: OnDemandStopSaTest
49  * @tc.desc:
50  * @tc.type: FUNC
51  * @tc.require:
52  * @tc.author:
53  */
54 HWTEST_F(OnDemandStartStopSaTest, OnDemandStopSaTest, TestSize.Level1)
55 {
56     auto onDemandStartStopSa = std::make_shared<OnDemandStartStopSa>();
57     ASSERT_NE(nullptr, onDemandStartStopSa);
58 
59     onDemandStartStopSa->UnloadInputMethodSystemAbility();
60 }
61 
62 /**
63  * @tc.name: LoadSystemAbilityTest
64  * @tc.desc:
65  * @tc.type: FUNC
66  * @tc.require:
67  * @tc.author:
68  */
69 HWTEST_F(OnDemandStartStopSaTest, LoadSystemAbilityTest, TestSize.Level1)
70 {
71     auto onDemandStartStopSa = std::make_shared<OnDemandStartStopSa>();
72     ASSERT_NE(nullptr, onDemandStartStopSa);
73 
74     auto systemAbility = onDemandStartStopSa->LoadInputMethodSystemAbility();
75     EXPECT_NE(nullptr, systemAbility);
76 }
77 
78 /**
79  * @tc.name: SaLoadCallBackTest
80  * @tc.desc:
81  * @tc.type: FUNC
82  * @tc.require:
83  * @tc.author:
84  */
85 HWTEST_F(OnDemandStartStopSaTest, SaLoadCallBackTest, TestSize.Level1)
86 {
87     auto onDemandStartStopSa = std::make_shared<OnDemandStartStopSa>();
88     ASSERT_NE(nullptr, onDemandStartStopSa);
89 
90     sptr<OnDemandStartStopSa::SaLoadCallback> callback =
91         new (std::nothrow) OnDemandStartStopSa::SaLoadCallback(onDemandStartStopSa);
92     ASSERT_NE(nullptr, callback);
93 
94     sptr<IRemoteObject> object = new (std::nothrow) MockIRemoteObject();
95     ASSERT_NE(nullptr, object);
96     callback->OnLoadSystemAbilitySuccess(INPUT_METHOD_SYSTEM_ABILITY_ID, object);
97     EXPECT_NE(nullptr, onDemandStartStopSa->remoteObj_);
98     callback->OnLoadSystemAbilityFail(INPUT_METHOD_SYSTEM_ABILITY_ID);
99     EXPECT_EQ(nullptr, onDemandStartStopSa->remoteObj_);
100 }
101 } // namespace MiscServices
102 } // namespace OHOS
103