• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
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/hwext/gtest-ext.h>
17 #include <gtest/hwext/gtest-tag.h>
18 #include "hiappevent_util.h"
19 
20 #include <thread>
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 class HiAppEventUtilTest : public ::testing::Test {
27 public:
SetUpTestCase()28     static void SetUpTestCase()
29     {
30         ApiRecordReporter::InitProcessor();
31     }
32 };
33 
34 /**
35  * @tc.name: SingleRecordReporterTest
36  * @tc.desc: test SingleRecordReporter.
37  * @tc.type: FUNC
38  */
39 HWTEST_F(HiAppEventUtilTest, SingleRecordReporterTest, TestSize.Level0)
40 {
41     bool success = false;
42     {
43         {
44             constexpr auto testApiName = "SingleRecordReporterTest";
45             ApiInvokeRecorder successRecorder(testApiName);
46             ApiInvokeRecorder failedRecorder2(testApiName);
47             failedRecorder2.SetErrorCode(200);
48         }
49         success = true;
50     }
51     ASSERT_TRUE(success);
52 }
53 
54 /**
55  * @tc.name: MultipleRecordReporterTest
56  * @tc.desc: test MultipleRecordReporter.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(HiAppEventUtilTest, MultipleRecordReporterTest, TestSize.Level0)
60 {
61     MultipleRecordReporter multipleRecordReporter(1, 2);
62     std::this_thread::sleep_for(std::chrono::seconds(1));
63     bool success = false;
64     {
65         {
66             constexpr auto testApiName = "MultipleRecordReporterTest";
67             ApiInvokeRecorder successRecorder(testApiName, multipleRecordReporter);
68             ApiInvokeRecorder failedRecorder2(testApiName, multipleRecordReporter);
69             ApiInvokeRecorder failedRecorder3(testApiName, multipleRecordReporter);
70             failedRecorder3.SetErrorCode(200);
71         }
72         success = true;
73     }
74     ASSERT_TRUE(success);
75 }
76 }
77 }