mirror of
https://github.com/mpv-player/mpv
synced 2024-12-20 05:42:19 +00:00
fb56896319
Until now, each .c file in test/ was built as separate, self-contained binary. Each binary could be run to execute the tests it contained. Change this and make them part of the normal mpv binary. Now the tests have to be invoked via the --unittest option. Do this for two reasons: - Tests now run within a "properly" initialized mpv instance, so all services are available. - Possibly simplifying the situation for future build systems. The first point is the main motivation. The mpv code is entangled with mp_log and the option system. It feels like a bad idea to duplicate some of the initialization of this just so you can call code using them. I'm also getting rid of cmocka. There wouldn't be any problem to keep it (it's a perfectly sane set of helpers), but NIH calls. I would have had to aggregate all tests into a CMUnitTest list, and I don't see how I'd get different types of entry points easily. Probably easily solvable, but since we made only pretty basic use of this library, NIH-ing this is actually easier (I needed a list of tests with custom metadata anyway, so all what was left was reimplement the assert_* helpers). Unit tests now don't output anything, and if they fail, they'll simply crash and leave a message that typically requires inspecting the test code to figure out what went wrong (and probably editing the test code to get more information). I even merged the various test functions into single ones. Sucks, but here you go. chmap_sel.c is merged into chmap.c, because I didn't see the point of this being separate. json.c drops the print_message() to go along with the new silent-by-default idea, also there's a memory leak fix unrelated to the rest of this commit. The new code is enabled with --enable-tests (--enable-test goes away). Due to waf's option parser, --enable-test still works, because it's a unique prefix to --enable-tests.
25 lines
808 B
C
25 lines
808 B
C
#ifndef MP_TESTS_H
|
|
#define MP_TESTS_H
|
|
|
|
#include <math.h>
|
|
#include <float.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))
|
|
|
|
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);
|
|
|
|
#endif
|