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 "dms_hisysevent_report_test.h"
17
18 #include "dfx/dms_hisysevent_report.h"
19 #include "test_log.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace DistributedSchedule {
26 namespace {
27 const std::string bundleName = "ohos.hisysevent.test";
28 const std::string abilityName = "testAbility";
29 const std::string TAG = "DmsHiSysEventReportTest";
30 const int32_t eventResult = 0;
31 const int32_t callingAppUid = 0;
32 }
33
SetUpTestCase()34 void DmsHiSysEventReportTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void DmsHiSysEventReportTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void DmsHiSysEventReportTest::SetUp()
43 {
44 }
45
TearDown()46 void DmsHiSysEventReportTest::TearDown()
47 {
48 }
49
50 /**
51 * @tc.name: testReportBehaviorEvent_001
52 * @tc.desc: test ReportBehaviorEvent when HiSysEvent::Write success
53 * @tc.type: FUNC
54 * @tc.require: I621C1
55 */
56 HWTEST_F(DmsHiSysEventReportTest, testReportBehaviorEvent_001, TestSize.Level3)
57 {
58 DTEST_LOG << "DmsHiSysEventReportTest testReportBehaviorEvent_001 begin" << std::endl;
59 BehaviorEventParam param;
60 /**
61 * @tc.steps: step1. test ReportBehaviorEvent with invalid eventName
62 */
63 int32_t result = DmsHiSysEventReport::ReportBehaviorEvent(param);
64 EXPECT_NE(0, result);
65 /**
66 * @tc.steps: step2. test ReportBehaviorEvent
67 */
68 param = { EventCallingType::LOCAL, BehaviorEvent::START_REMOTE_ABILITY, eventResult,
69 bundleName, abilityName, callingAppUid };
70 result = DmsHiSysEventReport::ReportBehaviorEvent(param);
71 EXPECT_EQ(0, result);
72 DTEST_LOG << "DmsHiSysEventReportTest testReportBehaviorEvent_001 end" << std::endl;
73 }
74
75 /**
76 * @tc.name: testReportFaultEvent_001
77 * @tc.desc: test ReportFaultEvent when HiSysEvent::Write success
78 * @tc.type: FUNC
79 * @tc.require: I621C1
80 */
81 HWTEST_F(DmsHiSysEventReportTest, testReportFaultEvent_001, TestSize.Level3)
82 {
83 DTEST_LOG << "DmsHiSysEventReportTest testReportFaultEvent_001 begin" << std::endl;
84 std::string eventName;
85 std::string errorType;
86 /**
87 * @tc.steps: step1. test ReportFaultEvent with invalid error type
88 */
89 int32_t result = DmsHiSysEventReport::ReportFaultEvent("", "");
90 EXPECT_NE(0, result);
91 /**
92 * @tc.steps: step2. test ReportFaultEvent
93 */
94 result = DmsHiSysEventReport::ReportFaultEvent(FaultEvent::START_REMOTE_ABILITY,
95 EventErrorType::GET_ABILITY_MGR_FAILED);
96 EXPECT_EQ(0, result);
97 DTEST_LOG << "DmsHiSysEventReportTest testReportFaultEvent_001 end" << std::endl;
98 }
99 } // DistributedSchedule
100 } // namespace OHOS