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 <hilog/log.h>
18
19 #include "jank_detector/rs_jank_detector.h"
20
21 using namespace testing::ext;
22
23 namespace OHOS::Rosen {
24 class RSJankDetectorTest : public testing::Test {
25 public:
26 static constexpr HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0, "RSJankDetectorTest" };
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp() override;
30 void TearDown() override;
31
32 static inline std::shared_ptr<RSJankDetector> jankDetector = nullptr;
33 };
34
SetUpTestCase()35 void RSJankDetectorTest::SetUpTestCase()
36 {
37 jankDetector = std::make_shared<RSJankDetector>();
38 }
39
TearDownTestCase()40 void RSJankDetectorTest::TearDownTestCase()
41 {
42 jankDetector = nullptr;
43 }
44
SetUp()45 void RSJankDetectorTest::SetUp() {}
TearDown()46 void RSJankDetectorTest::TearDown() {}
47
48 /**
49 * @tc.name: SetRefreshPeriodTest
50 * @tc.desc: Verify the SetRefreshPeriod of RSJankDetectorTest
51 * @tc.type: FUNC
52 */
53 HWTEST_F(RSJankDetectorTest, SetRefreshPeriodTest, Function | SmallTest | Level1)
54 {
55 // start SetRefreshPeriodTest test
56 uint64_t refreshPeriod = 16666667;
57 jankDetector->SetRefreshPeriod(refreshPeriod);
58 EXPECT_EQ(jankDetector->GetRefreshPeriod(), refreshPeriod);
59 }
60
61 /**
62 * @tc.name: GetRefreshPeriodTest
63 * @tc.desc: Verify the GetRefreshPeriod of RSJankDetectorTest
64 * @tc.type: FUNC
65 */
66 HWTEST_F(RSJankDetectorTest, GetRefreshPeriodTest, Function | SmallTest | Level1)
67 {
68 // start GetRefreshPeriodTest test
69 uint64_t refreshPeriod = jankDetector->GetRefreshPeriod();
70 EXPECT_EQ(16666667, refreshPeriod);
71 }
72
73 /**
74 * @tc.name: GetSysTimeNsTest
75 * @tc.desc: Verify the GetSysTimeNs of RSJankDetectorTest
76 * @tc.type: FUNC
77 */
78 HWTEST_F(RSJankDetectorTest, GetSysTimeNsTest, Function | SmallTest | Level1)
79 {
80 // start GetSysTimeNsTest test
81 uint64_t endTimeStamp = jankDetector->GetSysTimeNs();;
82 EXPECT_FALSE(endTimeStamp == 0);
83 }
84 } // namespace OHOS::Rosen