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 #include "hilog_wrapper.h"
22
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace AAFwk {
26
27 class AbilityEventHandlerTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp();
32 void TearDown();
33 };
34
SetUpTestCase()35 void AbilityEventHandlerTest::SetUpTestCase()
36 {}
37
TearDownTestCase()38 void AbilityEventHandlerTest::TearDownTestCase()
39 {}
40
SetUp()41 void AbilityEventHandlerTest::SetUp()
42 {}
43
TearDown()44 void AbilityEventHandlerTest::TearDown()
45 {}
46
47 /*
48 * Feature: Ability Event Handler
49 * Function: ProcessEvent
50 * SubFunction: NA
51 * FunctionPoints: Ability Event Handler ProcessEvent
52 * EnvConditions: NA
53 * CaseDescription: Verify ProcessEvent
54 */
55 HWTEST_F(AbilityEventHandlerTest, ability_event_handler_001, TestSize.Level1)
56 {
57 std::shared_ptr<AppExecFwk::EventRunner> runner;
58 std::weak_ptr<AbilityManagerService> server;
59 std::shared_ptr<UserEvent> eventData = std::make_shared<UserEvent>();
60 auto event = AppExecFwk::InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_START, eventData);
61 auto handler = std::make_shared<AbilityEventHandler>(runner, server);
62 SetParameter("libc.hook_mode", "startup:");
63 handler->ProcessEvent(event);
64 SetParameter("libc.hook_mode", "test_parameter");
65 handler->ProcessEvent(event);
66 auto event2 = event->Get(AbilityManagerService::LOAD_TIMEOUT_MSG, event->GetParam());
67 std::string str = std::to_string(event->GetInnerEventId());
68 handler->ProcessEvent(event2);
69 event2 = event->Get(AbilityManagerService::ACTIVE_TIMEOUT_MSG, event->GetParam());
70 handler->ProcessEvent(event2);
71 event2 = event->Get(AbilityManagerService::INACTIVE_TIMEOUT_MSG, event->GetParam());
72 handler->ProcessEvent(event2);
73 event2 = event->Get(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, event->GetParam());
74 handler->ProcessEvent(event2);
75 event2 = event->Get(AbilityManagerService::BACKGROUND_TIMEOUT_MSG, event->GetParam());
76 handler->ProcessEvent(event2);
77 } // namespace AppExecFwk
78 } // namespace OHOS
79 }