1 /*
2  * Copyright (c) 2023 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_bundle_event_callback.h"
20 #include "ability_event_util.h"
21 #undef private
22 #undef protected
23 
24 using namespace testing::ext;
25 using namespace testing;
26 using namespace OHOS::AppExecFwk;
27 using namespace OHOS::AbilityRuntime;
28 namespace OHOS {
29 namespace AAFwk {
30 class AbilityBundleEventCallbackTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36 };
SetUpTestCase(void)37 void AbilityBundleEventCallbackTest::SetUpTestCase(void) {}
TearDownTestCase(void)38 void AbilityBundleEventCallbackTest::TearDownTestCase(void) {}
TearDown()39 void AbilityBundleEventCallbackTest::TearDown() {}
SetUp()40 void AbilityBundleEventCallbackTest::SetUp() {}
41 
42 /**
43  * @tc.name: AbilityBundleEventCallbackTest_OnReceiveEvent_0100
44  * @tc.desc: Test the state of OnReceiveEvent
45  * @tc.type: FUNC
46  */
47 HWTEST_F(AbilityBundleEventCallbackTest, OnReceiveEvent_0100, TestSize.Level1)
48 {
49     sptr<AbilityBundleEventCallback> abilityBundleEventCallback_ =
50         new (std::nothrow) AbilityBundleEventCallback(nullptr, nullptr);
51     EXPECT_NE(abilityBundleEventCallback_, nullptr);
52     EventFwk::CommonEventData eventData;
53     abilityBundleEventCallback_->OnReceiveEvent(eventData);
54     EXPECT_EQ(abilityBundleEventCallback_->taskHandler_, nullptr);
55 }
56 
57 /**
58  * @tc.name: AbilityBundleEventCallbackTest_OnReceiveEvent_0200
59  * @tc.desc: Test the state of OnReceiveEvent
60  * @tc.type: FUNC
61  */
62 HWTEST_F(AbilityBundleEventCallbackTest, OnReceiveEvent_0200, TestSize.Level1)
63 {
64     sptr<AbilityBundleEventCallback> abilityBundleEventCallback_ =
65         new (std::nothrow) AbilityBundleEventCallback(nullptr, nullptr);
66     EXPECT_NE(abilityBundleEventCallback_, nullptr);
67     abilityBundleEventCallback_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("AbilityBundleEventCallbackTest");
68     EventFwk::CommonEventData eventData;
69     abilityBundleEventCallback_->OnReceiveEvent(eventData);
70     EXPECT_NE(abilityBundleEventCallback_->taskHandler_, nullptr);
71 }
72 } // namespace AAFwk
73 } // namespace OHOS
74