mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00: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:
@@ -53,7 +53,7 @@ static void exit_cleanup(void)
|
|||||||
{
|
{
|
||||||
if (ctx)
|
if (ctx)
|
||||||
mpv_destroy(ctx);
|
mpv_destroy(ctx);
|
||||||
if (out_path)
|
if (out_path && *out_path)
|
||||||
unlink(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)
|
if (size < 100)
|
||||||
fail("did not encode anything");
|
fail("did not encode anything\n");
|
||||||
|
|
||||||
char magic[4] = {0};
|
char magic[4] = {0};
|
||||||
lseek(fd, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
read(fd, magic, sizeof(magic));
|
fread(magic, sizeof(magic), 1, fp);
|
||||||
static const char ebml_magic[] = {26, 69, 223, 163};
|
static const char ebml_magic[] = {26, 69, 223, 163};
|
||||||
if (memcmp(magic, ebml_magic, 4) != 0)
|
if (memcmp(magic, ebml_magic, 4) != 0)
|
||||||
fail("output was not Matroska");
|
fail("output was not Matroska\n");
|
||||||
|
|
||||||
puts("output file ok");
|
puts("output file ok");
|
||||||
}
|
}
|
||||||
@@ -113,14 +114,11 @@ int main(int argc, char *argv[])
|
|||||||
if (!ctx)
|
if (!ctx)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int fd;
|
static char path[] = "./testout.XXXXXX";
|
||||||
{
|
out_path = mktemp(path);
|
||||||
char path[] = "./testout.XXXXXX";
|
if (!out_path || !*out_path)
|
||||||
fd = mp_mkostemps(path, 0, 0);
|
fail("tmpfile failed\n");
|
||||||
if (fd == -1)
|
|
||||||
fail("mkstemp failed");
|
|
||||||
out_path = strdup(path);
|
|
||||||
}
|
|
||||||
check_api_error(mpv_set_option_string(ctx, "o", out_path));
|
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, "of", "matroska"));
|
||||||
check_api_error(mpv_set_option_string(ctx, "end", "1.5"));
|
check_api_error(mpv_set_option_string(ctx, "end", "1.5"));
|
||||||
@@ -139,8 +137,11 @@ int main(int argc, char *argv[])
|
|||||||
mpv_destroy(ctx);
|
mpv_destroy(ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
|
|
||||||
check_output(fd);
|
FILE *output = fopen(out_path, "rb");
|
||||||
close(fd);
|
if (!output)
|
||||||
|
fail("output file doesn't exist\n");
|
||||||
|
check_output(output);
|
||||||
|
fclose(output);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ test_utils_files = [
|
|||||||
'common/common.c',
|
'common/common.c',
|
||||||
'misc/bstr.c',
|
'misc/bstr.c',
|
||||||
'misc/dispatch.c',
|
'misc/dispatch.c',
|
||||||
'misc/io_utils.c',
|
|
||||||
'misc/json.c',
|
'misc/json.c',
|
||||||
'misc/language.c',
|
'misc/language.c',
|
||||||
'misc/node.c',
|
'misc/node.c',
|
||||||
@@ -129,7 +128,7 @@ if get_option('libmpv')
|
|||||||
test('libmpv', exe, args: file, timeout: 60, should_fail: not features['lua'])
|
test('libmpv', exe, args: file, timeout: 60, should_fail: not features['lua'])
|
||||||
|
|
||||||
exe = executable('libmpv-encode', 'libmpv_encode.c',
|
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)
|
test('libmpv-encode', exe, timeout: 30)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user