• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 <parameter.h>
19 #include "ability_manager_service.h"
20 #include "ability_event_handler.h"
21 
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace AAFwk {
25 
26 class AbilityEventHandlerTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void AbilityEventHandlerTest::SetUpTestCase()
35 {}
36 
TearDownTestCase()37 void AbilityEventHandlerTest::TearDownTestCase()
38 {}
39 
SetUp()40 void AbilityEventHandlerTest::SetUp()
41 {}
42 
TearDown()43 void AbilityEventHandlerTest::TearDown()
44 {}
45 
46 /*
47  * Feature: Ability Event Handler
48  * Function: ProcessEvent
49  * SubFunction: NA
50  * FunctionPoints: Ability Event Handler ProcessEvent
51  * EnvConditions: NA
52  * CaseDescription: Verify ProcessEvent
53  */
54 HWTEST_F(AbilityEventHandlerTest, ability_event_handler_001, TestSize.Level1)
55 {
56     std::shared_ptr<TaskHandlerWrap> runner;
57     std::weak_ptr<AbilityManagerService> server;
58     std::shared_ptr<UserEvent> eventData = std::make_shared<UserEvent>();
59     auto event = EventWrap(UserEventHandler::EVENT_SYSTEM_USER_START, eventData);
60     auto handler = std::make_shared<AbilityEventHandler>(runner, server);
61     SetParameter("libc.hook_mode", "startup:");
62     handler->ProcessEvent(event);
63     SetParameter("libc.hook_mode", "test_parameter");
64     handler->ProcessEvent(event);
65     auto event2 = EventWrap(AbilityManagerService::LOAD_TIMEOUT_MSG, event.GetParam());
66     std::string str = std::to_string(event.GetEventId());
67     handler->ProcessEvent(event2);
68     event2 = EventWrap(AbilityManagerService::ACTIVE_TIMEOUT_MSG, event.GetParam());
69     handler->ProcessEvent(event2);
70     event2 = EventWrap(AbilityManagerService::INACTIVE_TIMEOUT_MSG, event.GetParam());
71     handler->ProcessEvent(event2);
72     event2 = EventWrap(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, event.GetParam());
73     handler->ProcessEvent(event2);
74     event2 = EventWrap(AbilityManagerService::BACKGROUND_TIMEOUT_MSG, event.GetParam());
75     handler->ProcessEvent(event2);
76     EXPECT_TRUE(handler != nullptr);
77 }  // namespace AppExecFwk
78 
79 /*
80  * Feature: Ability Event Handler
81  * Function: EventWrap
82  * SubFunction: NA
83  * FunctionPoints: EventWrap
84  * EnvConditions: NA
85  * CaseDescription: Verify ProcessEvent
86  */
87 HWTEST_F(AbilityEventHandlerTest, event_wrap_001, TestSize.Level1)
88 {
89     auto event = EventWrap(10);
90     EXPECT_TRUE(event.GetEventId() == 10);
91     EXPECT_TRUE(event.GetParam() == 0);
92 }  // namespace AppExecFwk
93 
94 /*
95  * Feature: Ability Event Handler
96  * Function: EventWrap
97  * SubFunction: NA
98  * FunctionPoints: EventWrap
99  * EnvConditions: NA
100  * CaseDescription: Verify ProcessEvent
101  */
102 HWTEST_F(AbilityEventHandlerTest, event_wrap_002, TestSize.Level1)
103 {
104     auto event = EventWrap(10, 101);
105     EXPECT_TRUE(event.GetEventId() == 10);
106     EXPECT_TRUE(event.GetParam() == 101);
107     EXPECT_FALSE(event.IsExtension());
108 }  // namespace AppExecFwk
109 
110 /*
111  * Feature: Ability Event Handler
112  * Function: EventWrap
113  * SubFunction: NA
114  * FunctionPoints: EventWrap
115  * EnvConditions: NA
116  * CaseDescription: Verify ProcessEvent
117  */
118 HWTEST_F(AbilityEventHandlerTest, event_wrap_003, TestSize.Level1)
119 {
120     auto event = EventWrap(10, 101, true);
121     EXPECT_TRUE(event.GetEventId() == 10);
122     EXPECT_TRUE(event.GetParam() == 101);
123     EXPECT_TRUE(event.IsExtension());
124     EXPECT_TRUE(event.GetEventString() == "10_101");
125 }  // namespace AppExecFwk
126 
127 /*
128  * Feature: Ability Event Handler
129  * Function: EventWrap
130  * SubFunction: NA
131  * FunctionPoints: EventWrap
132  * EnvConditions: NA
133  * CaseDescription: Verify ProcessEvent
134  */
135 HWTEST_F(AbilityEventHandlerTest, event_wrap_004, TestSize.Level1)
136 {
137     auto event = EventWrap(10, "connectTimeout_101");
138     EXPECT_TRUE(event.GetEventId() == 10);
139     EXPECT_TRUE(event.GetEventString() == "10_connectTimeout_101");
140 }  // namespace AppExecFwk
141 
142 /*
143  * Feature: Ability Event Handler
144  * Function: EventWrap
145  * SubFunction: NA
146  * FunctionPoints: EventWrap
147  * EnvConditions: NA
148  * CaseDescription: Verify ProcessEvent
149  */
150 HWTEST_F(AbilityEventHandlerTest, event_wrap_005, TestSize.Level1)
151 {
152     auto event = EventWrap(10, 101, true, "connectTimeout_101");
153     EXPECT_TRUE(event.GetEventId() == 10);
154     EXPECT_TRUE(event.GetParam() == 101);
155     EXPECT_TRUE(event.IsExtension());
156     EXPECT_TRUE(event.GetEventString() == "10_connectTimeout_101");
157 }  // namespace AppExecFwk
158 
159 /*
160  * Feature: Ability Event Handler
161  * Function: EventWrap
162  * SubFunction: NA
163  * FunctionPoints: EventWrap
164  * EnvConditions: NA
165  * CaseDescription: Verify ProcessEvent
166  */
167 HWTEST_F(AbilityEventHandlerTest, event_wrap_006, TestSize.Level1)
168 {
169     auto event = EventWrap(10, "connectTimeout_101");
170     event.SetTimeout(10000);
171     EXPECT_TRUE(event.GetEventId() == 10);
172     EXPECT_TRUE(event.GetEventString() == "10_connectTimeout_101");
173     EXPECT_TRUE(event.GetTimeout() == 10000);
174 }  // namespace AppExecFwk
175 
176 /*
177  * Feature: Ability Event Handler
178  * Function: EventWrap
179  * SubFunction: NA
180  * FunctionPoints: EventWrap
181  * EnvConditions: NA
182  * CaseDescription: Verify ProcessEvent
183  */
184 HWTEST_F(AbilityEventHandlerTest, event_wrap_007, TestSize.Level1)
185 {
186     auto event = EventWrap(10, "connectTimeout_101");
187     event.SetCreateTime(6);
188     EXPECT_TRUE(event.GetEventId() == 10);
189     EXPECT_TRUE(event.GetEventString() == "10_connectTimeout_101");
190     EXPECT_TRUE(event.GetCreateTime() == 6);
191 }
192 }  // namespace AppExecFwk
193 }  // namespace OHOS