stdex/UnitTests/watchdog.cpp
Simon Rozman 38c6b40b21 Bump Copyright year
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-06 10:55:09 +01:00

32 lines
682 B
C++

/*
SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis
*/
#include "pch.hpp"
using namespace std;
#ifdef _WIN32
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
#endif
namespace UnitTests
{
TEST_CLASS(watchdog)
{
public:
TEST_METHOD(test)
{
volatile bool wd_called = false;
stdex::watchdog<std::chrono::steady_clock> wd(
std::chrono::milliseconds(100), [&] { wd_called = true; });
for (int i = 0; i < 100; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Assert::IsFalse(wd_called);
wd.reset();
}
std::this_thread::sleep_for(std::chrono::milliseconds(300));
Assert::IsTrue(wd_called);
}
};
}