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 <cstdlib>
17#include <gtest/gtest.h>
18#include <string>
19#include <thread>
20#include <unistd.h>
21#include <chrono>
22
23#include "hicollie.h"
24
25using namespace testing::ext;
26
27namespace {
28class HiCollieTest : public ::testing::Test {
29public:
30    void SetUp() override {}
31    void TearDown() override {}
32};
33
34void TaskTest()
35{
36    printf("TaskTest");
37}
38
39void InitBeginFunc(const char* eventName)
40{
41    std::string str(eventName);
42    printf("InitBeginFunc eventName: %s\n", str.c_str());
43}
44
45void InitEndFunc(const char* eventName)
46{
47    std::string str(eventName);
48    printf("InitBeginFunc eventName: %s\n", str.c_str());
49}
50
51/**
52 * @tc.name: OH_HiCollie_Init_StuckDetection
53 * @tc.desc: test OH_HiCollie_Init_StuckDetection
54 * @tc.type: FUNC
55 */
56HWTEST_F(HiCollieTest, Test_OH_HiCollie_Init_StuckDetection_1, TestSize.Level1)
57{
58    int result = OH_HiCollie_Init_StuckDetection(&TaskTest);
59    EXPECT_EQ(result, HICOLLIE_SUCCESS);
60}
61
62/**
63 * @tc.name: OH_HiCollie_Init_StuckDetection
64 * @tc.desc: test OH_HiCollie_Init_StuckDetection
65 * @tc.type: FUNC
66 */
67HWTEST_F(HiCollieTest, Test_OH_HiCollie_Init_StuckDetection_2, TestSize.Level1)
68{
69    int result = OH_HiCollie_Init_StuckDetection(nullptr);
70    EXPECT_EQ(result, HICOLLIE_SUCCESS);
71}
72
73/**
74 * @tc.name: OH_HiCollie_Init_JankDetection
75 * @tc.desc: test OH_HiCollie_Init_JankDetection
76 * @tc.type: FUNC
77 */
78HWTEST_F(HiCollieTest, Test_OH_HiCollie_Init_JankDetection_1, TestSize.Level1)
79{
80    OH_HiCollie_BeginFunc begin_ = InitBeginFunc;
81    OH_HiCollie_EndFunc end_ = InitEndFunc;
82    HiCollie_DetectionParam param {
83        .sampleStackTriggerTime = 150,
84        .reserved = 0,
85    };
86    int result = OH_HiCollie_Init_JankDetection(&begin_, &end_, param);
87    EXPECT_EQ(result, HICOLLIE_SUCCESS);
88    result = OH_HiCollie_Init_JankDetection(nullptr, nullptr, param);
89    EXPECT_EQ(result, HICOLLIE_SUCCESS);
90}
91
92/**
93 * @tc.name: OH_HiCollie_Report
94 * @tc.desc: test OH_HiCollie_Report
95 * @tc.type: FUNC
96 */
97HWTEST_F(HiCollieTest, Test_OH_HiCollie_Report_1, TestSize.Level1)
98{
99    bool isSixSecond = false;
100    int result = OH_HiCollie_Report(&isSixSecond);
101    printf("OH_HiCollie_Report result: %d\n", result);
102    EXPECT_TRUE(isSixSecond);
103    result = OH_HiCollie_Report(&isSixSecond);
104    printf("OH_HiCollie_Report result: %d\n", result);
105    EXPECT_FALSE(isSixSecond);
106}
107} // namespace
108