diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/chmap.c | 14 | ||||
-rw-r--r-- | test/libmpv_encode.c | 49 | ||||
-rw-r--r-- | test/libmpv_test.c | 4 | ||||
-rw-r--r-- | test/meson.build | 20 | ||||
-rw-r--r-- | test/paths.c | 4 | ||||
-rw-r--r-- | test/test_utils.c | 66 |
6 files changed, 92 insertions, 65 deletions
diff --git a/test/chmap.c b/test/chmap.c index 48af822e72..d6b69d233f 100644 --- a/test/chmap.c +++ b/test/chmap.c @@ -1,11 +1,9 @@ -#include "audio/chmap.h" -#include "audio/chmap_sel.h" #include "config.h" -#include "test_utils.h" -#if HAVE_AV_CHANNEL_LAYOUT +#include "audio/chmap.h" #include "audio/chmap_avchannel.h" -#endif +#include "audio/chmap_sel.h" +#include "test_utils.h" #define LAYOUTS(...) (char*[]){__VA_ARGS__, NULL} @@ -34,7 +32,6 @@ static void test_sel(const char *input, const char *expected_selection, mp_chmap_to_str(&expected_map)); } -#if HAVE_AV_CHANNEL_LAYOUT static bool layout_matches(const AVChannelLayout *av_layout, const struct mp_chmap *mp_layout, bool require_default_unspec) @@ -151,8 +148,6 @@ static void test_av_channel_layout_to_mp_chmap(void) assert_false(anything_failed); } -#endif - int main(void) { @@ -210,9 +205,8 @@ int main(void) assert_int_equal(mp_chmap_diffn(&a, &b), 0); assert_int_equal(mp_chmap_diffn(&b, &a), 3); -#if HAVE_AV_CHANNEL_LAYOUT test_av_channel_layout_to_mp_chmap(); test_mp_chmap_to_av_channel_layout(); -#endif + return 0; } diff --git a/test/libmpv_encode.c b/test/libmpv_encode.c index 183cd768f7..51a28bbebe 100644 --- a/test/libmpv_encode.c +++ b/test/libmpv_encode.c @@ -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,24 +87,23 @@ 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"); } -int mp_mkostemps(char *template, int suffixlen, int flags); - int main(int argc, char *argv[]) { atexit(exit_cleanup); @@ -113,23 +112,28 @@ 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"; + +#ifdef _WIN32 + out_path = _mktemp(path); + if (!out_path || !*out_path) + fail("tmpfile failed\n"); +#else + int fd = mkstemp(path); + if (fd == -1) + fail("tmpfile failed\n"); + out_path = path; +#endif + 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")); + check_api_error(mpv_set_option_string(ctx, "terminal", "yes")); + check_api_error(mpv_set_option_string(ctx, "msg-level", "all=v")); if (mpv_initialize(ctx) != 0) return 1; - check_api_error(mpv_set_option_string(ctx, "terminal", "yes")); - check_api_error(mpv_set_option_string(ctx, "msg-level", "all=v")); check_api_error(mpv_set_option_string(ctx, "idle", "once")); const char *cmd[] = {"loadfile", "av://lavfi:testsrc", NULL}; @@ -139,8 +143,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; } diff --git a/test/libmpv_test.c b/test/libmpv_test.c index e4356e8537..2c72c8c9a9 100644 --- a/test/libmpv_test.c +++ b/test/libmpv_test.c @@ -71,10 +71,10 @@ static mpv_event *wrap_wait_event(void) mpv_event *ev = mpv_wait_event(ctx, 1); if (ev->event_id == MPV_EVENT_NONE) { - continue; + continue; } else if (ev->event_id == MPV_EVENT_LOG_MESSAGE) { mpv_event_log_message *msg = (mpv_event_log_message*)ev->data; - printf("[%s:%s] %s", msg->prefix, msg->level, msg->text); + printf("[%s:%s] %s", msg->prefix, msg->level, msg->text); if (msg->log_level <= MPV_LOG_LEVEL_ERROR) fail("error was logged"); } else { diff --git a/test/meson.build b/test/meson.build index 1088aa544c..2d27169422 100644 --- a/test/meson.build +++ b/test/meson.build @@ -4,10 +4,8 @@ outdir = join_paths(build_root, 'test', 'out') refdir = '' # Convenient testing libraries. An adhoc collection of -# mpv objects that test_utils.c needs. Paths and subprocesses -# are required in order to run a diff command when comparing -# different files. Stuff will probably break if core things are -# carelessly moved around. +# mpv objects that test_utils.c needs. Stuff will probably +# break if core things are carelessly moved around. test_utils_args = [] test_utils_files = [ 'audio/chmap.c', @@ -15,7 +13,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', @@ -25,13 +22,9 @@ test_utils_files = [ 'options/m_config_core.c', 'options/m_config_frontend.c', 'options/m_option.c', - 'options/path.c', 'osdep/io.c', - 'osdep/subprocess.c', 'osdep/timer.c', timer_source, - path_source, - subprocess_source, 'ta/ta.c', 'ta/ta_talloc.c', 'ta/ta_utils.c' @@ -71,7 +64,6 @@ img_utils_files = [ 'video/fmt-conversion.c', 'video/img_format.c', 'video/mp_image.c', - 'video/out/placebo/utils.c', 'video/sws_utils.c' ] if features['zimg'] @@ -84,11 +76,9 @@ img_utils = static_library('img-utils', 'img_utils.c', include_directories: incd # The actual tests. chmap_files = [ - 'audio/chmap_sel.c' + 'audio/chmap_avchannel.c', + 'audio/chmap_sel.c', ] -if features['av-channel-layout'] - chmap_files += 'audio/chmap_avchannel.c' -endif chmap_objects = libmpv.extract_objects(chmap_files) chmap = executable('chmap', 'chmap.c', include_directories: incdir, dependencies: [libavutil], objects: chmap_objects, @@ -129,7 +119,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 diff --git a/test/paths.c b/test/paths.c index 13b3b26779..0e02f19d52 100644 --- a/test/paths.c +++ b/test/paths.c @@ -85,6 +85,10 @@ int main(void) TEST_NORMALIZE("/foo", "/foo"); #endif +#if defined(_WIN32) && (!defined(HAVE_PATHCCH) || !HAVE_PATHCCH) + return 0; +#endif + void *ctx = talloc_new(NULL); bstr dst = bstr0(mp_getcwd(ctx)); bstr_xappend(ctx, &dst, bstr0("/foo")); diff --git a/test/test_utils.c b/test/test_utils.c index 94fd2e6bb0..22b53b5e32 100644 --- a/test/test_utils.c +++ b/test/test_utils.c @@ -60,23 +60,55 @@ void assert_text_files_equal_impl(const char *file, int line, const char *ref, const char *new, const char *err) { - char *path_ref = mp_tprintf(4096, "%s/%s", refdir, ref); - char *path_new = mp_tprintf(4096, "%s/%s", outdir, new); - - struct mp_subprocess_opts opts = { - .exe = "diff", - .args = (char*[]){"diff", "-u", "--", path_ref, path_new, 0}, - .fds = { {0, .src_fd = 0}, {1, .src_fd = 1}, {2, .src_fd = 2} }, - .num_fds = 3, - }; - - struct mp_subprocess_result res; - mp_subprocess2(&opts, &res); - - if (res.error || res.exit_status) { - if (res.error) - printf("Note: %s\n", mp_subprocess_err_str(res.error)); - printf("Giving up.\n"); + char path_ref[4096]; + char path_new[4096]; + + snprintf(path_ref, sizeof(path_ref), "%s/%s", refdir, ref); + snprintf(path_new, sizeof(path_new), "%s/%s", outdir, new); + + bool ok = false; + FILE *fref = fopen(path_ref, "r"); + FILE *fnew = fopen(path_new, "r"); + + if (!fref || !fnew) { + printf("Error: Could not open files %s or %s\n", path_ref, path_new); + goto done; + } + + char ref_line[4096]; + char new_line[4096]; + int line_num = 0; + + while (fgets(ref_line, sizeof(ref_line), fref)) + { + line_num++; + + if (!fgets(new_line, sizeof(new_line), fnew)) { + printf("Extra line %d in reference file: %s", line_num, ref_line); + goto done; + } + + if (strcmp(ref_line, new_line)) { + printf("Difference found at line %d:\n", line_num); + printf("Reference: %s", ref_line); + printf("New file: %s", new_line); + goto done; + } + } + + if (fgets(new_line, sizeof(new_line), fnew)) { + printf("Extra line %d in new file: %s", line_num, new_line); + goto done; + } + + ok = true; + +done: + if (fref) + fclose(fref); + if (fnew) + fclose(fnew); + if (!ok) { fflush(stdout); abort(); } |