Skip to content

Commit 800dfc1

Browse files
committed
test fixes for windows full
1 parent aa96bee commit 800dfc1

4 files changed

Lines changed: 130 additions & 39 deletions

File tree

tests/test_archive.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,28 @@
1414
#include <stdlib.h>
1515

1616
#ifdef _WIN32
17-
#define TEST_TAR "streamio_test.tar"
17+
#include <windows.h>
18+
static char g_temp_path[MAX_PATH];
19+
static char g_test_tar[MAX_PATH];
20+
static char g_test_tgz[MAX_PATH];
21+
static char g_test_dir[MAX_PATH];
22+
23+
static void init_test_paths(void) {
24+
static int initialized = 0;
25+
if (!initialized) {
26+
GetTempPathA(MAX_PATH, g_temp_path);
27+
snprintf(g_test_tar, MAX_PATH, "%sstreamio_test.tar", g_temp_path);
28+
snprintf(g_test_tgz, MAX_PATH, "%sstreamio_test.tar.gz", g_temp_path);
29+
snprintf(g_test_dir, MAX_PATH, "%sstreamio_test_dir", g_temp_path);
30+
initialized = 1;
31+
}
32+
}
33+
#define TEST_TAR (init_test_paths(), g_test_tar)
34+
#define TEST_TGZ (init_test_paths(), g_test_tgz)
35+
#define TEST_DIR (init_test_paths(), g_test_dir)
1836
#else
1937
#define TEST_TAR "/tmp/streamio_test.tar"
20-
#endif
21-
#ifdef _WIN32
22-
#define TEST_TGZ "streamio_test.tar.gz"
23-
#else
2438
#define TEST_TGZ "/tmp/streamio_test.tar.gz"
25-
#endif
26-
#ifdef _WIN32
27-
#define TEST_DIR "streamio_test_dir"
28-
#else
2939
#define TEST_DIR "/tmp/streamio_test_dir"
3040
#endif
3141

@@ -369,13 +379,18 @@ int main(void)
369379

370380
#ifdef HAVE_LIBARCHIVE
371381
test_archive_available();
382+
#ifndef _WIN32
383+
/* Archive tests require tar command, skip on Windows */
372384
test_archive_open();
373385
test_archive_walk();
374386
test_archive_read_entry();
375387

376388
#ifdef HAVE_ZLIB
377389
test_archive_compressed();
378390
#endif
391+
#else
392+
printf("SKIP: Archive creation tests (tar command not available on Windows)\n");
393+
#endif
379394

380395
#else
381396
printf("SKIP: Archive tests (libarchive not available)\n");

tests/test_basic.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@
1515
#endif
1616

1717
#ifdef _WIN32
18-
#define TEST_FILE "streamio_test.dat"
18+
#include <windows.h>
19+
static char g_test_file[MAX_PATH];
20+
static const char *TEST_FILE(void) {
21+
static int initialized = 0;
22+
if (!initialized) {
23+
GetTempPathA(MAX_PATH, g_test_file);
24+
strcat(g_test_file, "streamio_test.dat");
25+
initialized = 1;
26+
}
27+
return g_test_file;
28+
}
29+
#define TEST_FILE TEST_FILE()
1930
#else
2031
#define TEST_FILE "/tmp/streamio_test.dat"
2132
#endif

tests/test_compression.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,36 @@
1212
#endif
1313

