@@ -128,6 +128,7 @@
|
||||
<ClCompile Include="sgml.cpp" />
|
||||
<ClCompile Include="stream.cpp" />
|
||||
<ClCompile Include="unicode.cpp" />
|
||||
<ClCompile Include="watchdog.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="compat.hpp" />
|
||||
|
@@ -39,6 +39,9 @@
|
||||
<ClCompile Include="hash.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="watchdog.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.hpp">
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "sgml.cpp"
|
||||
#include "stream.cpp"
|
||||
#include "unicode.cpp"
|
||||
#include "watchdog.cpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
@@ -34,6 +35,7 @@ int main(int argc, const char * argv[])
|
||||
UnitTests::unicode::str2wstr();
|
||||
UnitTests::unicode::wstr2str();
|
||||
UnitTests::unicode::charset_encoder();
|
||||
UnitTests::watchdog::test();
|
||||
std::cout << "PASS\n";
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <stdex/system.hpp>
|
||||
#include <stdex/unicode.hpp>
|
||||
#include <stdex/vector_queue.hpp>
|
||||
#include <stdex/watchdog.hpp>
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
32
UnitTests/watchdog.cpp
Normal file
32
UnitTests/watchdog.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 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);
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user