1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 08:37:59 +00:00

test/libmpv_test_track_selection: eliminate reloading redundancy

Loading the file and then waiting it for it to be loaded again doesn't
need to be two separate functions. Combine it into a simple
"reload_file" so it's more readable.
This commit is contained in:
Dudemanguy 2025-02-13 13:04:42 -06:00
parent dba53e1b5b
commit 9e38208951

View File

@ -27,8 +27,10 @@ static void check_string(const char *property, const char *expect)
mpv_free(result_string);
}
static void wait_for_file_load(void)
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();
@ -46,63 +48,52 @@ static void test_track_selection(char *file, char *path)
if (ret)
fail("Test file, '%s', was not found!\n", path);
const char *cmd[] = {"loadfile", path, NULL};
if (strcmp(file, "eng_default.mkv") == 0) {
// --no-config
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/sub/selected", "yes");
// --subs-falback=no
check_api_error(mpv_set_property_string(ctx, "subs-fallback", "no"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("track-list/2/selected", "no");
} else if (strcmp(file, "eng_default_forced.mkv") == 0) {
// --subs-fallback-forced=no
check_api_error(mpv_set_property_string(ctx, "subs-fallback-forced", "no"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/sub/selected", "yes");
} else if (strcmp(file, "eng_forced_matching_audio.mkv") == 0) {
// select forced track
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/sub/selected", "yes");
} else if (strcmp(file, "eng_forced_no_matching_audio.mkv") == 0) {
// forced track should not be selected
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("track-list/2/selected", "no");
} else if (strcmp(file, "eng_forced_always_audio.mkv") == 0) {
// forced track should be selected anyway despite no matching audio
check_api_error(mpv_set_property_string(ctx, "subs-fallback-forced", "always"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/sub/selected", "yes");
} else if (strcmp(file, "eng_no_default.mkv") == 0) {
// track should not be selected
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("track-list/2/selected", "no");
// --subs-fallback=yes
check_api_error(mpv_set_property_string(ctx, "subs-fallback", "yes"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/sub/selected", "yes");
} else if (strcmp(file, "multilang.mkv") == 0) {
// --alang=jpn should select forced jpn subs
check_api_error(mpv_set_property_string(ctx, "alang", "jpn"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "jpn");
check_string("current-tracks/sub/lang", "jpn");
// --alang=pol should select default, non-forced ger subs
check_api_error(mpv_set_property_string(ctx, "alang", "pol"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "pol");
check_string("current-tracks/sub/lang", "ger");
@ -110,8 +101,7 @@ static void test_track_selection(char *file, char *path)
check_api_error(mpv_set_property_string(ctx, "alang", "eng"));
check_api_error(mpv_set_property_string(ctx, "slang", "eng"));
check_api_error(mpv_set_property_string(ctx, "subs-with-matching-audio", "no"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "eng");
check_string("track-list/5/selected", "no");
check_string("track-list/6/selected", "no");
@ -120,32 +110,28 @@ static void test_track_selection(char *file, char *path)
// --subs-with-matching-audio=forced checks
check_api_error(mpv_set_property_string(ctx, "subs-with-matching-audio", "forced"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "eng");
check_string("current-tracks/sub/lang", "eng");
// forced jpn subs should be selected
check_api_error(mpv_set_property_string(ctx, "alang", "jpn"));
check_api_error(mpv_set_property_string(ctx, "slang", "jpn"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "jpn");
check_string("current-tracks/sub/lang", "jpn");
// default+forced eng subs should be selected
check_api_error(mpv_set_property_string(ctx, "alang", "ger"));
check_api_error(mpv_set_property_string(ctx, "slang", "ger"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "ger");
check_string("current-tracks/sub/lang", "eng");
// eng audio and pol subs should be selected
check_api_error(mpv_set_property_string(ctx, "alang", "it"));
check_api_error(mpv_set_property_string(ctx, "slang", "pt,it,pol,ger"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "eng");
check_string("current-tracks/sub/lang", "pol");
@ -154,8 +140,7 @@ static void test_track_selection(char *file, char *path)
check_api_error(mpv_set_property_string(ctx, "slang", "jpn,pol"));
check_api_error(mpv_set_property_string(ctx, "subs-with-matching-audio", "yes"));
check_api_error(mpv_set_property_string(ctx, "subs-fallback-forced", "always"));
check_api_error(mpv_command(ctx, cmd));
wait_for_file_load();
reload_file(path);
check_string("current-tracks/audio/lang", "ger");
check_string("current-tracks/sub/lang", "jpn");
}