summaryrefslogtreecommitdiffstats
path: root/test/test_utils.h
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-02-25 21:50:08 -0600
committerDudemanguy <random342@airmail.cc>2023-03-02 15:45:27 +0000
commit9db818279aa63d071f2bca369235285314444dcd (patch)
tree9aafc5cf73e19ae8ea69751c060cab9766a6b9a4 /test/test_utils.h
parent61532421571f972f076b3700d7ae468c0a0438c0 (diff)
downloadmpv-9db818279aa63d071f2bca369235285314444dcd.tar.bz2
mpv-9db818279aa63d071f2bca369235285314444dcd.tar.xz
test: integrate unittests with meson
This reworks all of mpv's unit tests so they are compiled as separate executables (optional) and run via meson test. Because most of the tests are dependant on mpv's internals, existing compiled objects are leveraged to create static libs and used when necessary. As an aside, a function was moved into video/out/gpu/utils for sanity's sake (otherwise most of vo would have been needed). As a plus, meson multithreads running tests automatically and also the output no longer pollutes the source directory. There are tests that can break due to ffmpeg changes, so they require a specific minimum libavutil version to be built.
Diffstat (limited to 'test/test_utils.h')
-rw-r--r--test/test_utils.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/test_utils.h b/test/test_utils.h
new file mode 100644
index 0000000000..7dcb32cc3b
--- /dev/null
+++ b/test/test_utils.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#include <float.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "common/common.h"
+
+#define assert_true(x) assert(x)
+#define assert_false(x) assert(!(x))
+#define assert_int_equal(a, b) \
+ assert_int_equal_impl(__FILE__, __LINE__, (a), (b))
+#define assert_string_equal(a, b) \
+ assert_string_equal_impl(__FILE__, __LINE__, (a), (b))
+#define assert_float_equal(a, b, tolerance) \
+ assert_float_equal_impl(__FILE__, __LINE__, (a), (b), (tolerance))
+
+// Assert that memcmp(a,b,s)==0, or hexdump output on failure.
+#define assert_memcmp(a, b, s) \
+ assert_memcmp_impl(__FILE__, __LINE__, (a), (b), (s))
+
+// Require that the files "ref" and "new" are the same. The paths can be
+// relative to ref_path and out_path respectively. If they're not the same,
+// the output of "diff" is shown, the err message (if not NULL), and the test
+// fails.
+#define assert_text_files_equal(refdir, outdir, name, err) \
+ assert_text_files_equal_impl(__FILE__, __LINE__, (refdir), (outdir), (name), (name), (err))
+
+void assert_int_equal_impl(const char *file, int line, int64_t a, int64_t b);
+void assert_string_equal_impl(const char *file, int line,
+ const char *a, const char *b);
+void assert_float_equal_impl(const char *file, int line,
+ double a, double b, double tolerance);
+void assert_text_files_equal_impl(const char *file, int line,
+ const char *refdir, const char *outdir,
+ const char *ref, const char *new,
+ const char *err);
+void assert_memcmp_impl(const char *file, int line,
+ const void *a, const void *b, size_t size);
+
+// Open a new file in the build dir path. Always succeeds.
+FILE *test_open_out(const char *outdir, const char *name);
+
+/* Stubs */
+
+// Files commonly import common/msg.h which requires these to be
+// defined. We don't actually need mpv's logging system here so
+// just define these as stubs that do nothing.
+struct mp_log;
+void mp_msg(struct mp_log *log, int lev, const char *format, ...)
+ PRINTF_ATTRIBUTE(3, 4);
+int mp_msg_find_level(const char *s);
+int mp_msg_level(struct mp_log *log);
+void mp_write_console_ansi(void);
+
+// Windows additionally requires timer related code so it will actually
+// import the real versions of these functions and use them. On other
+// platforms, these can just be stubs for simplicity.
+#ifndef WIN32_TESTS
+void mp_add_timeout(void);
+void mp_rel_time_to_timespec(void);
+void mp_time_us(void);
+void mp_time_us_to_timespec(void);
+#endif