summaryrefslogtreecommitdiffstats
path: root/test/tests.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-08 17:20:57 +0100
committerwm4 <wm4@nowhere>2019-11-08 21:22:49 +0100
commit1edb3d061bd88e86cba05e9383d6decb4a13950b (patch)
tree18b5438f040464f841c5e0b9ae0a877175759c75 /test/tests.h
parenta6c8b4efa59628a755755c510aa9ee6db2728fb9 (diff)
downloadmpv-1edb3d061bd88e86cba05e9383d6decb4a13950b.tar.bz2
mpv-1edb3d061bd88e86cba05e9383d6decb4a13950b.tar.xz
test: add dumping of img_format metadata
This is fragile enough that it warrants getting "monitored". This takes the commented test program code from img_format.c, makes it output to a text file, and then compares it to a "ref" file stored in git. Originally, I wanted to do the comparison etc. in a shell or Python script. But why not do it in C. So mpv calls /usr/bin/diff as a sub-process now. This test will start producing different output if FFmpeg adds new pixel formats or pixel format flags, or if mpv adds new IMGFMT (either aliases to FFmpeg formats or own formats). That is unavoidable, and requires manual inspection of the results, and then updating the ref file. The changes in the non-test code are to guarantee that the format ID conversion functions only translate between valid IDs.
Diffstat (limited to 'test/tests.h')
-rw-r--r--test/tests.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/test/tests.h b/test/tests.h
index c19f90f75d..0a589d984d 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -13,6 +13,12 @@ bool run_tests(struct MPContext *mpctx);
struct test_ctx {
struct mpv_global *global;
struct mp_log *log;
+
+ // Path for ref files, without trailing "/".
+ const char *ref_path;
+
+ // Path for result files, without trailing "/".
+ const char *out_path;
};
struct unittest {
@@ -32,6 +38,7 @@ struct unittest {
extern const struct unittest test_chmap;
extern const struct unittest test_gl_video;
+extern const struct unittest test_img_format;
extern const struct unittest test_json;
extern const struct unittest test_linked_list;
@@ -44,8 +51,21 @@ extern const struct unittest test_linked_list;
#define assert_float_equal(a, b, tolerance) \
assert_float_equal_impl(__FILE__, __LINE__, (a), (b), (tolerance))
+// 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(ctx, ref, new, err) \
+ assert_text_files_equal_impl(__FILE__, __LINE__, (ctx), (ref), (new), (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);
+ double a, double b, double tolerance);
+void assert_text_files_equal_impl(const char *file, int line,
+ struct test_ctx *ctx, const char *ref,
+ const char *new, const char *err);
+
+// Open a new file in the out_path. Always succeeds.
+FILE *test_open_out(struct test_ctx *ctx, const char *name);