Skip to content

Commit 5e48d78

Browse files
committed
Fix unit tests to use std::chrono not Windows.h
This fixes the unit tests to use the std::chrono library insead of windows.h for timing information.
1 parent 02bba8a commit 5e48d78

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

unit/util/piped_process.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# include <util/optional.h>
77
# include <util/piped_process.h>
88
# include <util/string_utils.h>
9+
// Used for testing destructor/timing
10+
#include <chrono>
911

1012
TEST_CASE(
1113
"Creating a sub process and reading its output.",
@@ -75,14 +77,16 @@ TEST_CASE(
7577
std::vector<std::string> commands;
7678
#ifdef _WIN32
7779
commands.push_back("cmd /c ping 127.0.0.1 -n 6 > nul");
78-
SYSTEMTIME st;
79-
GetSystemTime(&st);
80-
WORD calc = 3600 * st.wHour + 60 * st.wMinute + st.wSecond;
80+
std::chrono::steady_clock::time_point start_time =
81+
std::chrono::steady_clock::now();
8182
piped_processt process(commands);
8283
process.~piped_processt();
83-
GetSystemTime(&st);
84-
// New time minus old time, could go wrong at midnight
85-
calc = 3600 * st.wHour + 60 * st.wMinute + st.wSecond - calc;
84+
std::chrono::steady_clock::time_point end_time =
85+
std::chrono::steady_clock::now();
86+
std::chrono::duration<double> time_span =
87+
std::chrono::duration_cast<std::chrono::duration<double>>(
88+
end_time - start_time);
89+
size_t calc = time_span.count();
8690
#else
8791
// Currently not working under Linxu/MacOS?!
8892
// commands.push_back("sleep 6");

0 commit comments

Comments
 (0)