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 #define private public
18 #define protected public
19 #include "ability_manager_event_subscriber.h"
20 #undef private
21 #undef protected
22 #include "common_event_support.h"
23 #include "hilog_tag_wrapper.h"
24
25 using namespace testing::ext;
26 using namespace testing;
27 namespace OHOS {
28 namespace AbilityRuntime {
29 class AbilityManagerEventSubscriberTest : public testing::Test {
30 public:
31 static void SetUpTestCase(void);
32 static void TearDownTestCase(void);
33 void SetUp();
34 void TearDown();
35 };
SetUpTestCase(void)36 void AbilityManagerEventSubscriberTest::SetUpTestCase(void) {}
TearDownTestCase(void)37 void AbilityManagerEventSubscriberTest::TearDownTestCase(void) {}
TearDown()38 void AbilityManagerEventSubscriberTest::TearDown() {}
SetUp()39 void AbilityManagerEventSubscriberTest::SetUp() {}
40
41 /**
42 * @tc.name: AbilityManagerEventSubscriberTest_OnReceiveEvent_0001
43 * @tc.desc: Test the state of OnReceiveEvent
44 * @tc.type: FUNC
45 */
46 HWTEST_F(AbilityManagerEventSubscriberTest, OnReceiveEvent_0001, TestSize.Level1)
47 {
48 EventFwk::CommonEventSubscribeInfo subscribeInfo;
__anonb1cb88020102() 49 std::function<void()> callback = []() {};
__anonb1cb88020202() 50 std::function<void()> userScreenUnlockCallback = []() {};
51 EXPECT_NE(callback, nullptr);
52 EXPECT_NE(userScreenUnlockCallback, nullptr);
53 auto subscriber = std::make_shared<AbilityManagerEventSubscriber>(
54 subscribeInfo, callback, userScreenUnlockCallback);
55 EventFwk::CommonEventData data;
56 data.want_.operation_.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED;
57 subscriber->OnReceiveEvent(data);
58 EXPECT_NE(subscriber->screenUnlockCallback_, nullptr);
59 data.want_.operation_.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED;
60 subscriber->OnReceiveEvent(data);
61 EXPECT_NE(subscriber->userScreenUnlockCallback_, nullptr);
62 }
63 } // namespace AAFwk
64 } // namespace OHOS
65