Skip to content

Commit b303d16

Browse files
committed
Enable util_tests.cpp on Windows
1 parent 2e998d2 commit b303d16

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

modules/core/util/func_tests/util_tests.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,28 @@
66

77
#include "core/util/include/util.hpp"
88

9+
#ifdef _WIN32
10+
#include <Windows.h>
11+
inline int unsetenv(const char* name) { return SetEnvironmentVariableA(name, NULL) ? 0 : -1; }
12+
inline int setenv(const char* name, const char* value, int overwrite) {
13+
return SetEnvironmentVariableA(name, value) ? 0 : -1;
14+
}
15+
#else
16+
extern "C" int unsetenv(const char* name);
17+
extern "C" int setenv(const char* name, const char* value, int overwrite);
18+
#endif
19+
920
TEST(util_tests, check_unset_env) {
10-
#ifndef _WIN32
1121
int save_var = ppc::util::GetPPCNumThreads();
1222

1323
unsetenv("OMP_NUM_THREADS"); // NOLINT(misc-include-cleaner)
1424

1525
EXPECT_EQ(ppc::util::GetPPCNumThreads(), 1);
1626

1727
setenv("OMP_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(misc-include-cleaner)
18-
#else
19-
GTEST_SKIP();
20-
#endif
2128
}
2229

2330
TEST(util_tests, check_set_env) {
24-
#ifndef _WIN32
2531
int save_var = ppc::util::GetPPCNumThreads();
2632

2733
const int num_threads = static_cast<int>(std::thread::hardware_concurrency());
@@ -30,7 +36,4 @@ TEST(util_tests, check_set_env) {
3036
EXPECT_EQ(ppc::util::GetPPCNumThreads(), num_threads);
3137

3238
setenv("OMP_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(misc-include-cleaner)
33-
#else
34-
GTEST_SKIP();
35-
#endif
3639
}

0 commit comments

Comments
 (0)