|
6 | 6 | #include <scratchcpp/variable.h> |
7 | 7 | #include <scratchcpp/list.h> |
8 | 8 | #include <timermock.h> |
| 9 | +#include <clockmock.h> |
9 | 10 |
|
10 | 11 | #include "../common.h" |
11 | 12 | #include "testsection.h" |
12 | 13 | #include "engine/internal/engine.h" |
| 14 | +#include "engine/internal/clock.h" |
13 | 15 |
|
14 | 16 | using namespace libscratchcpp; |
15 | 17 |
|
| 18 | +using ::testing::Return; |
| 19 | + |
16 | 20 | // NOTE: resolveIds() and compile() are tested in load_project_test |
17 | 21 |
|
| 22 | +TEST(EngineTest, Clock) |
| 23 | +{ |
| 24 | + Engine engine; |
| 25 | + ASSERT_EQ(engine.m_clock, Clock::instance().get()); |
| 26 | +} |
| 27 | + |
18 | 28 | TEST(EngineTest, Clear) |
19 | 29 | { |
20 | 30 | Engine engine; |
@@ -61,6 +71,33 @@ TEST(EngineTest, Fps) |
61 | 71 | ASSERT_EQ(engine.fps(), 60.25); |
62 | 72 | } |
63 | 73 |
|
| 74 | +TEST(EngineTest, FpsProject) |
| 75 | +{ |
| 76 | + Project p("2_frames.sb3"); |
| 77 | + ASSERT_TRUE(p.load()); |
| 78 | + |
| 79 | + ClockMock clock; |
| 80 | + Engine *engine = dynamic_cast<Engine *>(p.engine().get()); |
| 81 | + engine->m_clock = &clock; |
| 82 | + |
| 83 | + std::chrono::steady_clock::time_point time1(std::chrono::milliseconds(50)); |
| 84 | + std::chrono::steady_clock::time_point time2(std::chrono::milliseconds(75)); |
| 85 | + std::chrono::steady_clock::time_point time3(std::chrono::milliseconds(83)); |
| 86 | + std::chrono::steady_clock::time_point time4(std::chrono::milliseconds(116)); |
| 87 | + EXPECT_CALL(clock, currentSteadyTime()).WillOnce(Return(time1)).WillOnce(Return(time2)).WillOnce(Return(time3)).WillOnce(Return(time4)).WillOnce(Return(time4)); |
| 88 | + EXPECT_CALL(clock, sleep(std::chrono::milliseconds(8))); |
| 89 | + p.run(); |
| 90 | + |
| 91 | + engine->setFps(10); |
| 92 | + std::chrono::steady_clock::time_point time5(std::chrono::milliseconds(100)); |
| 93 | + std::chrono::steady_clock::time_point time6(std::chrono::milliseconds(115)); |
| 94 | + std::chrono::steady_clock::time_point time7(std::chrono::milliseconds(200)); |
| 95 | + std::chrono::steady_clock::time_point time8(std::chrono::milliseconds(300)); |
| 96 | + EXPECT_CALL(clock, currentSteadyTime()).WillOnce(Return(time5)).WillOnce(Return(time6)).WillOnce(Return(time7)).WillOnce(Return(time8)).WillOnce(Return(time8)); |
| 97 | + EXPECT_CALL(clock, sleep(std::chrono::milliseconds(85))); |
| 98 | + p.run(); |
| 99 | +} |
| 100 | + |
64 | 101 | TEST(EngineTest, KeyState) |
65 | 102 | { |
66 | 103 | Engine engine; |
|
0 commit comments