• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 <iostream>
19 #include <cstddef>
20 #include <cstdint>
21 #define private public
22 #include "ability_event_util.h"
23 #undef private
24 #include "hilog_tag_wrapper.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::AAFwk;
29 using namespace OHOS::AppExecFwk;
30 
31 namespace OHOS {
32 namespace AbilityRuntime {
33 class AbilityEventUtilTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase(void)41 void AbilityEventUtilTest::SetUpTestCase(void) {}
TearDownTestCase(void)42 void AbilityEventUtilTest::TearDownTestCase(void) {}
SetUp()43 void AbilityEventUtilTest::SetUp() {}
TearDown()44 void AbilityEventUtilTest::TearDown() {}
45 
46 /**
47  * @tc.name: AbilityEventUtil_SendStartAbilityError_0100
48  * @tc.desc: SendStartAbilityError
49  * @tc.type: FUNC
50  * @tc.require: NA
51  */
52 HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0100, TestSize.Level1)
53 {
54     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0100 start");
55     std::shared_ptr<AbilityEventUtil> eventUtil = std::make_shared<AbilityEventUtil>();
56     EventInfo eventInfo = {};
57     int32_t errCode = -1;
58     std::string errMsg = "test event";
59     eventUtil->SendStartAbilityErrorEvent(eventInfo, errCode, errMsg);
60     EXPECT_EQ(eventInfo.userId, -1);
61     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0100 end");
62 }
63 
64 /**
65  * @tc.name: AbilityEventUtil_SendStartAbilityError_0200
66  * @tc.desc: SendStartAbilityError
67  * @tc.type: FUNC
68  * @tc.require: NA
69  */
70 HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0200, TestSize.Level1)
71 {
72     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0200 start");
73     std::shared_ptr<AbilityEventUtil> eventUtil = std::make_shared<AbilityEventUtil>();
74     EventInfo eventInfo = {};
75     int32_t errCode = -1;
76     std::string errMsg = "test event";
77     eventUtil->SendStartAbilityErrorEvent(eventInfo, errCode, errMsg, true);
78     EXPECT_EQ(eventInfo.userId, -1);
79     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0200 end");
80 }
81 
82 /**
83  * @tc.name: AbilityEventUtil_SendStartAbilityError_0300
84  * @tc.desc: SendKillProcessWithReasonEvent
85  * @tc.type: FUNC
86  * @tc.require: NA
87  */
88 HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0300, TestSize.Level1)
89 {
90     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0300 start");
91     std::shared_ptr<AbilityEventUtil> eventUtil = std::make_shared<AbilityEventUtil>();
92     EventInfo eventInfo = {};
93     int32_t errCode = 0;
94     std::string errMsg = "test event";
95     eventUtil->SendStartAbilityErrorEvent(eventInfo, errCode, errMsg);
96     EXPECT_EQ(eventInfo.userId, -1);
97     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0300 end");
98 }
99 
100 /**
101  * @tc.name: AbilityEventUtil_SendKillProcessWithReasonEvent_0100
102  * @tc.desc: SendKillProcessWithReasonEvent
103  * @tc.type: FUNC
104  * @tc.require: NA
105  */
106 HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendKillProcessWithReasonEvent_0100, TestSize.Level1)
107 {
108     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendKillProcessWithReasonEvent_0100 start");
109     std::shared_ptr<AbilityEventUtil> eventUtil = std::make_shared<AbilityEventUtil>();
110     EventInfo eventInfo = {};
111     int32_t errCode = -1;
112     std::string errMsg = "test event";
113     eventUtil->SendKillProcessWithReasonEvent(errCode, errMsg, eventInfo);
114     EXPECT_EQ(eventInfo.userId, -1);
115     TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendKillProcessWithReasonEvent_0100 end");
116 }
117 }  // namespace AAFwk
118 }  // namespace OHOS
119