diff --git a/tests/test_media_delivery_download.c b/tests/test_media_delivery_download.c index 5d17d43f..4402556f 100644 --- a/tests/test_media_delivery_download.c +++ b/tests/test_media_delivery_download.c @@ -16,7 +16,6 @@ #include "../lib/u_async.h" #include "../lib/debug_config.h" #include "../lib/mem.h" -#include "test_utils.h" #include "../transport_layer/secure_channel.h" #include "../routing_layer/topo_node_sqlite.h" #include "../routing_layer/conn_mgr.h" @@ -58,7 +57,13 @@ static int file_size(const char* path) { static void test_setup(void) { snprintf(g_temp_dir, sizeof(g_temp_dir), "%s", TEMP_DIR); - if (test_mkdtemp(g_temp_dir) != 0) { fprintf(stderr, "mkdtemp failed\n"); exit(1); } +#ifdef _WIN32 + { char tmp_path[512]; GetTempPathA(sizeof(tmp_path), tmp_path); + snprintf(g_temp_dir, sizeof(g_temp_dir), "%s\\utun_test_%08x", tmp_path, (unsigned)rand()); + _mkdir(g_temp_dir); } +#else + if (!mkdtemp(g_temp_dir)) { fprintf(stderr, "mkdtemp failed\n"); exit(1); } +#endif debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); g_ua = uasync_create(); } diff --git a/tests/test_media_delivery_full.c b/tests/test_media_delivery_full.c index cd68327e..06176694 100644 --- a/tests/test_media_delivery_full.c +++ b/tests/test_media_delivery_full.c @@ -22,7 +22,6 @@ #include "../lib/u_async.h" #include "../lib/debug_config.h" #include "../lib/mem.h" -#include "test_utils.h" #include #include @@ -61,6 +60,15 @@ static char* gv(const char* p, const char* k) { char* r = (strcmp(k, "pub") == 0) ? u_strdup(c->global.my_public_key_hex) : u_strdup(c->global.my_private_key_hex); free_config(c); return r; } +static void t_mkdtemp(char* t) { +#ifdef _WIN32 + char tmp_path[512]; GetTempPathA(sizeof(tmp_path), tmp_path); + snprintf(t, 256, "%s\\utun_test_%08x", tmp_path, (unsigned)rand()); + _mkdir(t); +#else + (void)!mkdtemp(t); +#endif +} static void t_rmdir(const char* p) { char cmd[512]; snprintf(cmd, sizeof(cmd), "rm -rf %s", p); system(cmd); } static int db_count(sqlite3* db, const char* tbl, const char* wh, uint64_t val) { @@ -308,7 +316,7 @@ int main(void) { utun_instance_set_tun_init_enabled(0); srand((unsigned)time(NULL)); printf("=== test_media_delivery_full ===\n"); - test_mkdtemp(g_tdir); + t_mkdtemp(g_tdir); for (int i = 0; i < N_NODES; i++) { snprintf(g_cfg[i], sizeof(g_cfg[i]), "%s/n%d.conf", g_tdir, i); diff --git a/tests/test_media_delivery_integration.c b/tests/test_media_delivery_integration.c index 1dc76707..965b07b0 100644 --- a/tests/test_media_delivery_integration.c +++ b/tests/test_media_delivery_integration.c @@ -16,7 +16,6 @@ #include "../transport_layer/etcp.h" #include "../config_parser.h" #include "../config_updater.h" -#include "test_utils.h" #include "../routing_layer/topo_group.h" #include "../routing_layer/topo_node.h" #include "../lib/u_async.h" @@ -59,6 +58,21 @@ static char* gv(const char* p, const char* k) { free_config(c); return r; } +static void test_mkdtemp(char* tmpl) { +#ifdef _WIN32 + char tmp_path[512]; GetTempPathA(sizeof(tmp_path), tmp_path); + snprintf(tmpl, 256, "%s\\utun_test_%08x", tmp_path, (unsigned)rand()); + _mkdir(tmpl); +#else + (void)!mkdtemp(tmpl); +#endif +} + +static void test_unlink(const char* p) { unlink(p); } +static void test_rmdir(const char* p) { + char cmd[512]; snprintf(cmd, sizeof(cmd), "rm -rf %s", p); system(cmd); +} + /* ── helpers ── */ static int count_rows(sqlite3* db, const char* tbl, const char* where, uint64_t val) { @@ -297,6 +311,6 @@ done: if (g_a) { g_a->running = 0; utun_instance_destroy(g_a); g_a = NULL; } if (g_b) { g_b->running = 0; utun_instance_destroy(g_b); g_b = NULL; } if (g_ua) { uasync_destroy(g_ua, 0); g_ua = NULL; } - { char cmd[512]; snprintf(cmd, sizeof(cmd), "rm -rf %s", g_tdir); system(cmd); } + test_rmdir(g_tdir); return g_failed > 0 ? 1 : 0; }