0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-19 19:42:24 +02:00

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.
This commit is contained in:
Kacper Michajłow 2024-05-21 22:31:17 +02:00
parent d70a0b4494
commit 8a9901963d
2 changed files with 19 additions and 19 deletions

View File

@ -53,7 +53,7 @@ static void exit_cleanup(void)
{
if (ctx)
mpv_destroy(ctx);
if (out_path)
if (out_path && *out_path)
unlink(out_path);
}
@ -87,18 +87,19 @@ static void wait_done(void)
}
}
static void check_output(int fd)
static void check_output(FILE *fp)
{
off_t size = lseek(fd, 0, SEEK_END);
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
if (size < 100)
fail("did not encode anything");
fail("did not encode anything\n");
char magic[4] = {0};
lseek(fd, 0, SEEK_SET);
read(fd, magic, sizeof(magic));
fseek(fp, 0, SEEK_SET);
fread(magic, sizeof(magic), 1, fp);
static const char ebml_magic[] = {26, 69, 223, 163};
if (memcmp(magic, ebml_magic, 4) != 0)
fail("output was not Matroska");
fail("output was not Matroska\n");
puts("output file ok");
}
@ -113,14 +114,11 @@ int main(int argc, char *argv[])
if (!ctx)
return 1;
int fd;
{
char path[] = "./testout.XXXXXX";
fd = mp_mkostemps(path, 0, 0);
if (fd == -1)
fail("mkstemp failed");
out_path = strdup(path);
}
static char path[] = "./testout.XXXXXX";
out_path = mktemp(path);
if (!out_path || !*out_path)
fail("tmpfile failed\n");
check_api_error(mpv_set_option_string(ctx, "o", out_path));
check_api_error(mpv_set_option_string(ctx, "of", "matroska"));
check_api_error(mpv_set_option_string(ctx, "end", "1.5"));
@ -139,8 +137,11 @@ int main(int argc, char *argv[])
mpv_destroy(ctx);
ctx = NULL;
check_output(fd);
close(fd);
FILE *output = fopen(out_path, "rb");
if (!output)
fail("output file doesn't exist\n");
check_output(output);
fclose(output);
return 0;
}

View File

@ -15,7 +15,6 @@ test_utils_files = [
'common/common.c',
'misc/bstr.c',
'misc/dispatch.c',
'misc/io_utils.c',
'misc/json.c',
'misc/language.c',
'misc/node.c',
@ -129,7 +128,7 @@ if get_option('libmpv')
test('libmpv', exe, args: file, timeout: 60, should_fail: not features['lua'])
exe = executable('libmpv-encode', 'libmpv_encode.c',
include_directories: incdir, link_with: [libmpv, test_utils])
include_directories: incdir, link_with: libmpv)
test('libmpv-encode', exe, timeout: 30)
endif