• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <numeric>
18 #include "event_report.h"
19 
20 namespace OHOS {
21 namespace EventFwk {
22 using namespace testing::ext;
23 
24 namespace {
25 const std::string TEST_EVENT_NAME = "usual.event.TEST_HISYSEVENT";
26 const std::string TEST_SUBSCRIBER_BUNDLE_NAME = "subscriber";
27 const std::string TEST_PUBLISHER_BUNDLE_NAME = "publisher";
28 constexpr int32_t TEST_USER_ID = 1000;
29 constexpr int32_t TEST_SUBSCRIBER_NUM = 256;
30 } // namespace
31 
32 class CommonEventHisyseventTest : public testing::Test {
33 public:
CommonEventHisyseventTest()34     CommonEventHisyseventTest()
35     {}
~CommonEventHisyseventTest()36     ~CommonEventHisyseventTest()
37     {}
38 
39     static void SetUpTestCase(void);
40     static void TearDownTestCase(void);
41     void SetUp();
42     void TearDown();
43 };
44 
SetUpTestCase(void)45 void CommonEventHisyseventTest::SetUpTestCase(void)
46 {}
47 
TearDownTestCase(void)48 void CommonEventHisyseventTest::TearDownTestCase(void)
49 {}
50 
SetUp(void)51 void CommonEventHisyseventTest::SetUp(void)
52 {}
53 
TearDown(void)54 void CommonEventHisyseventTest::TearDown(void)
55 {}
56 
57 /**
58  * @tc.name: SendOrderedEventProcTimeoutSysEvent_0100
59  * @tc.desc: Send "ORDERED_EVENT_PROC_TIMEOUT" hisysevent.
60  * @tc.type: FUNC
61  * @tc.require: I582Y4
62  */
HWTEST_F(CommonEventHisyseventTest,SendOrderedEventProcTimeoutSysEvent_0100,Level1)63 HWTEST_F(CommonEventHisyseventTest, SendOrderedEventProcTimeoutSysEvent_0100, Level1)
64 {
65     GTEST_LOG_(INFO) << "SendOrderedEventProcTimeoutSysEvent_0100 start";
66 
67     EventInfo eventInfo;
68     eventInfo.userId = TEST_USER_ID;
69     eventInfo.subscriberName = TEST_SUBSCRIBER_BUNDLE_NAME;
70     eventInfo.pid = getpid();
71     eventInfo.uid = getuid();
72     eventInfo.eventName = TEST_EVENT_NAME;
73     EventReport::SendHiSysEvent(ORDERED_EVENT_PROC_TIMEOUT, eventInfo);
74 
75     GTEST_LOG_(INFO) << "SendOrderedEventProcTimeoutSysEvent_0100 end";
76 }
77 
78 /**
79  * @tc.name: SendStaticEventProcErrorSysEvent_0100
80  * @tc.desc: Send "STATIC_EVENT_PROC_ERROR" hisysevent.
81  * @tc.type: FUNC
82  * @tc.require: I582Y4
83  */
HWTEST_F(CommonEventHisyseventTest,SendStaticEventProcErrorSysEvent_0100,Level1)84 HWTEST_F(CommonEventHisyseventTest, SendStaticEventProcErrorSysEvent_0100, Level1)
85 {
86     GTEST_LOG_(INFO) << "SendStaticEventProcErrorSysEvent_0100 start";
87 
88     EventInfo eventInfo;
89     eventInfo.userId = TEST_USER_ID;
90     eventInfo.publisherName = TEST_PUBLISHER_BUNDLE_NAME;
91     eventInfo.subscriberName = TEST_SUBSCRIBER_BUNDLE_NAME;
92     eventInfo.eventName = TEST_EVENT_NAME;
93     EventReport::SendHiSysEvent(STATIC_EVENT_PROC_ERROR, eventInfo);
94 
95     GTEST_LOG_(INFO) << "SendStaticEventProcErrorSysEvent_0100 end";
96 }
97 
98 /**
99  * @tc.name: SendSubscriberExceedMaximumSysEvent_0100
100  * @tc.desc: Send "SUBSCRIBER_EXCEED_MAXIMUM" hisysevent.
101  * @tc.type: FUNC
102  * @tc.require: I582Y4
103  */
HWTEST_F(CommonEventHisyseventTest,SendSubscriberExceedMaximumSysEvent_0100,Level1)104 HWTEST_F(CommonEventHisyseventTest, SendSubscriberExceedMaximumSysEvent_0100, Level1)
105 {
106     GTEST_LOG_(INFO) << "SendSubscriberExceedMaximumSysEvent_0100 start";
107 
108     EventInfo eventInfo;
109     eventInfo.userId = TEST_USER_ID;
110     eventInfo.eventName = TEST_EVENT_NAME;
111     eventInfo.subscriberNum = TEST_SUBSCRIBER_NUM;
112     EventReport::SendHiSysEvent(SUBSCRIBER_EXCEED_MAXIMUM, eventInfo);
113 
114     GTEST_LOG_(INFO) << "SendSubscriberExceedMaximumSysEvent_0100 end";
115 }
116 
117 /**
118  * @tc.name: SendPublishEventErrorSysEvent_0100
119  * @tc.desc: Send "PUBLISH_EVENT_ERROR" hisysevent.
120  * @tc.type: FUNC
121  * @tc.require: I582Y4
122  */
HWTEST_F(CommonEventHisyseventTest,SendPublishEventErrorSysEvent_0100,Level1)123 HWTEST_F(CommonEventHisyseventTest, SendPublishEventErrorSysEvent_0100, Level1)
124 {
125     GTEST_LOG_(INFO) << "SendSubscriberExceedMaximumSysEvent_0100 start";
126 
127     EventInfo eventInfo;
128     eventInfo.userId = TEST_USER_ID;
129     eventInfo.publisherName = TEST_SUBSCRIBER_BUNDLE_NAME;
130     eventInfo.pid = getpid();
131     eventInfo.uid = getuid();
132     eventInfo.eventName = TEST_EVENT_NAME;
133     EventReport::SendHiSysEvent(PUBLISH_ERROR, eventInfo);
134 
135     GTEST_LOG_(INFO) << "SendPublishEventErrorSysEvent_0100 end";
136 }
137 
138 /**
139  * @tc.name: SendSubscribeSysEvent_0100
140  * @tc.desc: Send "SUBSCRIBE_EVENT" hisysevent.
141  * @tc.type: FUNC
142  * @tc.require: I582Y4
143  */
HWTEST_F(CommonEventHisyseventTest,SendSubscribeSysEvent_0100,Level1)144 HWTEST_F(CommonEventHisyseventTest, SendSubscribeSysEvent_0100, Level1)
145 {
146     GTEST_LOG_(INFO) << "SendSubscribeSysEvent_0100 start";
147 
148     EventInfo eventInfo;
149     eventInfo.userId = TEST_USER_ID;
150     eventInfo.subscriberName = TEST_SUBSCRIBER_BUNDLE_NAME;
151     eventInfo.pid = getpid();
152     eventInfo.uid = getuid();
153     std::vector<std::string> events = {"event1", "event2", "event3"};
154     eventInfo.eventName = std::accumulate(events.begin(), events.end(), eventInfo.eventName,
155         [events](std::string eventName, const std::string &str) {
156             return (str == events.front()) ? (eventName + str) : (eventName + "," + str);
157         });
158     EventReport::SendHiSysEvent(SUBSCRIBE, eventInfo);
159 
160     std::vector<std::string> anotherEvent = {"event"};
161     eventInfo.eventName = std::accumulate(anotherEvent.begin(), anotherEvent.end(), std::string(""),
162         [anotherEvent](std::string eventName, const std::string &str) {
163             return (str == anotherEvent.front()) ? (eventName + str) : (eventName + "," + str);
164         });
165     EventReport::SendHiSysEvent(SUBSCRIBE, eventInfo);
166 
167     GTEST_LOG_(INFO) << "SendSubscribeSysEvent_0100 end";
168 }
169 
170 /**
171  * @tc.name: SendUnSubscribeSysEvent_0100
172  * @tc.desc: Send "UNSUBSCRIBE_EVENT" hisysevent.
173  * @tc.type: FUNC
174  * @tc.require: I582Y4
175  */
HWTEST_F(CommonEventHisyseventTest,SendUnSubscribeSysEvent_0100,Level1)176 HWTEST_F(CommonEventHisyseventTest, SendUnSubscribeSysEvent_0100, Level1)
177 {
178     GTEST_LOG_(INFO) << "SendUnSubscribeSysEvent_0100 start";
179 
180     EventInfo eventInfo;
181     eventInfo.userId = TEST_USER_ID;
182     eventInfo.subscriberName = TEST_SUBSCRIBER_BUNDLE_NAME;
183     eventInfo.pid = getpid();
184     eventInfo.uid = getuid();
185     std::vector<std::string> events = {"event1_1", "event1_2", "event1_3"};
186     eventInfo.eventName = std::accumulate(events.begin(), events.end(), eventInfo.eventName,
187         [events](std::string eventName, const std::string &str) {
188             return (str == events.front()) ? (eventName + str) : (eventName + "," + str);
189         });
190     EventReport::SendHiSysEvent(UNSUBSCRIBE, eventInfo);
191 
192     eventInfo.eventName = "";
193     std::vector<std::string> anotherEvent = {"event"};
194     eventInfo.eventName = std::accumulate(anotherEvent.begin(), anotherEvent.end(), eventInfo.eventName,
195         [anotherEvent](std::string eventName, const std::string &str) {
196             return (str == anotherEvent.front()) ? (eventName + str) : (eventName + "," + str);
197         });
198     EventReport::SendHiSysEvent(UNSUBSCRIBE, eventInfo);
199 
200     GTEST_LOG_(INFO) << "SendUnSubscribeSysEvent_0100 end";
201 }
202 
203 /**
204  * @tc.name: SendPublishSysEvent_0100
205  * @tc.desc: Send "PUBLISH_EVENT" hisysevent.
206  * @tc.type: FUNC
207  * @tc.require: I582Y4
208  */
HWTEST_F(CommonEventHisyseventTest,SendPublishSysEvent_0100,Level1)209 HWTEST_F(CommonEventHisyseventTest, SendPublishSysEvent_0100, Level1)
210 {
211     GTEST_LOG_(INFO) << "SendPublishSysEvent_0100 start";
212 
213     EventInfo eventInfo;
214     eventInfo.userId = TEST_USER_ID;
215     eventInfo.publisherName = TEST_PUBLISHER_BUNDLE_NAME;
216     eventInfo.pid = getpid();
217     eventInfo.uid = getuid();
218     eventInfo.eventName = TEST_EVENT_NAME;
219     EventReport::SendHiSysEvent(PUBLISH, eventInfo);
220 
221     GTEST_LOG_(INFO) << "SendPublishSysEvent_0100 end";
222 }
223 }  // namespace EventFwk
224 }  // namespace OHOS