summaryrefslogtreecommitdiff
path: root/subprojects/pixpat/pixpat-native/tests/test_pixpat_c.c
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2026-05-08 17:22:58 +0300
committerTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2026-05-08 17:22:58 +0300
commit4e2b291a4acdc2cbd39f005c88bda363bc06bd34 (patch)
treee90048d5973ad1164b109d575cf577af7daf50be /subprojects/pixpat/pixpat-native/tests/test_pixpat_c.c
parent8f94b39040e79eccd9312ed1e467fe8ebfab8860 (diff)
parente0b7d30fd437292c88141fb08d60681870b86c6e (diff)
Merge commit 'e0b7d30fd437292c88141fb08d60681870b86c6e' as 'subprojects/pixpat'
Diffstat (limited to 'subprojects/pixpat/pixpat-native/tests/test_pixpat_c.c')
-rw-r--r--subprojects/pixpat/pixpat-native/tests/test_pixpat_c.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/subprojects/pixpat/pixpat-native/tests/test_pixpat_c.c b/subprojects/pixpat/pixpat-native/tests/test_pixpat_c.c
new file mode 100644
index 0000000..e80780a
--- /dev/null
+++ b/subprojects/pixpat/pixpat-native/tests/test_pixpat_c.c
@@ -0,0 +1,68 @@
+/*
+ * Native C smoke test for libpixpat.
+ *
+ * Sole purpose: prove that <pixpat/pixpat.h> compiles as C and that the
+ * library links and runs from a C consumer. Behavioral coverage lives
+ * in the Python suite; this file exists to catch C-only regressions in
+ * the public header (stray C++-isms, missing extern "C", etc.) that a
+ * C++ test cannot detect.
+ */
+
+#include <pixpat/pixpat.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* CHECK always evaluates its expression so the test still runs in
+ * release builds where assert() is compiled out. */
+#define CHECK(expr) do { \
+ if (!(expr)) { \
+ fprintf(stderr, "%s:%d: CHECK failed: %s\n", \
+ __FILE__, __LINE__, #expr); \
+ return 1; \
+ } \
+} while (0)
+
+int main(void)
+{
+ CHECK(pixpat_format_count() > 0);
+ CHECK(pixpat_format_supported("XRGB8888") == 1);
+
+ const uint32_t w = 32, h = 16;
+ uint8_t *rgb = (uint8_t *)calloc((size_t)w * h * 4, 1);
+ uint8_t *wide = (uint8_t *)calloc((size_t)w * h * 8, 1);
+ CHECK(rgb && wide);
+
+ pixpat_buffer fb;
+ memset(&fb, 0, sizeof(fb));
+ fb.format = "XRGB8888";
+ fb.width = w;
+ fb.height = h;
+ fb.num_planes = 1;
+ fb.planes[0] = rgb;
+ fb.strides[0] = w * 4;
+
+ pixpat_pattern_opts pat;
+ memset(&pat, 0, sizeof(pat));
+ pat.rec = PIXPAT_REC_BT709;
+ pat.range = PIXPAT_RANGE_LIMITED;
+ CHECK(pixpat_draw_pattern(&fb, "smpte", &pat) == 0);
+ /* Cover the NULL-opts path. */
+ CHECK(pixpat_draw_pattern(&fb, NULL, NULL) == 0);
+
+ pixpat_buffer dst;
+ memset(&dst, 0, sizeof(dst));
+ dst.format = "ABGR16161616";
+ dst.width = w;
+ dst.height = h;
+ dst.num_planes = 1;
+ dst.planes[0] = wide;
+ dst.strides[0] = w * 8;
+ CHECK(pixpat_convert(&dst, &fb, NULL) == 0);
+
+ free(rgb);
+ free(wide);
+ return 0;
+}