summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2026-06-25 08:34:56 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2026-09-04 11:06:23 +0200
commit78092ce771c506873b2839b70ad7c488a01535c3 (patch)
treeec47fc56a7f583195060fe08c30cade8c2b49cff
parent695b53939f5528d7a44d85d53029efb2fc28df9d (diff)
add tests to check for correct restored stencil
-rw-r--r--gunit_tests/save_restore.cpp53
-rw-r--r--samples/tests/save_restore.cpp38
2 files changed, 77 insertions, 14 deletions
diff --git a/gunit_tests/save_restore.cpp b/gunit_tests/save_restore.cpp
index 104f7bc..fb0f18d 100644
--- a/gunit_tests/save_restore.cpp
+++ b/gunit_tests/save_restore.cpp
@@ -16,24 +16,37 @@ class SaveRestoreTest : public DrawTestBase {
DrawTestBase::TearDown();
}
void recurse_draw(VkvgContext ctx, int depth, int maxDepth) {
- static float gap = 15.f;
+ static float gap = 10.f;
depth++;
- vkvg_save(ctx);
+ float depthRatio = (float)depth / maxDepth;
vkvg_rectangle(ctx, gap * depth, gap * depth, 512.f - gap * 2.f * depth, 512.f - gap * 2.f * depth);
vkvg_clip(ctx);
- vkvg_set_source_rgb(ctx, 0.3f/depth, 1.f / depth, 1.f);
+ vkvg_set_source_rgb(ctx, depthRatio, depthRatio, 1.f);
vkvg_paint(ctx);
vkvg_arc(ctx, 256, 256, 256.f - gap * depth, 0, 2.f*M_PI);
vkvg_clip(ctx);
vkvg_set_source_surface(ctx, imgSurf, 0, 0);
vkvg_paint(ctx);
+ vkvg_save(ctx);
+
if (depth < maxDepth)
recurse_draw(ctx, depth, maxDepth);
+ float a = M_PI * 0.5f * depthRatio;
+ float x = cos(a) * 256;
+ float y = sin(a) * 256;
+
+ vkvg_set_line_width(ctx, 2.f);
+ vkvg_move_to(ctx, 256.f - x, 256.f - y);
+ vkvg_line_to(ctx, 256.f + x, 256.f + y);
+ vkvg_set_source_rgba(ctx, 0.f, 1.f, 0.f, 0.6f);
+ vkvg_stroke(ctx);
vkvg_restore(ctx);
EXPECT_EQ(VKVG_STATUS_SUCCESS, vkvg_status(ctx));
+
+ depth--;
}
};
@@ -52,17 +65,35 @@ TEST_F(SaveRestoreTest, RestoreClip1) {
compareWithRefImage();
}
+TEST_F(SaveRestoreTest, RecursePaint3) {
+ VkvgContext ctx = vkvg_create(surf);
+
+ EXPECT_NO_FATAL_FAILURE(recurse_draw(ctx, 0, 3));
-TEST_F(SaveRestoreTest, RecursePaint5) {
+ vkvg_destroy(ctx);
+
+ compareWithRefImage();
+}
+
+TEST_F(SaveRestoreTest, RecursePaint6) {
VkvgContext ctx = vkvg_create(surf);
- EXPECT_NO_FATAL_FAILURE(recurse_draw(ctx, 0, 5));
+ EXPECT_NO_FATAL_FAILURE(recurse_draw(ctx, 0, 6));
vkvg_destroy(ctx);
compareWithRefImage();
}
+TEST_F(SaveRestoreTest, RecursePaint9) {
+ VkvgContext ctx = vkvg_create(surf);
+
+ EXPECT_NO_FATAL_FAILURE(recurse_draw(ctx, 0, 9));
+
+ vkvg_destroy(ctx);
+
+ compareWithRefImage();
+}
TEST_F(SaveRestoreTest, RecursePaint10) {
VkvgContext ctx = vkvg_create(surf);
@@ -73,11 +104,19 @@ TEST_F(SaveRestoreTest, RecursePaint10) {
compareWithRefImage();
}
+TEST_F(SaveRestoreTest, RecursePaint11) {
+ VkvgContext ctx = vkvg_create(surf);
+
+ EXPECT_NO_FATAL_FAILURE(recurse_draw(ctx, 0, 11));
+
+ vkvg_destroy(ctx);
-TEST_F(SaveRestoreTest, RecursePaint16) {
+ compareWithRefImage();
+}
+TEST_F(SaveRestoreTest, RecursePaint20) {
VkvgContext ctx = vkvg_create(surf);
- EXPECT_NO_THROW(recurse_draw(ctx, 0, 16));
+ EXPECT_NO_FATAL_FAILURE(recurse_draw(ctx, 0, 20));
vkvg_destroy(ctx);
diff --git a/samples/tests/save_restore.cpp b/samples/tests/save_restore.cpp
index 063e085..7bbcb41 100644
--- a/samples/tests/save_restore.cpp
+++ b/samples/tests/save_restore.cpp
@@ -17,23 +17,35 @@ void recurse_draw(VkvgContext ctx, int depth) {
vkvg_restore(ctx);
}
void recurse_draw_clipped(VkvgContext ctx, int depth, int maxDepth) {
- static float gap = 15.f;
+ static float gap = 10.f;
depth++;
- vkvg_save(ctx);
+ float depthRatio = (float)depth / maxDepth;
vkvg_rectangle(ctx, gap * depth, gap * depth, 512.f - gap * 2.f * depth, 512.f - gap * 2.f * depth);
vkvg_clip(ctx);
- vkvg_set_source_rgb(ctx, 0.3f/depth, 1.f / depth, 1.f);
+ vkvg_set_source_rgb(ctx, depthRatio, depthRatio, 1.f);
vkvg_paint(ctx);
vkvg_arc(ctx, 256, 256, 256.f - gap * depth, 0, 2.f*M_PI);
vkvg_clip(ctx);
vkvg_set_source_surface(ctx, imgSurf, 0, 0);
vkvg_paint(ctx);
+ vkvg_save(ctx);
+
if (depth < maxDepth)
recurse_draw_clipped(ctx, depth, maxDepth);
+ float a = M_PIF * 0.5f * depthRatio;
+ float x = cos(a) * 256;
+ float y = sin(a) * 256;
+
+ vkvg_set_line_width(ctx, 2.f);
+ vkvg_move_to(ctx, 256.f - x, 256.f - y);
+ vkvg_line_to(ctx, 256.f + x, 256.f + y);
+ vkvg_set_source_rgba(ctx, 0.f, 1.f, 0.f, 0.6f);
+ vkvg_stroke(ctx);
vkvg_restore(ctx);
+
depth--;
}
@@ -42,15 +54,27 @@ TEST(save_restrore) {
recurse_draw(ctx, 0);
vkvg_destroy(ctx);
}
-TEST(save_restrore_clipped) {
+TEST(save_restrore_clipped3) {
VkvgContext ctx = vkvg_create(test->surf);
imgSurf = vkvg_surface_create_from_image(test->device, GET_PATH("img512.png"));
- recurse_draw_clipped(ctx, 0, 14);
+ recurse_draw_clipped(ctx, 0, 3);
+ vkvg_surface_destroy(imgSurf);
+ vkvg_destroy(ctx);
+}
+TEST(save_restrore_clipped5) {
+ VkvgContext ctx = vkvg_create(test->surf);
+ imgSurf = vkvg_surface_create_from_image(test->device, GET_PATH("img512.png"));
+ recurse_draw_clipped(ctx, 0, 5);
+ vkvg_surface_destroy(imgSurf);
+ vkvg_destroy(ctx);
+}
+TEST(save_restrore_clipped20) {
+ VkvgContext ctx = vkvg_create(test->surf);
+ imgSurf = vkvg_surface_create_from_image(test->device, GET_PATH("img512.png"));
+ recurse_draw_clipped(ctx, 0, 20);
vkvg_surface_destroy(imgSurf);
vkvg_destroy(ctx);
}
-
-