Flutter Engine
 
Loading...
Searching...
No Matches
stopwatch_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
7#include "gmock/gmock.h" // IWYU pragma: keep
8#include "gtest/gtest.h"
9
10using testing::Return;
11
12namespace flutter {
13namespace testing {
14
16 public:
17 fml::Milliseconds GetFrameBudget() const override { return budget_; }
18
19 void SetFrameBudget(fml::Milliseconds budget) { budget_ = budget; }
20
21 private:
22 fml::Milliseconds budget_;
23};
24
25TEST(Instrumentation, GetDefaultFrameBudgetTest) {
26 fml::Milliseconds frame_budget_60fps = fml::RefreshRateToFrameBudget(60);
27 // The default constructor sets the frame_budget to 16.6667 (60 fps).
29 fml::Milliseconds actual_frame_budget = stopwatch.GetFrameBudget();
30 EXPECT_EQ(frame_budget_60fps, actual_frame_budget);
31}
32
33TEST(Instrumentation, GetOneShotFrameBudgetTest) {
34 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
35 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
36 fml::Milliseconds actual_frame_budget = stopwatch.GetFrameBudget();
37 EXPECT_EQ(frame_budget_90fps, actual_frame_budget);
38}
39
40TEST(Instrumentation, GetFrameBudgetFromUpdaterTest) {
42 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
43 updater.SetFrameBudget(frame_budget_90fps);
44
45 Stopwatch stopwatch(updater);
46 fml::Milliseconds actual_frame_budget = stopwatch.GetFrameBudget();
47 EXPECT_EQ(frame_budget_90fps, actual_frame_budget);
48}
49
50TEST(Instrumentation, GetLapByIndexTest) {
51 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
52 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
54 EXPECT_EQ(stopwatch.GetLap(0), fml::TimeDelta::FromMilliseconds(10));
55}
56
57TEST(Instrumentation, GetCurrentSampleStartStopTest) {
58 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
59 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
60 // Stopwatch starts primed to place the first sample in slot 0 when
61 // the actual time is available.
62 EXPECT_EQ(stopwatch.GetCurrentSample(), size_t(Stopwatch::kMaxSamples - 1u));
63 stopwatch.Start();
64 // CurrentSample still not updated because we are still measuring
65 // this frame.
66 EXPECT_EQ(stopwatch.GetCurrentSample(), size_t(Stopwatch::kMaxSamples - 1u));
67 stopwatch.Stop();
68 // The most current sample is placed in slot #0.
69 EXPECT_EQ(stopwatch.GetCurrentSample(), size_t(0));
70}
71
72TEST(Instrumentation, GetCurrentSampleSetLapTimeTest) {
73 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
74 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
75 // Stopwatch starts primed to place the first sample in slot 0 when
76 // the actual time is available.
77 EXPECT_EQ(stopwatch.GetCurrentSample(), size_t(Stopwatch::kMaxSamples - 1u));
79 // The most current sample is placed in slot #0.
80 EXPECT_EQ(stopwatch.GetCurrentSample(), size_t(0));
81}
82
83TEST(Instrumentation, GetLapsCount) {
84 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
85 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
87 EXPECT_EQ(stopwatch.GetLapsCount(), size_t(120));
88}
89
90} // namespace testing
91} // namespace flutter
Used for fixed refresh rate cases.
Definition stopwatch.h:80
The refresh rate interface for Stopwatch.
Definition stopwatch.h:23
const fml::TimeDelta & GetLap(size_t index) const
Definition stopwatch.cc:42
fml::Milliseconds GetFrameBudget() const
All places which want to get frame_budget should call this function.
Definition stopwatch.cc:85
size_t GetLapsCount() const
Return a reference to all the laps.
Definition stopwatch.cc:46
size_t GetCurrentSample() const
Definition stopwatch.cc:50
void SetLapTime(const fml::TimeDelta &delta)
Definition stopwatch.cc:33
static const size_t kMaxSamples
Definition stopwatch.h:20
fml::Milliseconds GetFrameBudget() const override
void SetFrameBudget(fml::Milliseconds budget)
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition time_delta.h:46
TEST(NativeAssetsManagerTest, NoAvailableAssets)
std::chrono::duration< double, std::milli > Milliseconds
Definition time_delta.h:18
Milliseconds RefreshRateToFrameBudget(T refresh_rate)
Definition time_delta.h:24