test/libmpv: inline some test-specific helpers in libmpv_common
These functions could be useful for any libmpv test and in fact check_string was already duplicated in a couple of places. Inline them in libmpv_common.
This commit is contained in:
1 parent
b5c629fd12
commit
cc7f9e3ce8
5 files changed
+53
-75
No files matched your search
+49
-14
@@ -24,20 +24,7 @@
|
||||
|
||||
#include <mpv/client.h>
|
||||
|
||||
// Stolen from osdep/compiler.h
|
||||
#ifdef __GNUC__
|
||||
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format(printf, a1, a2)))
|
||||
#define MP_NORETURN __attribute__((noreturn))
|
||||
#else
|
||||
#define PRINTF_ATTRIBUTE(a1, a2)
|
||||
#define MP_NORETURN
|
||||
#endif
|
||||
|
||||
// Broken crap with __USE_MINGW_ANSI_STDIO
|
||||
#if defined(__MINGW32__) && defined(__GNUC__) && !defined(__clang__)
|
||||
#undef PRINTF_ATTRIBUTE
|
||||
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (gnu_printf, a1, a2)))
|
||||
#endif
|
||||
#include "osdep/compiler.h"
|
||||
|
||||
// Global handle.
|
||||
static mpv_handle *ctx;
|
||||
@@ -84,6 +71,39 @@ static inline void check_api_error(int status)
|
||||
fail("mpv API error: %s\n", mpv_error_string(status));
|
||||
}
|
||||
|
||||
MP_UNUSED static void check_double(const char *property, double expect)
|
||||
{
|
||||
double result_double;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_DOUBLE, &result_double));
|
||||
if (expect != result_double)
|
||||
fail("Double: expected '%f' but got '%f'!\n", expect, result_double);
|
||||
}
|
||||
|
||||
MP_UNUSED static void check_flag(const char *property, int expect)
|
||||
{
|
||||
int result_flag;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_FLAG, &result_flag));
|
||||
if (expect != result_flag)
|
||||
fail("Flag: expected '%d' but got '%d'!\n", expect, result_flag);
|
||||
}
|
||||
|
||||
MP_UNUSED static void check_int(const char *property, int64_t expect)
|
||||
{
|
||||
int64_t result_int;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_INT64, &result_int));
|
||||
if (expect != result_int)
|
||||
fail("Int: expected '%" PRId64 "' but got '%" PRId64 "'!\n", expect, result_int);
|
||||
}
|
||||
|
||||
MP_UNUSED static inline void check_string(const char *property, const char *expect)
|
||||
{
|
||||
char *result_string;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_STRING, &result_string));
|
||||
if (strcmp(expect, result_string) != 0)
|
||||
fail("String: expected '%s' but got '%s'!\n", expect, result_string);
|
||||
mpv_free(result_string);
|
||||
}
|
||||
|
||||
static inline void initialize(void)
|
||||
{
|
||||
check_api_error(mpv_set_option_string(ctx, "vo", "null"));
|
||||
@@ -91,3 +111,18 @@ static inline void initialize(void)
|
||||
check_api_error(mpv_request_log_messages(ctx, "debug"));
|
||||
check_api_error(mpv_initialize(ctx));
|
||||
}
|
||||
|
||||
static inline void reload_file(const char *path)
|
||||
{
|
||||
const char *cmd[] = {"loadfile", path, NULL};
|
||||
check_api_error(mpv_command(ctx, cmd));
|
||||
bool loaded = false;
|
||||
while (!loaded) {
|
||||
mpv_event *event = wrap_wait_event();
|
||||
switch (event->event_id) {
|
||||
case MPV_EVENT_FILE_LOADED:
|
||||
loaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,39 +23,6 @@ static int flag = 1;
|
||||
static int64_t int_ = 20;
|
||||
static double double_ = 1.5;
|
||||
|
||||
static void check_double(const char *property, double expect)
|
||||
{
|
||||
double result_double;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_DOUBLE, &result_double));
|
||||
if (expect != result_double)
|
||||
fail("Double: expected '%f' but got '%f'!\n", expect, result_double);
|
||||
}
|
||||
|
||||
static void check_flag(const char *property, int expect)
|
||||
{
|
||||
int result_flag;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_FLAG, &result_flag));
|
||||
if (expect != result_flag)
|
||||
fail("Flag: expected '%d' but got '%d'!\n", expect, result_flag);
|
||||
}
|
||||
|
||||
static void check_int(const char *property, int64_t expect)
|
||||
{
|
||||
int64_t result_int;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_INT64, &result_int));
|
||||
if (expect != result_int)
|
||||
fail("Int: expected '%" PRId64 "' but got '%" PRId64 "'!\n", expect, result_int);
|
||||
}
|
||||
|
||||
static void check_string(const char *property, const char *expect)
|
||||
{
|
||||
char *result_string;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_STRING, &result_string));
|
||||
if (strcmp(expect, result_string) != 0)
|
||||
fail("String: expected '%s' but got '%s'!\n", expect, result_string);
|
||||
mpv_free(result_string);
|
||||
}
|
||||
|
||||
static void check_results(const char *properties[], enum mpv_format formats[])
|
||||
{
|
||||
for (int i = 0; properties[i]; i++) {
|
||||
|
||||
@@ -94,30 +94,6 @@ static bool have_english_locale(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void check_string(const char *property, const char *expect)
|
||||
{
|
||||
char *result_string;
|
||||
check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_STRING, &result_string));
|
||||
if (strcmp(expect, result_string) != 0)
|
||||
fail("String: expected '%s' but got '%s'!\n", expect, result_string);
|
||||
mpv_free(result_string);
|
||||
}
|
||||
|
||||
static void reload_file(const char *path)
|
||||
{
|
||||
const char *cmd[] = {"loadfile", path, NULL};
|
||||
check_api_error(mpv_command(ctx, cmd));
|
||||
bool loaded = false;
|
||||
while (!loaded) {
|
||||
mpv_event *event = wrap_wait_event();
|
||||
switch (event->event_id) {
|
||||
case MPV_EVENT_FILE_LOADED:
|
||||
loaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_track_selection(char *file, char *path)
|
||||
{
|
||||
int ret = access(path, F_OK);
|
||||
|
||||
+3
-3
@@ -119,15 +119,15 @@ if get_option('libmpv')
|
||||
file = join_paths(source_root, 'etc', 'mpv-icon-8bit-16x16.png')
|
||||
|
||||
exe = executable('libmpv-test-file-loading', 'libmpv_test_file_loading.c',
|
||||
dependencies: libmpv_dep)
|
||||
include_directories: incdir, dependencies: libmpv_dep)
|
||||
test('libmpv-test-file-loading', exe, args: file, suite: 'libmpv')
|
||||
|
||||
exe = executable('libmpv-test-lavfi-complex', 'libmpv_test_lavfi_complex.c',
|
||||
dependencies: libmpv_dep)
|
||||
include_directories: incdir, dependencies: libmpv_dep)
|
||||
test('libmpv-test-lavfi-complex', exe, args: file, suite: 'libmpv')
|
||||
|
||||
exe = executable('libmpv-test-options', 'libmpv_test_options.c',
|
||||
dependencies: libmpv_dep)
|
||||
include_directories: incdir, dependencies: libmpv_dep)
|
||||
test('libmpv-test-options', exe, suite: 'libmpv')
|
||||
|
||||
# Old versions of ffmpeg are bugged when setting forced tracks and older
|
||||
|
||||
@@ -68,7 +68,7 @@ foreach name, cmd: samples
|
||||
env = name == 'locale.mkv' ? 'LANG=C' : []
|
||||
testname = 'libmpv-test-' + name
|
||||
exe = executable(testname, '../libmpv_test_track_selection.c',
|
||||
dependencies: libmpv_dep)
|
||||
include_directories: incdir, dependencies: libmpv_dep)
|
||||
test(testname, exe, args: [name, target.full_path()],
|
||||
depends: target, env: env, suite: 'libmpv')
|
||||
endforeach
|
||||
Reference in new issue
Block a user