summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-08 14:21:40 +0100
committerwm4 <wm4@nowhere>2019-11-08 14:21:40 +0100
commit3ed9c1c9701098db17a2b791f9793e75a1947cc9 (patch)
tree4a1fb9145ab825c582e1e30fd819522d9aa0f93e
parent53b7a10f5453083390e65bdab5f1e642c37d89a2 (diff)
downloadmpv-3ed9c1c9701098db17a2b791f9793e75a1947cc9.tar.bz2
mpv-3ed9c1c9701098db17a2b791f9793e75a1947cc9.tar.xz
test: just always provide a context for all entrypoints
-rw-r--r--test/chmap.c4
-rw-r--r--test/gl_video.c4
-rw-r--r--test/index.c12
-rw-r--r--test/index.h15
-rw-r--r--test/json.c4
-rw-r--r--test/linked_list.c4
6 files changed, 24 insertions, 19 deletions
diff --git a/test/chmap.c b/test/chmap.c
index 6484698f4c..a489a7da61 100644
--- a/test/chmap.c
+++ b/test/chmap.c
@@ -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,
};
diff --git a/test/gl_video.c b/test/gl_video.c
index dd866c955c..eb2288d8b4 100644
--- a/test/gl_video.c
+++ b/test/gl_video.c
@@ -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,
};
diff --git a/test/index.c b/test/index.c
index 64f3f85344..c4ad10888f 100644
--- a/test/index.c
+++ b/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++;
}
}
diff --git a/test/index.h b/test/index.h
index 6060eb699f..1564fe311a 100644
--- a/test/index.h
+++ b/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;
diff --git a/test/json.c b/test/json.c
index e8499bee39..9997cdc892 100644
--- a/test/json.c
+++ b/test/json.c
@@ -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,
};
diff --git a/test/linked_list.c b/test/linked_list.c
index c679d8cc28..8daa854e9c 100644
--- a/test/linked_list.c
+++ b/test/linked_list.c
@@ -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,
};