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 #include <iostream>
18
19 #define private public
20 #define protected public
21 #include "system_event_observer.h"
22 #undef private
23 #undef protected
24 #include "ans_inner_errors.h"
25 #include "common_event_support.h"
26
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace Notification {
30 class SystemEventObserverTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp() override;
35 void TearDown() override;
36
37 std::shared_ptr<SystemEventObserver> stub_;
38 };
39
SetUpTestCase()40 void SystemEventObserverTest::SetUpTestCase()
41 {
42 }
43
TearDownTestCase()44 void SystemEventObserverTest::TearDownTestCase()
45 {
46 }
47
SetUp()48 void SystemEventObserverTest::SetUp()
49 {
50 ISystemEvent iSystemEvent;
51 stub_ = std::make_shared<SystemEventObserver>(iSystemEvent);
52 }
53
TearDown()54 void SystemEventObserverTest::TearDown()
55 {
56 }
57
58 /**
59 * @tc.number : OnReceiveEvent_001
60 * @tc.name :
61 * @tc.desc : Test OnReceiveEvent function, return is void.
62 */
63 HWTEST_F(SystemEventObserverTest, OnReceiveEvent_001, Function | SmallTest | Level1)
64 {
65 EventFwk::Want want;
66 EventFwk::CommonEventData data;
67 data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED));
68
69 stub_->OnReceiveEvent(data);
70 }
71
72 /**
73 * @tc.number : OnReceiveEvent_002
74 * @tc.name :
75 * @tc.desc : Test OnReceiveEvent function, return is void.
76 */
77 HWTEST_F(SystemEventObserverTest, OnReceiveEvent_002, Function | SmallTest | Level1)
78 {
79 EventFwk::Want want;
80 EventFwk::CommonEventData data;
81 data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED));
82 stub_->OnReceiveEvent(data);
83 }
84
85 /**
86 * @tc.number : OnReceiveEvent_003
87 * @tc.name :
88 * @tc.desc : Test OnReceiveEvent function, return is void.
89 */
90 HWTEST_F(SystemEventObserverTest, OnReceiveEvent_003, Function | SmallTest | Level1)
91 {
92 EventFwk::Want want;
93 EventFwk::CommonEventData data;
94 data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED));
95 stub_->OnReceiveEvent(data);
96 }
97
98 /**
99 * @tc.number : OnReceiveEvent_004
100 * @tc.name :
101 * @tc.desc : Test OnReceiveEvent function, return is void.
102 */
103 HWTEST_F(SystemEventObserverTest, OnReceiveEvent_004, Function | SmallTest | Level1)
104 {
105 EventFwk::Want want;
106 EventFwk::CommonEventData data;
107 data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED));
108 stub_->OnReceiveEvent(data);
109 }
110
111 /**
112 * @tc.number : GetBundleOption_001
113 * @tc.name :
114 * @tc.desc : Test GetBundleOption function.
115 * @tc.require : issueI5S4VP
116 */
117 HWTEST_F(SystemEventObserverTest, GetBundleOption_001, Function | SmallTest | Level1)
118 {
119 EventFwk::Want want;
120 sptr<NotificationBundleOption> systemEventObserver = stub_->GetBundleOption(want);
121 EXPECT_NE(systemEventObserver, nullptr);
122 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(std::string(), -1);
123 bundleOption ->SetBundleName("BundleName");
124 bundleOption ->SetUid(2);
125 stub_->GetBundleOption(want);
126 }
127 } // namespace Notification
128 } // namespace OHOS