1414
#ifdef _WIN32
15-
#define TEST_FILE "streamio_compress_test.txt"
15+
#include <windows.h>
16+
static char g_temp_path[MAX_PATH];
17+
static char g_test_file[MAX_PATH];
18+
static char g_test_file_gz[MAX_PATH];
19+
static char g_test_file_bz2[MAX_PATH];
20+
static char g_test_file_xz[MAX_PATH];
21+
static char g_test_file_zst[MAX_PATH];
22+
23+
static void init_test_paths(void) {
24+
static int initialized = 0;
25+
if (!initialized) {
26+
GetTempPathA(MAX_PATH, g_temp_path);
27+
snprintf(g_test_file, MAX_PATH, "%sstreamio_compress_test.txt", g_temp_path);
28+
snprintf(g_test_file_gz, MAX_PATH, "%sstreamio_compress_test.txt.gz", g_temp_path);
29+
snprintf(g_test_file_bz2, MAX_PATH, "%sstreamio_compress_test.txt.bz2", g_temp_path);
30+
snprintf(g_test_file_xz, MAX_PATH, "%sstreamio_compress_test.txt.xz", g_temp_path);
31+
snprintf(g_test_file_zst, MAX_PATH, "%sstreamio_compress_test.txt.zst", g_temp_path);
32+
initialized = 1;
33+
}
34+
}
35+
#define TEST_FILE (init_test_paths(), g_test_file)
36+
#define TEST_FILE_GZ (init_test_paths(), g_test_file_gz)
37+
#define TEST_FILE_BZ2 (init_test_paths(), g_test_file_bz2)
38+
#define TEST_FILE_XZ (init_test_paths(), g_test_file_xz)
39+
#define TEST_FILE_ZST (init_test_paths(), g_test_file_zst)
1640
#else
1741
#define TEST_FILE "/tmp/streamio_compress_test.txt"
18-
#endif
19-
#ifdef _WIN32
20-
#define TEST_FILE_GZ "streamio_compress_test.txt.gz"
21-
#else
2242
#define TEST_FILE_GZ "/tmp/streamio_compress_test.txt.gz"
23-
#endif
24-
#ifdef _WIN32
25-
#define TEST_FILE_BZ2 "streamio_compress_test.txt.bz2"
26-
#else
2743
#define TEST_FILE_BZ2 "/tmp/streamio_compress_test.txt.bz2"
28-
#endif
29-
#ifdef _WIN32
30-
#define TEST_FILE_XZ "streamio_compress_test.txt.xz"
31-
#else
3244
#define TEST_FILE_XZ "/tmp/streamio_compress_test.txt.xz"
33-
#endif
34-
#ifdef _WIN32
35-
#define TEST_FILE_ZST "streamio_compress_test.txt.zst"
36-
#else
3745
#define TEST_FILE_ZST "/tmp/streamio_compress_test.txt.zst"
3846
#endif
3947

tests/test_walker.c

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@
1515
#include <sys/stat.h>
1616

1717
#ifdef _WIN32
18-
#define TEST_DIR "streamio_walker_test"
18+
#include <windows.h>
19+
static char g_test_dir[MAX_PATH];
20+
static const char *get_test_dir(void) {
21+
static int initialized = 0;
22+
if (!initialized) {
23+
GetTempPathA(MAX_PATH, g_test_dir);
24+
strcat(g_test_dir, "streamio_walker_test");
25+
initialized = 1;
26+
}
27+
return g_test_dir;
28+
}
29+
#define TEST_DIR get_test_dir()
1930
#else
2031
#define TEST_DIR "/tmp/streamio_walker_test"
2132
#endif
@@ -41,35 +52,77 @@ static int test_passed = 0;
4152
return; \
4253
} while (0)
4354

