1 #pragma once 2 3 #include <float.h> 4 #include <inttypes.h> 5 #include <math.h> 6 7 #include "common/common.h" 8 9 struct MPContext; 10 11 bool run_tests(struct MPContext *mpctx); 12 13 struct test_ctx { 14 struct mpv_global *global; 15 struct mp_log *log; 16 17 // Path for ref files, without trailing "/". 18 const char *ref_path; 19 20 // Path for result files, without trailing "/". 21 const char *out_path; 22 }; 23 24 struct unittest { 25 // This is used to select the test on command line with --unittest=<name>. 26 const char *name; 27 28 // Cannot run without additional arguments supplied. 29 bool is_complex; 30 31 // Entrypoints. There are various for various purposes. Only 1 of them must 32 // be set. 33 34 // Entrypoint for tests which have a simple dependency on the mpv core. The 35 // core is sufficiently initialized at this point. 36 void (*run)(struct test_ctx *ctx); 37 }; 38 39 extern const struct unittest test_chmap; 40 extern const struct unittest test_gl_video; 41 extern const struct unittest test_img_format; 42 extern const struct unittest test_json; 43 extern const struct unittest test_linked_list; 44 extern const struct unittest test_repack_sws; 45 extern const struct unittest test_repack_zimg; 46 extern const struct unittest test_repack; 47 extern const struct unittest test_paths; 48 49 #define assert_true(x) assert(x) 50 #define assert_false(x) assert(!(x)) 51 #define assert_int_equal(a, b) \ 52 assert_int_equal_impl(__FILE__, __LINE__, (a), (b)) 53 #define assert_string_equal(a, b) \ 54 assert_string_equal_impl(__FILE__, __LINE__, (a), (b)) 55 #define assert_float_equal(a, b, tolerance) \ 56 assert_float_equal_impl(__FILE__, __LINE__, (a), (b), (tolerance)) 57 58 // Assert that memcmp(a,b,s)==0, or hexdump output on failure. 59 #define assert_memcmp(a, b, s) \ 60 assert_memcmp_impl(__FILE__, __LINE__, (a), (b), (s)) 61 62 // Require that the files "ref" and "new" are the same. The paths can be 63 // relative to ref_path and out_path respectively. If they're not the same, 64 // the output of "diff" is shown, the err message (if not NULL), and the test 65 // fails. 66 #define assert_text_files_equal(ctx, ref, new, err) \ 67 assert_text_files_equal_impl(__FILE__, __LINE__, (ctx), (ref), (new), (err)) 68 69 void assert_int_equal_impl(const char *file, int line, int64_t a, int64_t b); 70 void assert_string_equal_impl(const char *file, int line, 71 const char *a, const char *b); 72 void assert_float_equal_impl(const char *file, int line, 73 double a, double b, double tolerance); 74 void assert_text_files_equal_impl(const char *file, int line, 75 struct test_ctx *ctx, const char *ref, 76 const char *new, const char *err); 77 void assert_memcmp_impl(const char *file, int line, 78 const void *a, const void *b, size_t size); 79 80 // Open a new file in the out_path. Always succeeds. 81 FILE *test_open_out(struct test_ctx *ctx, const char *name); 82 83 // Sorted list of valid imgfmts. Call init_imgfmts_list() before use. 84 extern int imgfmts[]; 85 extern int num_imgfmts; 86 87 void init_imgfmts_list(void); 88