Skip to content

Commit

Permalink
Allow ziptool_regress to read commands from stdin, use to pass non-AS…
Browse files Browse the repository at this point in the history
…CII commands.

Hopefully fixes tests on Windows CI builds.
  • Loading branch information
dillof committed Jul 19, 2023
1 parent 94f1e6a commit 4bfca9d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
5 changes: 4 additions & 1 deletion regress/file_comment_encmismatch.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# set file comment to UTF-8 for CP437 encoded filename (adds InfoZIP extra field)
return 0
arguments testfile.zip set_file_comment 0 ÄÖÜßäöü
arguments -i testfile.zip dummy
stdin
set_file_comment 0 ÄÖÜßäöü
end-of-inline-data
file testfile.zip test-cp437.zip test-cp437-comment-utf-8.zip
5 changes: 4 additions & 1 deletion regress/name_locate-utf8.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
description tests for various encoding flags for zip_name_locate
arguments test.zip name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" 0 name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" 4 name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" 8 name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" r name_locate "æÆôöòûùÿÖÜ¢£¥₧ƒá" s
arguments -i test.zip dummy
stdin
name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá 0 name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá 4 name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá 8 name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá r name_locate æÆôöòûùÿÖÜ¢£¥₧ƒá s
end-of-inline-data
return 0
file test.zip test-cp437.zip
stdout
Expand Down
5 changes: 4 additions & 1 deletion regress/rename_utf8.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# rename file to UTF-8 name in zip archive
return 0
arguments testfile rename 0 ÄÖÜßäöü
arguments -i testfile dummy
stdin
rename 0 ÄÖÜßäöü
end-of-inline-data
file testfile testfile.zip testfile-UTF8.zip
5 changes: 4 additions & 1 deletion regress/rename_utf8_encmismatch.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# rename file to UTF-8 name in zip archive with CP437 comment (sets InfoZIP UTF-8 Name Extension)
return 0
arguments testfile rename 0 ÄÖÜßäöü
arguments -i testfile dummy
stdin
rename 0 ÄÖÜßäöü
end-of-inline-data
file testfile test-cp437-fc.zip test-cp437-fc-utf-8-filename.zip
39 changes: 37 additions & 2 deletions regress/ziptool_regress.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ source_type_t source_type = SOURCE_TYPE_NONE;
zip_uint64_t fragment_size = 0;
zip_file_t *z_files[16];
unsigned int z_files_count;
int commands_from_stdin = 0;

static int add_nul(char *argv[]);
static int cancel(char *argv[]);
Expand All @@ -24,14 +25,17 @@ static int unchange_one(char *argv[]);
static int unchange_all(char *argv[]);
static int zin_close(char *argv[]);

#define OPTIONS_REGRESS "F:Hmx"
#define OPTIONS_REGRESS "F:Himx"

#define USAGE_REGRESS " [-Hmx] [-F fragment-size]"
#define USAGE_REGRESS " [-Himx] [-F fragment-size]"

#define GETOPT_REGRESS \
case 'H': \
source_type = SOURCE_TYPE_HOLE; \
break; \
case 'i': \
commands_from_stdin = 1; \
break; \
case 'm': \
source_type = SOURCE_TYPE_IN_MEMORY; \
break; \
Expand Down Expand Up @@ -69,12 +73,43 @@ static int zin_close(char *argv[]);

/* clang-format on */

#define MAX_STDIN_ARGC 128
#define MAX_STDIN_LENGTH 8192

char* stdin_argv[MAX_STDIN_ARGC];
static char stdin_line[MAX_STDIN_LENGTH];

int get_stdin_commands(void);

#define REGRESS_PREPARE_ARGS \
if (commands_from_stdin) { \
argc = get_stdin_commands(); \
arg = 0; \
argv = stdin_argv; \
}

zip_t *ziptool_open(const char *archive, int flags, zip_error_t *error, zip_uint64_t offset, zip_uint64_t len);


#include "ziptool.c"

int get_stdin_commands(void) {
int argc = 0;
char *p, *word;
fgets(stdin_line, sizeof(stdin_line), stdin);
p = stdin_line;
while ((word = strsep(&p, " \n")) != NULL) {
if (word[0] == '\0') {
continue;
}
stdin_argv[argc] = word;
argc++;
if (argc >= MAX_STDIN_ARGC) {
break;
}
}
return argc;
}

zip_source_t *memory_src = NULL;

Expand Down
4 changes: 4 additions & 0 deletions src/ziptool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@ main(int argc, char *argv[]) {
}
zip_error_fini(&error);

#ifdef REGRESS_PREPARE_ARGS
REGRESS_PREPARE_ARGS
#endif

err = 0;
while (arg < argc) {
int ret;
Expand Down

0 comments on commit 4bfca9d

Please sign in to comment.