@@ -32,6 +32,15 @@ using Catch::Matchers::Contains;
32
32
using Catch::Matchers::EndsWith;
33
33
using Catch::Matchers::Equals;
34
34
35
+ #ifdef OMEGA_BUILD_WINDOWS
36
+ #include < chrono>
37
+ #include < thread>
38
+ /* *
39
+ * Sleep for the given number of seconds.
40
+ * @param seconds Number of seconds to sleep.
41
+ */
42
+ static inline void omega_util_sleep_ (const int seconds) { std::this_thread::sleep_for (std::chrono::seconds (seconds)); }
43
+ #endif // OMEGA_BUILD_WINDOWS
35
44
36
45
TEST_CASE (" File Compare" , " [UtilTests]" ) {
37
46
SECTION (" Identity" ) {
@@ -65,7 +74,7 @@ TEST_CASE("File Copy", "[UtilTests]") {
65
74
REQUIRE (0 == stat (MAKE_PATH (" test1.copy.dat" ), &dst_stat));
66
75
67
76
// The mode includes the file type
68
- const int dst_mode = 0100600 ;// S_IFREG | S_IRUSR regular file with owner read-only
77
+ const int dst_mode = 0100600 ; // S_IFREG | S_IRUSR regular file with owner read-only
69
78
REQUIRE (dst_mode != src_stat.st_mode );
70
79
REQUIRE (src_stat.st_mode == dst_stat.st_mode );
71
80
@@ -125,7 +134,7 @@ TEST_CASE("File Touch", "[UtilTests]") {
125
134
expected = dont_exist;
126
135
REQUIRE_THAT (omega_util_available_filename (dont_exist.c_str (), nullptr ), Equals (expected));
127
136
omega_util_touch (dont_exist.c_str (),
128
- 0 );// logs an error as expected because create is false and the file does not exist
137
+ 0 ); // logs an error as expected because create is false and the file does not exist
129
138
REQUIRE (!omega_util_file_exists (dont_exist.c_str ()));
130
139
#ifdef OMEGA_BUILD_WINDOWS
131
140
// sleep for 1 second to ensure the file modification time is different,
@@ -237,65 +246,65 @@ TEST_CASE("File Extension", "[UtilTests]") {
237
246
238
247
239
248
TEST_CASE (" Emoji Filename Handling" , " [FilesystemTests]" ) {
240
- const char * emoji_filenames[] = {
249
+ const char * emoji_filenames[] = {
241
250
" test_😀.dat" ,
242
251
" test_👍.dat" ,
243
252
" test_🔥.dat" ,
244
253
" test 💩.dat" , // Space in filename as well
245
254
" test_🚀.dat" ,
246
- " test_👨👩👧👦.dat" // Family emoji with zero-width joiners
255
+ " test_👨👩👧👦.dat" // Family emoji with zero-width joiners
247
256
};
248
-
257
+
249
258
char buffer[FILENAME_MAX];
250
-
259
+
251
260
// Test filesystem operations with emoji filenames
252
- for (const auto & emoji_filename : emoji_filenames) {
261
+ for (const auto & emoji_filename: emoji_filenames) {
253
262
const char dir_sep = omega_util_directory_separator ();
254
263
std::string base_path = std::string (DATA_DIR.string ().c_str ()) + dir_sep;
255
264
std::string full_path = base_path + emoji_filename;
256
-
265
+
257
266
// Create a file with emoji in filename
258
267
std::ofstream file (full_path);
259
268
file << " Test content" << std::endl;
260
269
file.close ();
261
-
270
+
262
271
// Test file_exists
263
272
REQUIRE (omega_util_file_exists (full_path.c_str ()));
264
-
273
+
265
274
// Test available_filename - since the file exists, we expect a path with -1 suffix
266
- char * available_name = omega_util_available_filename (full_path.c_str (), buffer);
275
+ char * available_name = omega_util_available_filename (full_path.c_str (), buffer);
267
276
REQUIRE (available_name != nullptr );
268
277
// The file exists so available_name should append -1 to the filename
269
278
std::string expected_path = full_path;
270
279
size_t dot_pos = expected_path.rfind (' .' );
271
280
expected_path.insert (dot_pos, " -1" );
272
281
REQUIRE (std::string (available_name) == expected_path);
273
-
282
+
274
283
// Test basename, dirname and extension
275
- char * basename_result = omega_util_basename (full_path.c_str (), nullptr , 0 );
284
+ char * basename_result = omega_util_basename (full_path.c_str (), nullptr , 0 );
276
285
REQUIRE (basename_result != nullptr );
277
286
REQUIRE (std::string (basename_result) == emoji_filename);
278
-
279
- char * dirname_result = omega_util_dirname (full_path.c_str (), nullptr );
287
+
288
+ char * dirname_result = omega_util_dirname (full_path.c_str (), nullptr );
280
289
REQUIRE (dirname_result != nullptr );
281
290
REQUIRE (std::string (dirname_result) == base_path.substr (0 , base_path.length () - 1 ));
282
-
283
- char * ext_result = omega_util_file_extension (full_path.c_str (), nullptr );
291
+
292
+ char * ext_result = omega_util_file_extension (full_path.c_str (), nullptr );
284
293
REQUIRE (ext_result != nullptr );
285
294
REQUIRE (std::string (ext_result) == " .dat" );
286
-
295
+
287
296
// Create a second file for copy operations
288
297
std::string copy_path = base_path + " copy_" + emoji_filename;
289
-
298
+
290
299
// Test file_copy
291
300
REQUIRE (0 == omega_util_file_copy (full_path.c_str (), copy_path.c_str (), 0 ));
292
301
REQUIRE (omega_util_file_exists (copy_path.c_str ()));
293
302
REQUIRE (0 == omega_util_compare_files (full_path.c_str (), copy_path.c_str ()));
294
-
303
+
295
304
// Test remove_file
296
305
REQUIRE (0 == omega_util_remove_file (full_path.c_str ()));
297
306
REQUIRE (!omega_util_file_exists (full_path.c_str ()));
298
-
307
+
299
308
REQUIRE (0 == omega_util_remove_file (copy_path.c_str ()));
300
309
REQUIRE (!omega_util_file_exists (copy_path.c_str ()));
301
310
}
0 commit comments