1 /*
2 * Copyright (c) 2021 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 } // namespace AppExecFwk
77 } // namespace OHOS
78 }