History

test/libmpv_encode: don't use mpv internals for test

mktemp is good enough for this test purposes and also tests if libmpv is able to create a file that doesn't exist.

Kacper Michajłow committed 2 years ago

Commit 8a990191 parent d70a0b42 files · +19 −19Browse files

Unified · Split

2 files
  1. test/libmpv_encode.c +18 −17
  2. test/meson.build +1 −2
test/libmpv_encode.c+18−17
@@ -53,7 +53,7 @@ static void exit_cleanup(void) · 52 unmodified lines
5353 {
5454 if (ctx)
5555 mpv_destroy(ctx);
56− if (out_path)
56+ if (out_path && *out_path)
5757 unlink(out_path);
5858 }
5959
@@ -87,18 +87,19 @@ static void wait_done(void) · 27 unmodified lines
8787 }
8888 }
8989
90−static void check_output(int fd)
90+static void check_output(FILE *fp)
9191 {
92− off_t size = lseek(fd, 0, SEEK_END);
92+ fseek(fp, 0, SEEK_END);
93+ long size = ftell(fp);
9394 if (size < 100)
94− fail("did not encode anything");
95+ fail("did not encode anything\n");
9596
9697 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);
99100 static const char ebml_magic[] = {26, 69, 223, 163};
100101 if (memcmp(magic, ebml_magic, 4) != 0)
101− fail("output was not Matroska");
102+ fail("output was not Matroska\n");
102103
103104 puts("output file ok");
104105 }
@@ -113,14 +114,11 @@ int main(int argc, char *argv[]) · 8 unmodified lines
113114 if (!ctx)
114115 return 1;
115116
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+
124122 check_api_error(mpv_set_option_string(ctx, "o", out_path));
125123 check_api_error(mpv_set_option_string(ctx, "of", "matroska"));
126124 check_api_error(mpv_set_option_string(ctx, "end", "1.5"));
@@ -139,8 +137,11 @@ int main(int argc, char *argv[]) · 12 unmodified lines
139137 mpv_destroy(ctx);
140138 ctx = NULL;
141139
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);
144145
145146 return 0;
146147 }
test/meson.build+1−2
@@ -15,7 +15,6 @@ test_utils_files = [ · 14 unmodified lines
1515 'common/common.c',
1616 'misc/bstr.c',
1717 'misc/dispatch.c',
18− 'misc/io_utils.c',
1918 'misc/json.c',
2019 'misc/language.c',
2120 'misc/node.c',
@@ -129,7 +128,7 @@ if get_option('libmpv') · 107 unmodified lines
129128 test('libmpv', exe, args: file, timeout: 60, should_fail: not features['lua'])
130129
131130 exe = executable('libmpv-encode', 'libmpv_encode.c',
132− include_directories: incdir, link_with: [libmpv, test_utils])
131+ include_directories: incdir, link_with: libmpv)
133132 test('libmpv-encode', exe, timeout: 30)
134133 endif
135134

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t