55+
/* Helper to create directory cross-platform */
56+
static int mkdir_compat(const char *path) {
57+
#ifdef _WIN32
58+
return _mkdir(path);
59+
#else
60+
return mkdir(path, 0755);
61+
#endif
62+
}
63+
64+
/* Helper to build path cross-platform */
65+
static void build_path(char *dest, size_t size, const char *dir, const char *file) {
66+
#ifdef _WIN32
67+
snprintf(dest, size, "%s\\%s", dir, file);
68+
#else
69+
snprintf(dest, size, "%s/%s", dir, file);
70+
#endif
71+
}
72+
73+
/* Recursive directory removal */
74+
static void rmdir_recursive(const char *path) {
75+
#ifdef _WIN32
76+
char cmd[MAX_PATH + 20];
77+
snprintf(cmd, sizeof(cmd), "rmdir /s /q \"%s\" 2>nul", path);
78+
system(cmd);
79+
#else
80+
char cmd[PATH_MAX + 20];
81+
snprintf(cmd, sizeof(cmd), "rm -rf \"%s\"", path);
82+
system(cmd);
83+
#endif
84+
}
85+
4486
/* Create test directory structure */
4587
static int create_test_tree(void)
4688
{
47-
system("rm -rf " TEST_DIR);
48-
mkdir(TEST_DIR, 0755);
89+
char path[512];
90+
91+
rmdir_recursive(TEST_DIR);
92+
mkdir_compat(TEST_DIR);
4993

5094
/* Create files */
51-
FILE *f1 = fopen(TEST_DIR "/file1.txt", "w");
95+
build_path(path, sizeof(path), TEST_DIR, "file1.txt");
96+
FILE *f1 = fopen(path, "w");
5297
if (!f1) return -1;
5398
fprintf(f1, "File 1 content");
5499
fclose(f1);
55100

56-
FILE *f2 = fopen(TEST_DIR "/file2.txt", "w");
101+
build_path(path, sizeof(path), TEST_DIR, "file2.txt");
102+
FILE *f2 = fopen(path, "w");
57103
if (!f2) return -1;
58104
fprintf(f2, "File 2 content");
59105
fclose(f2);
60106

61107
/* Create subdirectory */
62-
mkdir(TEST_DIR "/subdir", 0755);
108+
build_path(path, sizeof(path), TEST_DIR, "subdir");
109+
mkdir_compat(path);
63110

64-
FILE *f3 = fopen(TEST_DIR "/subdir/file3.txt", "w");
111+
char subdir_path[512];
112+
build_path(subdir_path, sizeof(subdir_path), TEST_DIR, "subdir");
113+
build_path(path, sizeof(path), subdir_path, "file3.txt");
114+
FILE *f3 = fopen(path, "w");
65115
if (!f3) return -1;
66116
fprintf(f3, "File 3 in subdir");
67117
fclose(f3);
68118

69119
/* Create nested subdirectory */
70-
mkdir(TEST_DIR "/subdir/nested", 0755);
120+
char nested_path[512];
121+
build_path(nested_path, sizeof(nested_path), subdir_path, "nested");
122+
mkdir_compat(nested_path);
71123

72-
FILE *f4 = fopen(TEST_DIR "/subdir/nested/file4.txt", "w");
124+
build_path(path, sizeof(path), nested_path, "file4.txt");
125+
FILE *f4 = fopen(path, "w");
73126
if (!f4) return -1;
74127
fprintf(f4, "File 4 in nested");
75128
fclose(f4);
@@ -80,7 +133,7 @@ static int create_test_tree(void)
80133
/* Clean up test files */
81134
static void cleanup_test_tree(void)
82135
{
83-
system("rm -rf " TEST_DIR);
136+
rmdir_recursive(TEST_DIR);
84137
}
85138

86139
/* Test walking a single file */
@@ -99,8 +152,11 @@ void test_walk_single_file(void)
99152
if (create_test_tree() != 0)
100153
FAIL("Failed to create test tree");
101154

155+
char file_path[512];
156+
build_path(file_path, sizeof(file_path), TEST_DIR, "file1.txt");
157+
102158
single_file_count = 0;
103-
int ret = walk_path(TEST_DIR "/file1.txt", single_file_callback, NULL, 0);
159+
int ret = walk_path(file_path, single_file_callback, NULL, 0);
104160
if (ret < 0) {
105161
cleanup_test_tree();
106162
FAIL("walk_path failed");
@@ -459,7 +515,8 @@ int main(void)
459515
test_walk_filter_dirs();
460516
test_read_file_streams();
461517

462-
#ifdef HAVE_LIBARCHIVE
518+
#if defined(HAVE_LIBARCHIVE) && !defined(_WIN32)
519+
/* Archive tests require tar command, skip on Windows */
463520
test_walk_expand_archive();
464521
test_read_archive_streams();
465522
#ifdef HAVE_ZLIB

0 commit comments

Comments
 (0)