mktemp is good enough for this test purposes and also tests if libmpv is able to create a file that doesn't exist.
Unified · Split
| @@ -53,7 +53,7 @@ static void exit_cleanup(void) · 52 unmodified lines | ||
| 53 | 53 | { |
| 54 | 54 | if (ctx) |
| 55 | 55 | mpv_destroy(ctx); |
| 56 | − if (out_path) | |
| 56 | + if (out_path && *out_path) | |
| 57 | 57 | unlink(out_path); |
| 58 | 58 | } |
| 59 | 59 | |
| @@ -87,18 +87,19 @@ static void wait_done(void) · 27 unmodified lines | ||
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | −static void check_output(int fd) | |
| 90 | +static void check_output(FILE *fp) | |
| 91 | 91 | { |
| 92 | − off_t size = lseek(fd, 0, SEEK_END); | |
| 92 | + fseek(fp, 0, SEEK_END); | |
| 93 | + long size = ftell(fp); | |
| 93 | 94 | if (size < 100) |
| 94 | − fail("did not encode anything"); | |
| 95 | + fail("did not encode anything\n"); | |
| 95 | 96 | |
| 96 | 97 | char magic[4] = {0}; |
| 97 | − lseek(fd, 0, SEEK_SET); | |
| 98 | − read(fd, magic, sizeof(magic)); | |
| 98 | + fseek(fp, 0, SEEK_SET); | |
| 99 | + fread(magic, sizeof(magic), 1, fp); | |
| 99 | 100 | static const char ebml_magic[] = {26, 69, 223, 163}; |
| 100 | 101 | if (memcmp(magic, ebml_magic, 4) != 0) |
| 101 | − fail("output was not Matroska"); | |
| 102 | + fail("output was not Matroska\n"); | |
| 102 | 103 | |
| 103 | 104 | puts("output file ok"); |
| 104 | 105 | } |
| @@ -113,14 +114,11 @@ int main(int argc, char *argv[]) · 8 unmodified lines | ||
| 113 | 114 | if (!ctx) |
| 114 | 115 | return 1; |
| 115 | 116 | |
| 116 | − int fd; | |
| 117 | − { | |
| 118 | − char path[] = "./testout.XXXXXX"; | |
| 119 | − fd = mp_mkostemps(path, 0, 0); | |
| 120 | − if (fd == -1) | |
| 121 | − fail("mkstemp failed"); | |
| 122 | − out_path = strdup(path); | |
| 123 | − } | |
| 117 | + static char path[] = "./testout.XXXXXX"; | |
| 118 | + out_path = mktemp(path); | |
| 119 | + if (!out_path || !*out_path) | |
| 120 | + fail("tmpfile failed\n"); | |
| 121 | + | |
| 124 | 122 | check_api_error(mpv_set_option_string(ctx, "o", out_path)); |
| 125 | 123 | check_api_error(mpv_set_option_string(ctx, "of", "matroska")); |
| 126 | 124 | check_api_error(mpv_set_option_string(ctx, "end", "1.5")); |
| @@ -139,8 +137,11 @@ int main(int argc, char *argv[]) · 12 unmodified lines | ||
| 139 | 137 | mpv_destroy(ctx); |
| 140 | 138 | ctx = NULL; |
| 141 | 139 | |
| 142 | − check_output(fd); | |
| 143 | − close(fd); | |
| 140 | + FILE *output = fopen(out_path, "rb"); | |
| 141 | + if (!output) | |
| 142 | + fail("output file doesn't exist\n"); | |
| 143 | + check_output(output); | |
| 144 | + fclose(output); | |
| 144 | 145 | |
| 145 | 146 | return 0; |
| 146 | 147 | } |
| @@ -15,7 +15,6 @@ test_utils_files = [ · 14 unmodified lines | ||
| 15 | 15 | 'common/common.c', |
| 16 | 16 | 'misc/bstr.c', |
| 17 | 17 | 'misc/dispatch.c', |
| 18 | − 'misc/io_utils.c', | |
| 19 | 18 | 'misc/json.c', |
| 20 | 19 | 'misc/language.c', |
| 21 | 20 | 'misc/node.c', |
| @@ -129,7 +128,7 @@ if get_option('libmpv') · 107 unmodified lines | ||
| 129 | 128 | test('libmpv', exe, args: file, timeout: 60, should_fail: not features['lua']) |
| 130 | 129 | |
| 131 | 130 | exe = executable('libmpv-encode', 'libmpv_encode.c', |
| 132 | − include_directories: incdir, link_with: [libmpv, test_utils]) | |
| 131 | + include_directories: incdir, link_with: libmpv) | |
| 133 | 132 | test('libmpv-encode', exe, timeout: 30) |
| 134 | 133 | endif |
| 135 | 134 | |