summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2025-08-19 10:07:59 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2026-09-04 11:06:23 +0200
commit9a394c11e7a3e6a2c27b361d40831c61d5da8a1e (patch)
tree40dc975a06315b0f0d2bca83d68a82a7c737f734
parent711cd23163ef2b593f5c6df64c30f33ae356fe77 (diff)
more samples
-rw-r--r--samples/tests/colinear.cpp19
-rw-r--r--samples/tests/compositing.cpp4
-rw-r--r--samples/tests/context.cpp15
-rw-r--r--samples/tests/fill_and_stroke.cpp47
-rw-r--r--samples/tests/gradient.cpp14
-rw-r--r--samples/tests/recording.cpp41
-rw-r--r--samples/tests/save_restore.cpp30
-rw-r--r--samples/tests/stroke.cpp54
-rw-r--r--samples/tests/surface.cpp15
-rw-r--r--samples/tests/svg.cpp45
-rw-r--r--tests/CMakeLists.txt2
11 files changed, 283 insertions, 3 deletions
diff --git a/samples/tests/colinear.cpp b/samples/tests/colinear.cpp
new file mode 100644
index 0000000..300c744
--- /dev/null
+++ b/samples/tests/colinear.cpp
@@ -0,0 +1,19 @@
+#include "VkvgTest.hpp"
+
+TEST(colinear_line_to) {
+ VkvgContext ctx = vkvg_create(test->surf);
+
+ vkvg_set_source_rgba(ctx, 0.7f, 0.7f, 0.7f, 1);
+ vkvg_paint(ctx);
+
+ vkvg_set_source_rgba(ctx, 0, 1, 0, 1);
+ vkvg_set_line_width(ctx, 10);
+
+ vkvg_move_to(ctx, 100, 100);
+ vkvg_line_to(ctx, 100, 200);
+ vkvg_line_to(ctx, 100, 300);
+ vkvg_stroke(ctx);
+
+ vkvg_destroy(ctx);
+}
+
diff --git a/samples/tests/compositing.cpp b/samples/tests/compositing.cpp
index 6ef062e..d122912 100644
--- a/samples/tests/compositing.cpp
+++ b/samples/tests/compositing.cpp
@@ -1,7 +1,7 @@
#include "VkvgTest.hpp"
-
TEST(compositing) {
VkvgContext ctx = vkvg_create(test->surf);
+ vkvg_clear(ctx);
vkvg_set_source_rgba(ctx, 1, 0, 0, 0.5f);
vkvg_rectangle(ctx, 100, 100, 200, 200);
@@ -13,9 +13,9 @@ TEST(compositing) {
vkvg_destroy(ctx);
}
-
TEST(opacity) {
VkvgContext ctx = vkvg_create(test->surf);
+ vkvg_clear(ctx);
vkvg_set_source_rgba(ctx, 1, 0, 0, 1.0f);
vkvg_rectangle(ctx, 100, 100, 200, 200);
diff --git a/samples/tests/context.cpp b/samples/tests/context.cpp
new file mode 100644
index 0000000..157fbc3
--- /dev/null
+++ b/samples/tests/context.cpp
@@ -0,0 +1,15 @@
+#include "VkvgTest.hpp"
+
+TEST(context_create_destroy_multi) {
+ VkvgContext* ctxs = (VkvgContext*)malloc(sizeof(VkvgContext) * test->app->testSize);
+ for (uint32_t i = 0; i < test->app->testSize; i++)
+ ctxs[i] = vkvg_create(test->surf);
+ for (uint32_t i = 0; i < test->app->testSize; i++)
+ vkvg_destroy(ctxs[i]);
+ free(ctxs);
+}
+
+TEST(context_create_destroy_single) {
+ VkvgContext ctx = vkvg_create(test->surf);
+ vkvg_destroy(ctx);
+}
diff --git a/samples/tests/fill_and_stroke.cpp b/samples/tests/fill_and_stroke.cpp
new file mode 100644
index 0000000..cfc6706
--- /dev/null
+++ b/samples/tests/fill_and_stroke.cpp
@@ -0,0 +1,47 @@
+#include "VkvgTest.hpp"
+TEST(fill_and_stroke) {
+ VkvgContext ctx = vkvg_create(test->surf);
+
+ vkvg_move_to(ctx, 100, 100);
+ vkvg_rel_line_to(ctx, 50, -80);
+ vkvg_rel_line_to(ctx, 50, 80);
+ vkvg_close_path(ctx);
+
+ vkvg_move_to(ctx, 300, 100);
+ vkvg_rel_line_to(ctx, 50, -80);
+ vkvg_rel_line_to(ctx, 50, 80);
+ vkvg_close_path(ctx);
+
+ vkvg_set_line_width(ctx, 10.0);
+ vkvg_set_source_rgb(ctx, 0, 0, 1);
+ vkvg_fill_preserve(ctx);
+ // vkvg_fill(ctx);
+ vkvg_set_source_rgb(ctx, 1, 0, 0);
+ vkvg_stroke(ctx);
+
+ vkvg_destroy(ctx);
+}
+TEST(fill_non_zero) {
+ VkvgContext ctx = vkvg_create(test->surf);
+ vkvg_save(ctx);
+ vkvg_set_line_width(ctx, 30);
+ vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO);
+
+ vkvg_set_source_rgba(ctx, 0.1f, 0.9f, 0.1f, 1.0f);
+ vkvg_move_to(ctx, 100, 100);
+ vkvg_rel_line_to(ctx, 200, 0);
+ vkvg_rel_line_to(ctx, 0, 150);
+ vkvg_rel_line_to(ctx, -200, 0);
+ vkvg_close_path(ctx);
+
+ vkvg_move_to(ctx, 150, 150);
+ vkvg_rel_line_to(ctx, 0, 50);
+ vkvg_rel_line_to(ctx, 100, 0);
+ vkvg_rel_line_to(ctx, 0, -50);
+ vkvg_close_path(ctx);
+
+ vkvg_fill(ctx);
+
+ vkvg_destroy(ctx);
+}
+
diff --git a/samples/tests/gradient.cpp b/samples/tests/gradient.cpp
index 2af598d..37379b3 100644
--- a/samples/tests/gradient.cpp
+++ b/samples/tests/gradient.cpp
@@ -158,3 +158,17 @@ TEST(gradient_alpha) {
vkvg_destroy(ctx);
}
+
+TEST(gradient_radial) {
+ VkvgContext ctx = vkvg_create(test->surf);
+
+ VkvgPattern radial = vkvg_pattern_create_radial(250.0f, 250.0f, 0, 300, 300, 260.0f);
+ vkvg_pattern_add_color_stop(radial, 0.0, 1, 0, 0, 1);
+ vkvg_pattern_add_color_stop(radial, 0.5, 0, 1, 0, 1);
+ vkvg_pattern_add_color_stop(radial, 1.0, 0, 0, 0, 1);
+ vkvg_set_source(ctx, radial);
+ vkvg_paint(ctx);
+ vkvg_pattern_destroy(radial);
+
+ vkvg_destroy(ctx);
+}
diff --git a/samples/tests/recording.cpp b/samples/tests/recording.cpp
new file mode 100644
index 0000000..2abb48d
--- /dev/null
+++ b/samples/tests/recording.cpp
@@ -0,0 +1,41 @@
+#include "VkvgTest.hpp"
+
+#if VKVG_RECORDING
+TEST(recording) {
+ VkvgContext ctx = vkvg_create(test->surf);
+
+ vkvg_scale(ctx, 0.5, 0.5);
+ vkvg_start_recording(ctx);
+
+ vkvg_set_source_rgba(ctx, 0.1f, 0.9f, 0.1f, 1.0f);
+ vkvg_move_to(ctx, 100, 100);
+ vkvg_rel_line_to(ctx, 50, 200);
+ vkvg_rel_line_to(ctx, 150, -100);
+ vkvg_rel_line_to(ctx, 100, 200);
+ vkvg_rel_line_to(ctx, -100, 100);
+ vkvg_rel_line_to(ctx, -10, -100);
+ vkvg_rel_line_to(ctx, -190, -50);
+ vkvg_rel_line_to(ctx, 300, 50);
+ vkvg_rel_line_to(ctx, 50, 0);
+ vkvg_rel_line_to(ctx, 0, 50);
+ vkvg_rel_line_to(ctx, 50, 0);
+ vkvg_rel_line_to(ctx, 0, 50);
+ vkvg_rel_line_to(ctx, 50, 0);
+ vkvg_rel_line_to(ctx, 0, 50);
+ vkvg_rel_line_to(ctx, 50, 0);
+ vkvg_rel_line_to(ctx, 0, 50);
+ vkvg_close_path(ctx);
+
+ vkvg_stroke_preserve(ctx);
+ vkvg_fill(ctx);
+
+ VkvgRecording rec = vkvg_stop_recording(ctx);
+
+ vkvg_translate(ctx, 400, 0);
+ vkvg_replay(ctx, rec);
+
+ vkvg_destroy(ctx);
+ vkvg_recording_destroy(rec);
+}
+#endif
+
diff --git a/samples/tests/save_restore.cpp b/samples/tests/save_restore.cpp
new file mode 100644
index 0000000..48833e3
--- /dev/null
+++ b/samples/tests/save_restore.cpp
@@ -0,0 +1,30 @@
+#include "VkvgTest.hpp"
+
+void recurse_draw(VkvgContext ctx, int depth) {
+ depth++;
+ vkvg_save(ctx);
+
+ vkvg_translate(ctx, 5, 5);
+ vkvg_rectangle(ctx, (float)depth, (float)depth, 200, 200);
+ /*vkvg_clip_preserve(ctx);
+ vkvg_set_source_rgb(ctx, 1.f/depth, 1.f / depth, 1.f / depth);
+ vkvg_fill_preserve(ctx);*/
+ vkvg_set_source_rgb(ctx, 0, 1, 0);
+ vkvg_stroke(ctx);
+
+ if (depth < 20)
+ recurse_draw(ctx, depth);
+
+ vkvg_restore(ctx);
+}
+
+TEST(save_restrore) {
+ VkvgContext ctx = vkvg_create(test->surf);
+ recurse_draw(ctx, 0);
+ vkvg_destroy(ctx);
+}
+
+
+
+
+
diff --git a/samples/tests/stroke.cpp b/samples/tests/stroke.cpp
new file mode 100644
index 0000000..7f9f8ab
--- /dev/null
+++ b/samples/tests/stroke.cpp
@@ -0,0 +1,54 @@
+#include "VkvgTest.hpp"
+TEST(stroke) {
+ VkvgContext ctx = vkvg_create(test->surf);
+
+ vkvg_set_line_width(ctx, 1);
+ vkvg_set_source_rgba(ctx, 1, 0, 0, 1);
+ vkvg_move_to(ctx, 200.5f, 200.5f);
+ vkvg_line_to(ctx, 400.5f, 200.5f);
+ vkvg_line_to(ctx, 400.5f, 400.5f);
+ vkvg_line_to(ctx, 200.5f, 400.5f);
+ vkvg_close_path(ctx);
+ vkvg_stroke(ctx);
+
+ vkvg_set_source_rgba(ctx, 0, 1, 0, 1);
+ vkvg_move_to(ctx, 300.5f, 300.5f);
+ vkvg_line_to(ctx, 500.5f, 300.5f);
+ vkvg_line_to(ctx, 500.5f, 500.5f);
+ vkvg_line_to(ctx, 300.5f, 500.5f);
+ vkvg_stroke(ctx);
+
+ // vkvg_set_source_rgba(ctx,0,0.2,0.35,1);
+ // vkvg_fill(ctx);
+
+ vkvg_set_source_rgba(ctx, 0.5f, 1, 0, 1);
+ vkvg_move_to(ctx, 320.5f, 320.5f);
+ vkvg_line_to(ctx, 520.5f, 320.5f);
+ vkvg_line_to(ctx, 520.5f, 520.5f);
+ vkvg_line_to(ctx, 320.5f, 520.5f);
+ // vkvg_close_path(ctx);
+ vkvg_stroke(ctx);
+ vkvg_set_line_width(ctx, 40);
+ vkvg_set_source_rgba(ctx, 0.5f, 0.6f, 1, 1.0f);
+ vkvg_move_to(ctx, 700, 475);
+ vkvg_line_to(ctx, 400, 475);
+ vkvg_stroke(ctx);
+ vkvg_set_source_rgba(ctx, 0, 0.5f, 0.5f, 0.5f);
+ vkvg_move_to(ctx, 300, 200);
+ vkvg_arc(ctx, 200, 200, 100, 0, M_PIF);
+ vkvg_stroke(ctx);
+
+ vkvg_set_line_width(ctx, 20);
+ vkvg_set_source_rgba(ctx, 0.1f, 0.1f, 0.1f, 0.5f);
+ vkvg_move_to(ctx, 100, 60);
+ vkvg_line_to(ctx, 400, 600);
+ vkvg_stroke(ctx);
+
+ vkvg_set_source_rgba(ctx, 1, 1, 1, 1);
+ vkvg_set_line_width(ctx, 1);
+ vkvg_rectangle(ctx, 600.5f, 200.5f, 100, 60);
+ vkvg_stroke(ctx);
+
+ vkvg_destroy(ctx);
+}
+
diff --git a/samples/tests/surface.cpp b/samples/tests/surface.cpp
new file mode 100644
index 0000000..e82d176
--- /dev/null
+++ b/samples/tests/surface.cpp
@@ -0,0 +1,15 @@
+#include "VkvgTest.hpp"
+TEST(surface_create_destroy_multi_512) {
+ VkvgSurface* surfs = (VkvgSurface*)malloc(sizeof(VkvgSurface) * test->app->testSize);
+ for (uint32_t i = 0; i < test->app->testSize; i++)
+ surfs[i] = vkvg_surface_create(test->device, 512, 512);
+ for (uint32_t i = 0; i < test->app->testSize; i++)
+ vkvg_surface_destroy(surfs[i]);
+ free(surfs);
+}
+
+TEST(surface_create_destroy_single_512) {
+ VkvgSurface s = vkvg_surface_create(test->device, 512, 512);
+ vkvg_surface_destroy(s);
+}
+
diff --git a/samples/tests/svg.cpp b/samples/tests/svg.cpp
new file mode 100644
index 0000000..12f2895
--- /dev/null
+++ b/samples/tests/svg.cpp
@@ -0,0 +1,45 @@
+#include "VkvgTest.hpp"
+
+#include "vkvg-svg.h"
+
+static float rotation = 0.f;
+
+TEST(svg_surface_create_from_svg) {
+ VkvgSurface svgSurf = vkvg_surface_create_from_svg(test->device, test->app->width, test->app->height, GET_PATH("tiger.svg"));
+ VkvgContext ctx = vkvg_create(test->surf);
+
+ vkvg_set_source_rgb(ctx, 1, 1, 1);
+ vkvg_paint(ctx);
+
+ vkvg_set_source_surface(ctx, svgSurf, 0, 0);
+ vkvg_paint(ctx);
+
+ vkvg_destroy(ctx);
+ vkvg_surface_destroy(svgSurf);
+}
+TEST(svg_load_render) {
+ VkvgSvg svg = vkvg_svg_load(GET_PATH("tiger.svg"));
+ uint32_t w, h;
+ vkvg_svg_get_dimensions(svg, &w, &h);
+ VkvgContext ctx = vkvg_create(test->surf);
+ vkvg_clear(ctx);
+
+ vkvg_svg_render(svg, ctx, NULL);
+
+ vkvg_destroy(ctx);
+ vkvg_svg_destroy(svg);
+}
+TEST(svg_load_render_sub) {
+ VkvgSvg svg = vkvg_svg_load(GET_PATH("checkbox.svg"));
+ uint32_t w, h;
+ vkvg_svg_get_dimensions(svg, &w, &h);
+ VkvgContext ctx = vkvg_create(test->surf);
+ vkvg_clear(ctx);
+
+ vkvg_svg_render(svg, ctx, "#True");
+ vkvg_translate(ctx, 200, 0);
+ vkvg_svg_render(svg, ctx, "#False");
+
+ vkvg_destroy(ctx);
+ vkvg_svg_destroy(svg);
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d148dbe..20124e9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,7 +8,7 @@ IF (VKVG_TEST_OFFSCREEN)
ADD_DEFINITIONS (-DVKVG_TEST_OFFSCREEN)
ENDIF ()
-set(TESTS_DATA_ROOT "${CMAKE_SOURCE_DIR}/tests/data/" CACHE STRING "Data path for tests")
+SET(TESTS_DATA_ROOT "${CMAKE_SOURCE_DIR}/tests/data/" CACHE STRING "Data path for tests")
FUNCTION (buildtest TEST_FILE)
GET_FILENAME_COMPONENT(TEST_NAME ${TEST_FILE} NAME_WE)