|
27 | 27 | #include <cstring> |
28 | 28 | #include <fstream> |
29 | 29 | #include <map> |
| 30 | +#include <vector> |
| 31 | + |
| 32 | +#ifdef _WIN32 |
| 33 | +#include <direct.h> |
| 34 | +#include <sys/types.h> |
| 35 | +#include <sys/stat.h> |
| 36 | +#include <io.h> |
| 37 | +#define stat_func _stat |
| 38 | +#define stat_struct struct _stat |
| 39 | +#else |
30 | 40 | #include <sys/stat.h> |
31 | 41 | #include <unistd.h> |
32 | | -#include <vector> |
| 42 | +#define stat_func stat |
| 43 | +#define stat_struct struct stat |
| 44 | +#endif |
33 | 45 |
|
34 | 46 | using namespace lsl::security; |
35 | 47 |
|
36 | 48 | // Helper functions for test file/directory operations |
37 | 49 | static void test_mkdir_p(const std::string& path) { |
| 50 | +#ifdef _WIN32 |
| 51 | + std::string cmd = "mkdir \"" + path + "\" 2>nul"; |
| 52 | +#else |
38 | 53 | std::string cmd = "mkdir -p \"" + path + "\""; |
| 54 | +#endif |
39 | 55 | std::system(cmd.c_str()); |
40 | 56 | } |
41 | 57 |
|
42 | 58 | static void test_rm_rf(const std::string& path) { |
| 59 | +#ifdef _WIN32 |
| 60 | + std::string cmd = "rmdir /s /q \"" + path + "\" 2>nul"; |
| 61 | +#else |
43 | 62 | std::string cmd = "rm -rf \"" + path + "\""; |
| 63 | +#endif |
44 | 64 | std::system(cmd.c_str()); |
45 | 65 | } |
46 | 66 |
|
47 | 67 | static bool test_file_exists(const std::string& path) { |
48 | | - struct stat buffer; |
49 | | - return (stat(path.c_str(), &buffer) == 0); |
| 68 | + stat_struct buffer; |
| 69 | + return (stat_func(path.c_str(), &buffer) == 0); |
50 | 70 | } |
51 | 71 |
|
52 | 72 | static size_t test_file_size(const std::string& path) { |
53 | | - struct stat buffer; |
54 | | - if (stat(path.c_str(), &buffer) != 0) return 0; |
| 73 | + stat_struct buffer; |
| 74 | + if (stat_func(path.c_str(), &buffer) != 0) return 0; |
55 | 75 | return static_cast<size_t>(buffer.st_size); |
56 | 76 | } |
57 | 77 |
|
@@ -122,7 +142,14 @@ TEST_CASE("Key save creates directories and sets permissions", "[security][keyge |
122 | 142 | sec.initialize(); |
123 | 143 |
|
124 | 144 | // Use a unique nested path that does not pre-exist |
125 | | - std::string test_base = "/tmp/lsl_dirtest_" + |
| 145 | + std::string tmp_dir; |
| 146 | +#ifdef _WIN32 |
| 147 | + const char* tmp_env = std::getenv("TEMP"); |
| 148 | + tmp_dir = tmp_env ? tmp_env : "C:\\Temp"; |
| 149 | +#else |
| 150 | + tmp_dir = "/tmp"; |
| 151 | +#endif |
| 152 | + std::string test_base = tmp_dir + "/lsl_dirtest_" + |
126 | 153 | std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()); |
127 | 154 | std::string nested_config = test_base + "/sub/deep/lsl_api.cfg"; |
128 | 155 |
|
|
0 commit comments