/
Mr.Stalin
/
FOnline-Engine
Обзор
Документация
Войти
/
Mr.Stalin
/
FOnline-Engine
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Tests/Test_Timer.cpp
113 строк
4 KB
cvet
Non const locals (#190)
24 июл 2026, 10:46
Не верифицирован
24 июл 2026, 10:46
4883d25
Код
Авторство
О чём код?
// __________ ___ ______ _ // / ____/ __ \____ / (_)___ ___ / ____/___ ____ _(_)___ ___ // / /_ / / / / __ \/ / / __ \/ _ \ / __/ / __ \/ __ `/ / __ \/ _ ` // / __/ / /_/ / / / / / / / / / __/ / /___/ / / / /_/ / / / / / __/ // /_/ \____/_/ /_/_/_/_/ /_/\___/ /_____/_/ /_/\__, /_/_/ /_/\___/ // /____/ // FOnline Engine // https://fonline.ru // https://github.com/cvet/fonline // // MIT License // // Copyright (c) 2006 - 2026, Anton Tsvetinskiy aka cvet <cvet@tut.by> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #include "catch_amalgamated.hpp" #include "Timer.h" FO_BEGIN_NAMESPACE TEST_CASE("GameTimer") { GlobalSettings settings {false}; SECTION("SynchronizedTimeThrowsBeforeInitialization") { GameTimer timer {&settings}; CHECK_FALSE(timer.IsTimeSynchronized()); CHECK_THROWS_AS(timer.GetSynchronizedTime(), TimeNotSyncException); } SECTION("FrameAdvanceUpdatesTimeAndDelta") { GameTimer timer {&settings}; nanotime initial_time = timer.GetFrameTime(); std::this_thread::sleep_for(std::chrono::milliseconds(5)); timer.FrameAdvance(false); CHECK(timer.GetFrameTime() >= initial_time); CHECK(timer.GetFrameDeltaTime() >= timespan {}); } SECTION("SynchronizedTimeMovesForwardAfterAdvance") { GameTimer timer {&settings}; synctime sync_base {123456}; timer.SetSynchronizedTime(sync_base); CHECK(timer.IsTimeSynchronized()); CHECK(timer.GetSynchronizedTime() == sync_base); std::this_thread::sleep_for(std::chrono::milliseconds(5)); timer.FrameAdvance(false); CHECK(timer.GetSynchronizedTime() >= sync_base); } SECTION("MonotonicSynchronizedTimeDoesNotRollbackAndCatchesUp") { GameTimer timer {&settings}; synctime sync_base {123456}; timer.SetSynchronizedTime(sync_base); std::this_thread::sleep_for(std::chrono::milliseconds(20)); timer.FrameAdvance(false); synctime current_time = timer.GetSynchronizedTime(); synctime older_time {current_time.milliseconds() - 100}; timer.SetSynchronizedTimeMonotonic(older_time); CHECK(timer.GetSynchronizedTime() == current_time); std::this_thread::sleep_for(std::chrono::milliseconds(120)); timer.FrameAdvance(false); CHECK(timer.GetSynchronizedTime() > current_time); } SECTION("FramesPerSecondBecomesAvailableAfterOneSecondWindow") { GameTimer timer {&settings}; timer.FrameAdvance(false); CHECK(timer.GetFramesPerSecond() == 0); std::this_thread::sleep_for(std::chrono::milliseconds(1100)); timer.FrameAdvance(false); CHECK(timer.GetFramesPerSecond() >= 1); } } FO_END_NAMESPACE