summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/chmap.c140
-rw-r--r--test/format.c99
-rw-r--r--test/gl_video.c14
-rw-r--r--test/img_format.c129
-rw-r--r--test/img_utils.c63
-rw-r--r--test/img_utils.h24
-rw-r--r--test/input-gamepad.conf4
-rw-r--r--test/json.c15
-rw-r--r--test/libmpv_test.c271
-rw-r--r--test/linked_list.c10
-rw-r--r--test/meson.build153
-rw-r--r--test/paths.c11
-rw-r--r--test/ref/draw_bmp.txt249
-rw-r--r--test/ref/img_formats.txt2246
-rw-r--r--test/ref/repack.txt385
-rw-r--r--test/ref/repack_zimg.log4
-rw-r--r--test/ref/zimg_formats.txt249
-rw-r--r--test/repack.c534
-rw-r--r--test/scale_sws.c11
-rw-r--r--test/scale_test.c30
-rw-r--r--test/scale_test.h6
-rw-r--r--test/scale_zimg.c30
-rw-r--r--test/subtimes.js7
-rw-r--r--test/test_utils.c121
-rw-r--r--test/test_utils.h56
-rw-r--r--test/tests.c130
-rw-r--r--test/tests.h80
-rw-r--r--test/timer.c41
28 files changed, 4144 insertions, 968 deletions
diff --git a/test/chmap.c b/test/chmap.c
index 91b1cf797f..48af822e72 100644
--- a/test/chmap.c
+++ b/test/chmap.c
@@ -1,6 +1,11 @@
#include "audio/chmap.h"
#include "audio/chmap_sel.h"
-#include "tests.h"
+#include "config.h"
+#include "test_utils.h"
+
+#if HAVE_AV_CHANNEL_LAYOUT
+#include "audio/chmap_avchannel.h"
+#endif
#define LAYOUTS(...) (char*[]){__VA_ARGS__, NULL}
@@ -29,7 +34,127 @@ static void test_sel(const char *input, const char *expected_selection,
mp_chmap_to_str(&expected_map));
}
-static void run(struct test_ctx *ctx)
+#if HAVE_AV_CHANNEL_LAYOUT
+static bool layout_matches(const AVChannelLayout *av_layout,
+ const struct mp_chmap *mp_layout,
+ bool require_default_unspec)
+{
+ if (!mp_chmap_is_valid(mp_layout) ||
+ !av_channel_layout_check(av_layout) ||
+ av_layout->nb_channels != mp_layout->num ||
+ mp_layout->num > MP_NUM_CHANNELS)
+ return false;
+
+ switch (av_layout->order) {
+ case AV_CHANNEL_ORDER_UNSPEC:
+ {
+ if (!require_default_unspec)
+ return true;
+
+ // mp_chmap essentially does not have a concept of "unspecified"
+ // so we check if the mp layout matches the default layout for such
+ // channel count.
+ struct mp_chmap default_layout = { 0 };
+ mp_chmap_from_channels(&default_layout, mp_layout->num);
+ return mp_chmap_equals(mp_layout, &default_layout);
+ }
+ case AV_CHANNEL_ORDER_NATIVE:
+ return av_layout->u.mask == mp_chmap_to_lavc(mp_layout);
+ default:
+ // TODO: handle custom layouts
+ return false;
+ }
+
+ return true;
+}
+
+static void test_mp_chmap_to_av_channel_layout(void)
+{
+ mp_ch_layout_tuple *mapping_array = NULL;
+ void *iter = NULL;
+ bool anything_failed = false;
+
+ printf("Testing mp_chmap -> AVChannelLayout conversions\n");
+
+ while ((mapping_array = mp_iterate_builtin_layouts(&iter))) {
+ const char *mapping_name = (*mapping_array)[0];
+ const char *mapping_str = (*mapping_array)[1];
+ struct mp_chmap mp_layout = { 0 };
+ AVChannelLayout av_layout = { 0 };
+ char layout_desc[128] = {0};
+
+ assert_true(mp_chmap_from_str(&mp_layout, bstr0(mapping_str)));
+
+ mp_chmap_to_av_layout(&av_layout, &mp_layout);
+
+ assert_false(av_channel_layout_describe(&av_layout,
+ layout_desc, 128) < 0);
+
+ bool success =
+ (strcmp(layout_desc, mp_chmap_to_str(&mp_layout)) == 0 ||
+ layout_matches(&av_layout, &mp_layout, false));
+ if (!success)
+ anything_failed = true;
+
+ printf("%s: %s (%s) -> %s\n",
+ success ? "Success" : "Failure",
+ mapping_str, mapping_name, layout_desc);
+
+ av_channel_layout_uninit(&av_layout);
+ }
+
+ assert_false(anything_failed);
+}
+
+static void test_av_channel_layout_to_mp_chmap(void)
+{
+ const AVChannelLayout *av_layout = NULL;
+ void *iter = NULL;
+ bool anything_failed = false;
+
+ printf("Testing AVChannelLayout -> mp_chmap conversions\n");
+
+ while ((av_layout = av_channel_layout_standard(&iter))) {
+ struct mp_chmap mp_layout = { 0 };
+ char layout_desc[128] = {0};
+
+ assert_false(av_channel_layout_describe(av_layout,
+ layout_desc, 128) < 0);
+
+ bool ret = mp_chmap_from_av_layout(&mp_layout, av_layout);
+ if (!ret) {
+ bool too_many_channels =
+ av_layout->nb_channels > MP_NUM_CHANNELS;
+ printf("Conversion from '%s' to mp_chmap failed (%s)!\n",
+ layout_desc,
+ too_many_channels ?
+ "channel count was over max, ignoring" :
+ "unexpected, failing");
+
+ // we should for now only fail with things such as 22.2
+ // due to mp_chmap being currently limited to 16 channels
+ assert_true(too_many_channels);
+
+ continue;
+ }
+
+ bool success =
+ (strcmp(layout_desc, mp_chmap_to_str(&mp_layout)) == 0 ||
+ layout_matches(av_layout, &mp_layout, true));
+ if (!success)
+ anything_failed = true;
+
+ printf("%s: %s -> %s\n",
+ success ? "Success" : "Failure",
+ layout_desc, mp_chmap_to_str(&mp_layout));
+ }
+
+ assert_false(anything_failed);
+}
+#endif
+
+
+int main(void)
{
struct mp_chmap a;
struct mp_chmap b;
@@ -84,9 +209,10 @@ static void run(struct test_ctx *ctx)
mp_chmap_from_str(&b, bstr0("6.1(back)"));
assert_int_equal(mp_chmap_diffn(&a, &b), 0);
assert_int_equal(mp_chmap_diffn(&b, &a), 3);
-}
-const struct unittest test_chmap = {
- .name = "chmap",
- .run = run,
-};
+#if HAVE_AV_CHANNEL_LAYOUT
+ test_av_channel_layout_to_mp_chmap();
+ test_mp_chmap_to_av_channel_layout();
+#endif
+ return 0;
+}
diff --git a/test/format.c b/test/format.c
new file mode 100644
index 0000000000..8033d1b7e0
--- /dev/null
+++ b/test/format.c
@@ -0,0 +1,99 @@
+#include "test_utils.h"
+#include "common/common.h"
+
+int main(void)
+{
+ void *ta_ctx = talloc_new(NULL);
+
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, false, false), "123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, false, true), "123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, true, false), "123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, true, true), "123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, false, false), "+123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, false, true), "+123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, true, false), "+123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, true, true), "+123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false, false), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, true, false), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, true, true), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, false, false), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, true, false), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, true, true), "-123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, false, false), "123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, false, true), "123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, true, false), "123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, true, true), "123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, false, false), "+123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, false, true), "+123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, true, false), "+123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, true, true), "+123.46%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false, false), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false, true), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, true, false), "-123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, true, true), "-123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, false, false), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, false, true), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, true, false), "-123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, true, true), "-123.46%");
+
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, false, false), "123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, false, true), "123.456");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, true, false), "123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, true, true), "123.456%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, false, false), "+123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, false, true), "+123.456");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, true, false), "+123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, true, true), "+123.456%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false, false), "-123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false, true), "-123.456");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, true, false), "-123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, true, true), "-123.456%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, false, false), "-123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, false, true), "-123.456");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, true, false), "-123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, true, true), "-123.456%");
+
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, false, false), "123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, false, true), "123");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, true, false), "123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, true, true), "123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, false, false), "+123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, false, true), "+123");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, true, false), "+123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, true, true), "+123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false, false), "-123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, true, false), "-123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, true, true), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, false, false), "-123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, true, false), "-123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, true, true), "-123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, false, false), "inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, false, true), "inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, true, false), "inf%");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, true, true), "inf%");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, false, false), "+inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, false, true), "+inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, true, false), "+inf%");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, true, true), "+inf%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false, false), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false, true), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, true, false), "-inf%");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, true, true), "-inf%");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, false, false), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, false, true), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, true, false), "-inf%");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, true, true), "-inf%");
+
+ talloc_free(ta_ctx);
+}
diff --git a/test/gl_video.c b/test/gl_video.c
index 556a81ac92..a2bdda43a3 100644
--- a/test/gl_video.c
+++ b/test/gl_video.c
@@ -1,7 +1,7 @@
-#include "tests.h"
-#include "video/out/gpu/video.h"
+#include "test_utils.h"
+#include "video/out/gpu/utils.h"
-static void run(struct test_ctx *ctx)
+int main(void)
{
float x;
@@ -17,13 +17,9 @@ static void run(struct test_ctx *ctx)
x = gl_video_scale_ambient_lux(16.0, 64.0, 2.40, 1.961, 0.0);
assert_float_equal(x, 2.40f, FLT_EPSILON);
- // 32 corresponds to the the midpoint after converting lux to the log10 scale
+ // 32 corresponds to the midpoint after converting lux to the log10 scale
x = gl_video_scale_ambient_lux(16.0, 64.0, 2.40, 1.961, 32.0);
float mid_gamma = (2.40 - 1.961) / 2 + 1.961;
assert_float_equal(x, mid_gamma, FLT_EPSILON);
+ return 0;
}
-
-const struct unittest test_gl_video = {
- .name = "gl_video",
- .run = run,
-};
diff --git a/test/img_format.c b/test/img_format.c
index cf5bbb3af2..3b553f6531 100644
--- a/test/img_format.c
+++ b/test/img_format.c
@@ -1,55 +1,16 @@
#include <libavutil/frame.h>
#include <libavutil/pixdesc.h>
-#include "tests.h"
+#include "img_utils.h"
+#include "options/path.h"
+#include "test_utils.h"
#include "video/fmt-conversion.h"
#include "video/img_format.h"
#include "video/mp_image.h"
#include "video/sws_utils.h"
-int imgfmts[IMGFMT_AVPIXFMT_END - IMGFMT_AVPIXFMT_START + 100];
-int num_imgfmts;
-
static enum AVPixelFormat pixfmt_unsup[100];
static int num_pixfmt_unsup;
-static bool imgfmts_initialized;
-
-static int cmp_imgfmt_name(const void *a, const void *b)
-{
- char *name_a = mp_imgfmt_to_name(*(int *)a);
- char *name_b = mp_imgfmt_to_name(*(int *)b);
-
- return strcmp(name_a, name_b);
-}
-
-void init_imgfmts_list(void)
-{
- if (imgfmts_initialized)
- return;
-
- const AVPixFmtDescriptor *avd = av_pix_fmt_desc_next(NULL);
- for (; avd; avd = av_pix_fmt_desc_next(avd)) {
- enum AVPixelFormat fmt = av_pix_fmt_desc_get_id(avd);
- int mpfmt = pixfmt2imgfmt(fmt);
- if (!mpfmt) {
- assert(num_pixfmt_unsup < MP_ARRAY_SIZE(pixfmt_unsup));
- pixfmt_unsup[num_pixfmt_unsup++] = fmt;
- }
- }
-
- for (int fmt = IMGFMT_START; fmt <= IMGFMT_END; fmt++) {
- struct mp_imgfmt_desc d = mp_imgfmt_get_desc(fmt);
- enum AVPixelFormat pixfmt = imgfmt2pixfmt(fmt);
- if (d.id || pixfmt != AV_PIX_FMT_NONE) {
- assert(num_imgfmts < MP_ARRAY_SIZE(imgfmts)); // enlarge that array
- imgfmts[num_imgfmts++] = fmt;
- }
- }
-
- qsort(imgfmts, num_imgfmts, sizeof(imgfmts[0]), cmp_imgfmt_name);
-
- imgfmts_initialized = true;
-}
static const char *comp_type(enum mp_component_type type)
{
@@ -60,11 +21,13 @@ static const char *comp_type(enum mp_component_type type)
}
}
-static void run(struct test_ctx *ctx)
+int main(int argc, char *argv[])
{
init_imgfmts_list();
+ const char *refdir = argv[1];
+ const char *outdir = argv[2];
- FILE *f = test_open_out(ctx, "img_formats.txt");
+ FILE *f = test_open_out(outdir, "img_formats.txt");
for (int z = 0; z < num_imgfmts; z++) {
int mpfmt = imgfmts[z];
@@ -77,37 +40,82 @@ static void run(struct test_ctx *ctx)
int fcsp = mp_imgfmt_get_forced_csp(mpfmt);
if (fcsp)
- fprintf(f, "fcsp=%s ", m_opt_choice_str(mp_csp_names, fcsp));
+ fprintf(f, "fcsp=%s ", m_opt_choice_str(pl_csp_names, fcsp));
fprintf(f, "ctype=%s\n", comp_type(mp_imgfmt_get_component_type(mpfmt)));
struct mp_imgfmt_desc d = mp_imgfmt_get_desc(mpfmt);
if (d.id) {
- fprintf(f, " Legacy desc: ");
+ fprintf(f, " Basic desc: ");
#define FLAG(t, c) if (d.flags & (t)) fprintf(f, "[%s]", c);
FLAG(MP_IMGFLAG_BYTE_ALIGNED, "ba")
+ FLAG(MP_IMGFLAG_BYTES, "bb")
FLAG(MP_IMGFLAG_ALPHA, "a")
FLAG(MP_IMGFLAG_YUV_P, "yuvp")
FLAG(MP_IMGFLAG_YUV_NV, "nv")
- FLAG(MP_IMGFLAG_YUV, "yuv")
- FLAG(MP_IMGFLAG_RGB, "rgb")
+ FLAG(MP_IMGFLAG_COLOR_YUV, "yuv")
+ FLAG(MP_IMGFLAG_COLOR_RGB, "rgb")
+ FLAG(MP_IMGFLAG_COLOR_XYZ, "xyz")
+ FLAG(MP_IMGFLAG_GRAY, "gray")
FLAG(MP_IMGFLAG_LE, "le")
FLAG(MP_IMGFLAG_BE, "be")
- FLAG(MP_IMGFLAG_PAL, "pal")
- FLAG(MP_IMGFLAG_HWACCEL, "hw")
+ FLAG(MP_IMGFLAG_TYPE_PAL8, "pal")
+ FLAG(MP_IMGFLAG_TYPE_HW, "hw")
+ FLAG(MP_IMGFLAG_TYPE_FLOAT, "float")
+ FLAG(MP_IMGFLAG_TYPE_UINT, "uint")
fprintf(f, "\n");
- fprintf(f, " planes=%d, chroma=%d:%d align=%d:%d bits=%d cbits=%d\n",
- d.num_planes, d.chroma_xs, d.chroma_ys, d.align_x, d.align_y,
- d.plane_bits, d.component_bits);
+ fprintf(f, " planes=%d, chroma=%d:%d align=%d:%d\n",
+ d.num_planes, d.chroma_xs, d.chroma_ys, d.align_x, d.align_y);
fprintf(f, " {");
for (int n = 0; n < MP_MAX_PLANES; n++) {
- fprintf(f, "%d/%d/[%d:%d] ", d.bytes[n], d.bpp[n],
- d.xs[n], d.ys[n]);
+ if (n >= d.num_planes) {
+ assert(d.bpp[n] == 0 && d.xs[n] == 0 && d.ys[n] == 0);
+ continue;
+ }
+ fprintf(f, "%d/[%d:%d] ", d.bpp[n], d.xs[n], d.ys[n]);
}
fprintf(f, "}\n");
} else {
fprintf(f, " [NODESC]\n");
}
+ for (int n = 0; n < d.num_planes; n++) {
+ fprintf(f, " %d: %dbits", n, d.bpp[n]);
+ if (d.endian_shift)
+ fprintf(f, " endian_bytes=%d", 1 << d.endian_shift);
+ for (int x = 0; x < MP_NUM_COMPONENTS; x++) {
+ struct mp_imgfmt_comp_desc cm = d.comps[x];
+ fprintf(f, " {");
+ if (cm.plane == n) {
+ if (cm.size) {
+ fprintf(f, "%d:%d", cm.offset, cm.size);
+ if (cm.pad)
+ fprintf(f, "/%d", cm.pad);
+ } else {
+ assert(cm.offset == 0);
+ assert(cm.pad == 0);
+ }
+ }
+ fprintf(f, "}");
+ if (!(d.flags & (MP_IMGFLAG_PACKED_SS_YUV | MP_IMGFLAG_HAS_COMPS)))
+ {
+ assert(cm.size == 0);
+ assert(cm.offset == 0);
+ assert(cm.pad == 0);
+ }
+ }
+ fprintf(f, "\n");
+ if (d.flags & MP_IMGFLAG_PACKED_SS_YUV) {
+ assert(!(d.flags & MP_IMGFLAG_HAS_COMPS));
+ uint8_t offsets[10];
+ bool r = mp_imgfmt_get_packed_yuv_locations(mpfmt, offsets);
+ assert(r);
+ fprintf(f, " luma_offsets=[");
+ for (int x = 0; x < d.align_x; x++)
+ fprintf(f, " %d", offsets[x]);
+ fprintf(f, "]\n");
+ }
+ }
+
if (!(d.flags & MP_IMGFLAG_HWACCEL) && pixfmt != AV_PIX_FMT_NONE) {
AVFrame *fr = av_frame_alloc();
fr->format = pixfmt;
@@ -144,7 +152,8 @@ static void run(struct test_ctx *ctx)
fprintf(f, " Regular: planes=%d compbytes=%d bitpad=%d "
"chroma=%dx%d ctype=%s\n",
reg.num_planes, reg.component_size, reg.component_pad,
- reg.chroma_w, reg.chroma_h, comp_type(reg.component_type));
+ 1 << reg.chroma_xs, 1 << reg.chroma_ys,
+ comp_type(reg.component_type));
for (int n = 0; n < reg.num_planes; n++) {
struct mp_regular_imgfmt_plane *plane = &reg.planes[n];
fprintf(f, " %d: {", n);
@@ -202,11 +211,7 @@ static void run(struct test_ctx *ctx)
fclose(f);
- assert_text_files_equal(ctx, "img_formats.txt", "img_formats.txt",
+ assert_text_files_equal(refdir, outdir, "img_formats.txt",
"This can fail if FFmpeg adds new formats or flags.");
+ return 0;
}
-
-const struct unittest test_img_format = {
- .name = "img_format",
- .run = run,
-};
diff --git a/test/img_utils.c b/test/img_utils.c
new file mode 100644
index 0000000000..71764f304f
--- /dev/null
+++ b/test/img_utils.c
@@ -0,0 +1,63 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <assert.h>
+#include <libavutil/frame.h>
+#include <libavutil/pixdesc.h>
+
+#include "common/common.h"
+#include "img_utils.h"
+#include "video/img_format.h"
+#include "video/fmt-conversion.h"
+
+int imgfmts[IMGFMT_AVPIXFMT_END - IMGFMT_AVPIXFMT_START + 100];
+int num_imgfmts;
+
+static enum AVPixelFormat pixfmt_unsup[100];
+static int num_pixfmt_unsup;
+
+static int cmp_imgfmt_name(const void *a, const void *b)
+{
+ char *name_a = mp_imgfmt_to_name(*(int *)a);
+ char *name_b = mp_imgfmt_to_name(*(int *)b);
+
+ return strcmp(name_a, name_b);
+}
+
+void init_imgfmts_list(void)
+{
+ const AVPixFmtDescriptor *avd = av_pix_fmt_desc_next(NULL);
+ for (; avd; avd = av_pix_fmt_desc_next(avd)) {
+ enum AVPixelFormat fmt = av_pix_fmt_desc_get_id(avd);
+ int mpfmt = pixfmt2imgfmt(fmt);
+ if (!mpfmt) {
+ assert(num_pixfmt_unsup < MP_ARRAY_SIZE(pixfmt_unsup));
+ pixfmt_unsup[num_pixfmt_unsup++] = fmt;
+ }
+ }
+
+ for (int fmt = IMGFMT_START; fmt <= IMGFMT_END; fmt++) {
+ struct mp_imgfmt_desc d = mp_imgfmt_get_desc(fmt);
+ enum AVPixelFormat pixfmt = imgfmt2pixfmt(fmt);
+ if (d.id || pixfmt != AV_PIX_FMT_NONE) {
+ assert(num_imgfmts < MP_ARRAY_SIZE(imgfmts)); // enlarge that array
+ imgfmts[num_imgfmts++] = fmt;
+ }
+ }
+
+ qsort(imgfmts, num_imgfmts, sizeof(imgfmts[0]), cmp_imgfmt_name);
+}
diff --git a/test/img_utils.h b/test/img_utils.h
new file mode 100644
index 0000000000..2c21bcd954
--- /dev/null
+++ b/test/img_utils.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+// Sorted list of valid imgfmts. Call init_imgfmts_list() before use.
+extern int imgfmts[];
+extern int num_imgfmts;
+
+void init_imgfmts_list(void);
diff --git a/test/input-gamepad.conf b/test/input-gamepad.conf
deleted file mode 100644
index ad79fb9973..0000000000
--- a/test/input-gamepad.conf
+++ /dev/null
@@ -1,4 +0,0 @@
-GAMEPAD_RIGHT_STICK_LEFT seek -10
-GAMEPAD_RIGHT_STICK_RIGHT seek 10
-GAMEPAD_LEFT_TRIGGER seek -1
-GAMEPAD_RIGHT_TRIGGER seek 1
diff --git a/test/json.c b/test/json.c
index e95f88c972..8aeae2326e 100644
--- a/test/json.c
+++ b/test/json.c
@@ -1,7 +1,6 @@
-#include "common/common.h"
#include "misc/json.h"
#include "misc/node.h"
-#include "tests.h"
+#include "test_utils.h"
struct entry {
const char *src;
@@ -64,9 +63,7 @@ static const struct entry entries[] = {
NODE_MAP(L("_a12"), L(NODE_STR("b")))},
};
-#define MAX_DEPTH 10
-
-static void run(struct test_ctx *ctx)
+int main(void)
{
for (int n = 0; n < MP_ARRAY_SIZE(entries); n++) {
const struct entry *e = &entries[n];
@@ -74,7 +71,7 @@ static void run(struct test_ctx *ctx)
char *s = talloc_strdup(tmp, e->src);
json_skip_whitespace(&s);
struct mpv_node res;
- bool ok = json_parse(tmp, &res, &s, MAX_DEPTH) >= 0;
+ bool ok = json_parse(tmp, &res, &s, MAX_JSON_DEPTH) >= 0;
assert_true(ok != e->expect_fail);
if (!ok) {
talloc_free(tmp);
@@ -86,9 +83,5 @@ static void run(struct test_ctx *ctx)
assert_true(equal_mpv_node(&e->out_data, &res));
talloc_free(tmp);
}
+ return 0;
}
-
-const struct unittest test_json = {
- .name = "json",
- .run = run,
-};
diff --git a/test/libmpv_test.c b/test/libmpv_test.c
new file mode 100644
index 0000000000..fafef6ade9
--- /dev/null
+++ b/test/libmpv_test.c
@@ -0,0 +1,271 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <inttypes.h>
+#include <libmpv/client.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// Stolen from osdep/compiler.h
+#ifdef __GNUC__
+#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format(printf, a1, a2)))
+#define MP_NORETURN __attribute__((noreturn))
+#else
+#define PRINTF_ATTRIBUTE(a1, a2)
+#define MP_NORETURN
+#endif
+
+// Broken crap with __USE_MINGW_ANSI_STDIO
+#if defined(__MINGW32__) && defined(__GNUC__) && !defined(__clang__)
+#undef PRINTF_ATTRIBUTE
+#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (gnu_printf, a1, a2)))
+#endif
+
+// Dummy values for test_options_and_properties
+static const char *str = "string";
+static int flag = 1;
+static int64_t int_ = 20;
+static double double_ = 1.5;
+
+// Global handle.
+static mpv_handle *ctx;
+
+
+MP_NORETURN PRINTF_ATTRIBUTE(1, 2)
+static void fail(const char *fmt, ...)
+{
+ if (fmt) {
+ va_list va;
+ va_start(va, fmt);
+ vfprintf(stderr, fmt, va);
+ va_end(va);
+ }
+ mpv_destroy(ctx);
+ exit(1);
+}
+
+static void check_api_error(int status)
+{
+ if (status < 0)
+ fail("mpv API error: %s\n", mpv_error_string(status));
+}
+
+static void check_double(const char *property, double expect)
+{
+ double result_double;
+ check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_DOUBLE, &result_double));
+ if (expect != result_double)
+ fail("Double: expected '%f' but got '%f'!\n", expect, result_double);
+}
+
+static void check_flag(const char *property, int expect)
+{
+ int result_flag;
+ check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_FLAG, &result_flag));
+ if (expect != result_flag)
+ fail("Flag: expected '%d' but got '%d'!\n", expect, result_flag);
+}
+
+static void check_int(const char *property, int64_t expect)
+{
+ int64_t result_int;
+ check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_INT64, &result_int));
+ if (expect != result_int)
+ fail("Int: expected '%" PRId64 "' but got '%" PRId64 "'!\n", expect, result_int);
+}
+
+static void check_string(const char *property, const char *expect)
+{
+ char *result_string;
+ check_api_error(mpv_get_property(ctx, property, MPV_FORMAT_STRING, &result_string));
+ if (strcmp(expect, result_string) != 0)
+ fail("String: expected '%s' but got '%s'!\n", expect, result_string);
+ mpv_free(result_string);
+}
+
+static void check_results(const char *properties[], enum mpv_format formats[])
+{
+ for (int i = 0; properties[i]; i++) {
+ switch (formats[i]) {
+ case MPV_FORMAT_STRING:
+ check_string(properties[i], str);
+ break;
+ case MPV_FORMAT_FLAG:
+ check_flag(properties[i], flag);
+ break;
+ case MPV_FORMAT_INT64:
+ check_int(properties[i], int_);
+ break;
+ case MPV_FORMAT_DOUBLE:
+ check_double(properties[i], double_);
+ break;
+ }
+ }
+}
+
+static void set_options_and_properties(const char *options[], const char *properties[],
+ enum mpv_format formats[])
+{
+ for (int i = 0; options[i]; i++) {
+ switch (formats[i]) {