mirror of
https://github.com/mpv-player/mpv
synced 2024-12-24 07:42:17 +00:00
94d853d3a3
This tests the RGB repacker code in zimg, which deserves to be tested because it's tricky and there will be more formats. scale_test.c contains some code that can be used to test any scaler. Or at least that would be great; currently it can only test repacking of some byte-aligned-component RGB formats. It should be called repack_test.c, but I'm too lazy to change the filename now. The idea is that libswscale is used to cross-check the conversions performed by the zimg wrapper. This is why it's "OK" that scale_test.c does libswscale calls. scale_sws.c is the equivalent to scale_zimg.c, and is of course worthless (because it tests libswscale by comparing the results with libswscale), but still might help with finding bugs in scale_test.c. This borrows a sorted list of image formats from test/img_format.c, for the same reason that file sorts them. There's a slight possibility that this can be used to test vo_gpu.c too some times in the future.
80 lines
2.7 KiB
C
80 lines
2.7 KiB
C
#pragma once
|
|
|
|
#include <float.h>
|
|
#include <inttypes.h>
|
|
#include <math.h>
|
|
|
|
#include "common/common.h"
|
|
|
|
struct MPContext;
|
|
|
|
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 {
|
|
// This is used to select the test on command line with --unittest=<name>.
|
|
const char *name;
|
|
|
|
// Cannot run without additional arguments supplied.
|
|
bool is_complex;
|
|
|
|
// Entrypoints. There are various for various purposes. Only 1 of them must
|
|
// be set.
|
|
|
|
// Entrypoint for tests which have a simple dependency on the mpv core. The
|
|
// core is sufficiently initialized at this point.
|
|
void (*run)(struct test_ctx *ctx);
|
|
};
|
|
|
|
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;
|
|
extern const struct unittest test_repack_sws;
|
|
extern const struct unittest test_repack_zimg;
|
|
|
|
#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))
|
|
|
|
// 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);
|
|
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);
|
|
|
|
// Sorted list of valid imgfmts. Call init_imgfmts_list() before use.
|
|
extern int imgfmts[];
|
|
extern int num_imgfmts;
|
|
|
|
void init_imgfmts_list(void);
|