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

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