blob: 2193c9dd76328de30bad054ade2462ca41ee4ed9 [file] [log] [blame]
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001/*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Marin Shalamanove8a663d2020-11-24 17:48:00 +010017#include <gmock/gmock.h>
18#include <gtest/gtest.h>
19
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080020#include <scheduler/Fps.h>
21
22#include "FpsOps.h"
23
Marin Shalamanove8a663d2020-11-24 17:48:00 +010024namespace android {
25
26TEST(FpsTest, construct) {
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070027 EXPECT_FALSE(Fps().isValid());
Marin Shalamanove8a663d2020-11-24 17:48:00 +010028
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070029 EXPECT_FALSE((0_Hz).isValid());
30 EXPECT_TRUE((120_Hz).isValid());
31 EXPECT_TRUE((0.5_Hz).isValid());
32
33 EXPECT_FALSE(Fps::fromPeriodNsecs(0).isValid());
34
35 const Fps fps = Fps::fromPeriodNsecs(16'666'667);
36 EXPECT_TRUE(fps.isValid());
37 EXPECT_EQ(fps, 60_Hz);
Marin Shalamanove8a663d2020-11-24 17:48:00 +010038}
39
40TEST(FpsTest, compare) {
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070041 EXPECT_EQ(60_Hz, 60_Hz);
42 EXPECT_EQ(60_Hz, 59.9999_Hz);
43 EXPECT_EQ(60_Hz, 60.0001_Hz);
Marin Shalamanove8a663d2020-11-24 17:48:00 +010044
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070045 EXPECT_LE(60_Hz, 60_Hz);
46 EXPECT_LE(60_Hz, 59.9999_Hz);
47 EXPECT_LE(60_Hz, 60.0001_Hz);
Marin Shalamanove8a663d2020-11-24 17:48:00 +010048
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070049 EXPECT_GE(60_Hz, 60_Hz);
50 EXPECT_GE(60_Hz, 59.9999_Hz);
51 EXPECT_GE(60_Hz, 60.0001_Hz);
Marin Shalamanove8a663d2020-11-24 17:48:00 +010052
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070053 // Fps with difference of 1 should be different.
54 EXPECT_NE(60_Hz, 61_Hz);
55 EXPECT_LT(60_Hz, 61_Hz);
56 EXPECT_GT(60_Hz, 59_Hz);
Marin Shalamanove8a663d2020-11-24 17:48:00 +010057
58 // These are common refresh rates which should be different.
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070059 EXPECT_NE(60_Hz, 59.94_Hz);
60 EXPECT_GT(60_Hz, 59.94_Hz);
61 EXPECT_NE(30_Hz, 29.97_Hz);
62 EXPECT_GT(30_Hz, 29.97_Hz);
Marin Shalamanove8a663d2020-11-24 17:48:00 +010063}
64
65TEST(FpsTest, getIntValue) {
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070066 EXPECT_EQ(30, (30.1_Hz).getIntValue());
67 EXPECT_EQ(31, (30.9_Hz).getIntValue());
68 EXPECT_EQ(31, (30.5_Hz).getIntValue());
Marin Shalamanove8a663d2020-11-24 17:48:00 +010069}
70
Dominik Laskowski953b7fd2022-01-08 19:34:59 -080071TEST(FpsTest, range) {
72 const auto fps = Fps::fromPeriodNsecs(16'666'665);
73
74 EXPECT_TRUE((FpsRange{60.000004_Hz, 60.000004_Hz}.includes(fps)));
75 EXPECT_TRUE((FpsRange{59_Hz, 60.1_Hz}.includes(fps)));
76 EXPECT_FALSE((FpsRange{75_Hz, 90_Hz}.includes(fps)));
77 EXPECT_FALSE((FpsRange{60.0011_Hz, 90_Hz}.includes(fps)));
78 EXPECT_FALSE((FpsRange{50_Hz, 59.998_Hz}.includes(fps)));
79}
80
Marin Shalamanove8a663d2020-11-24 17:48:00 +010081} // namespace android