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
18 #include "intention_event/dfx/include/dfx_hisysevent.h"
19 #include "window_manager_hilog.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26
27 class DfxHisyseventTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void DfxHisyseventTest::SetUpTestCase()
36 {
37 }
38
TearDownTestCase()39 void DfxHisyseventTest::TearDownTestCase()
40 {
41 }
42
SetUp()43 void DfxHisyseventTest::SetUp()
44 {
45 }
46
TearDown()47 void DfxHisyseventTest::TearDown()
48 {
49 }
50
51 namespace {
52 /**
53 * @tc.name: ApplicationBlockInput
54 * @tc.desc: ApplicationBlockInput test Succ
55 * @tc.type: FUNC
56 * @tc.require: #I6JLSI
57 */
58
TEST_F(DfxHisyseventTest,ApplicationBlockInput_Success)59 TEST_F(DfxHisyseventTest, ApplicationBlockInput_Success)
60 {
61 DfxHisysevent dfxHisysevent;
62 int32_t eventId = 1;
63 int32_t pid = 2;
64 std::string bundleName = "TestBundleName";
65 int32_t persistentId = 4;
66 int result = 0;
67 std::function<void()> func = [&]() {
68 dfxHisysevent.ApplicationBlockInput(eventId, pid, bundleName, persistentId);
69 result = 1;
70 };
71 func();
72 ASSERT_EQ(result, 1);
73 }
74
75 /**
76 * @tc.name: ApplicationBlockInput
77 * @tc.desc: ApplicationBlockInput test Fail1
78 * @tc.type: FUNC
79 * @tc.require: #I6JLSI
80 */
81
TEST_F(DfxHisyseventTest,ApplicationBlockInput_Fail1)82 TEST_F(DfxHisyseventTest, ApplicationBlockInput_Fail1)
83 {
84 DfxHisysevent dfxHisysevent;
85 int32_t eventId = 1;
86 int32_t pid = -5;
87 std::string bundleName = "TestBundleName";
88 int32_t persistentId = 2;
89 int result = 0;
90 std::function<void()> func = [&]() {
91 dfxHisysevent.ApplicationBlockInput(eventId, pid, bundleName, persistentId);
92 result = 1;
93 };
94 func();
95 ASSERT_EQ(result, 1);
96 }
97
98 /**
99 * @tc.name: ApplicationBlockInput
100 * @tc.desc: ApplicationBlockInput test Fail2
101 * @tc.type: FUNC
102 * @tc.require: #I6JLSI
103 */
104
TEST_F(DfxHisyseventTest,ApplicationBlockInput_Fail2)105 TEST_F(DfxHisyseventTest, ApplicationBlockInput_Fail2)
106 {
107 DfxHisysevent dfxHisysevent;
108 int32_t eventId = 1;
109 int32_t pid = 5;
110 std::string bundleName = "TestBundleName";
111 int32_t persistentId = -2;
112 int result = 0;
113 std::function<void()> func = [&]() {
114 dfxHisysevent.ApplicationBlockInput(eventId, pid, bundleName, persistentId);
115 result = 1;
116 };
117 func();
118 ASSERT_EQ(result, 1);
119 }
120
121 /**
122 * @tc.name: ApplicationBlockInput
123 * @tc.desc: ApplicationBlockInput test Fail3
124 * @tc.type: FUNC
125 * @tc.require: #I6JLSI
126 */
127
TEST_F(DfxHisyseventTest,ApplicationBlockInput_Fail3)128 TEST_F(DfxHisyseventTest, ApplicationBlockInput_Fail3)
129 {
130 DfxHisysevent dfxHisysevent;
131 int32_t eventId = 1;
132 int32_t pid = -5;
133 std::string bundleName = "TestBundleName";
134 int32_t persistentId = -2;
135 int result = 0;
136 std::function<void()> func = [&]() {
137 dfxHisysevent.ApplicationBlockInput(eventId, pid, bundleName, persistentId);
138 result = 1;
139 };
140 func();
141 ASSERT_EQ(result, 1);
142 }
143
144 } // namespace
145 } // namespace OHOS
146 } // namespace Rosen
147