mirror of https://github.com/mpv-player/mpv
test: just always provide a context for all entrypoints
This commit is contained in:
parent
53b7a10f54
commit
3ed9c1c970
|
@ -30,7 +30,7 @@ static void test_sel(const char *input, const char *expected_selection,
|
|||
mp_chmap_to_str(&expected_map));
|
||||
}
|
||||
|
||||
static void run(void)
|
||||
static void run(struct test_ctx *ctx)
|
||||
{
|
||||
struct mp_chmap a;
|
||||
struct mp_chmap b;
|
||||
|
@ -89,5 +89,5 @@ static void run(void)
|
|||
|
||||
const struct unittest test_chmap = {
|
||||
.name = "chmap",
|
||||
.run_simple = run,
|
||||
.run = run,
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "test_helpers.h"
|
||||
#include "video/out/gpu/video.h"
|
||||
|
||||
static void run(void)
|
||||
static void run(struct test_ctx *ctx)
|
||||
{
|
||||
float x;
|
||||
|
||||
|
@ -26,5 +26,5 @@ static void run(void)
|
|||
|
||||
const struct unittest test_gl_video = {
|
||||
.name = "gl_video",
|
||||
.run_simple = run,
|
||||
.run = run,
|
||||
};
|
||||
|
|
12
test/index.c
12
test/index.c
|
@ -22,6 +22,11 @@ bool run_tests(struct MPContext *mpctx)
|
|||
return true;
|
||||
}
|
||||
|
||||
struct test_ctx ctx = {
|
||||
.global = mpctx->global,
|
||||
.log = mpctx->log,
|
||||
};
|
||||
|
||||
int num_run = 0;
|
||||
|
||||
for (int n = 0; unittests[n]; n++) {
|
||||
|
@ -29,18 +34,15 @@ bool run_tests(struct MPContext *mpctx)
|
|||
|
||||
// Exactly 1 entrypoint please.
|
||||
assert(MP_IS_POWER_OF_2(
|
||||
(t->run_simple ? (1 << 0) : 0) |
|
||||
(t->run ? (1 << 1) : 0)));
|
||||
|
||||
bool run = false;
|
||||
run |= strcmp(sel, "all-simple") == 0 && !!t->run_simple;
|
||||
run |= strcmp(sel, "all-simple") == 0 && !t->is_complex;
|
||||
run |= strcmp(sel, t->name);
|
||||
|
||||
if (run) {
|
||||
if (t->run_simple)
|
||||
t->run_simple();
|
||||
if (t->run)
|
||||
t->run(mpctx->global, mpctx->log);
|
||||
t->run(&ctx);
|
||||
num_run++;
|
||||
}
|
||||
}
|
||||
|
|
15
test/index.h
15
test/index.h
|
@ -2,25 +2,28 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct mpv_global;
|
||||
struct mp_log;
|
||||
struct MPContext;
|
||||
|
||||
bool run_tests(struct MPContext *mpctx);
|
||||
|
||||
struct test_ctx {
|
||||
struct mpv_global *global;
|
||||
struct mp_log *log;
|
||||
};
|
||||
|
||||
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 don't depend on the mpv core.
|
||||
void (*run_simple)(void);
|
||||
|
||||
// Entrypoint for tests which have a simple dependency on the mpv core. The
|
||||
// core is sufficiently initialized at this point.
|
||||
void (*run)(struct mpv_global *global, struct mp_log *log);
|
||||
void (*run)(struct test_ctx *ctx);
|
||||
};
|
||||
|
||||
extern const struct unittest test_chmap;
|
||||
|
|
|
@ -67,7 +67,7 @@ static const struct entry entries[] = {
|
|||
|
||||
#define MAX_DEPTH 10
|
||||
|
||||
static void run(void)
|
||||
static void run(struct test_ctx *ctx)
|
||||
{
|
||||
for (int n = 0; n < MP_ARRAY_SIZE(entries); n++) {
|
||||
const struct entry *e = &entries[n];
|
||||
|
@ -91,5 +91,5 @@ static void run(void)
|
|||
|
||||
const struct unittest test_json = {
|
||||
.name = "json",
|
||||
.run_simple = run,
|
||||
.run = run,
|
||||
};
|
||||
|
|
|
@ -56,7 +56,7 @@ static bool do_check_list(struct the_list *lst, int *c, int num_c)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void run(void)
|
||||
static void run(struct test_ctx *ctx)
|
||||
{
|
||||
struct the_list lst = {0};
|
||||
struct list_item e1 = {1};
|
||||
|
@ -161,5 +161,5 @@ static void run(void)
|
|||
|
||||
const struct unittest test_linked_list = {
|
||||
.name = "linked_list",
|
||||
.run_simple = run,
|
||||
.run = run,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue