From 1fbf162982e6941814d5f720a17b5f19b34cea1e Mon Sep 17 00:00:00 2001 From: Michal Maciola <71131832+mmaciola@users.noreply.github.com> Date: Thu, 15 Jul 2021 17:32:41 +0200 Subject: [PATCH] test capi: Stroke Radial Gradient Added tvg_shape_get_gradient --- test/capi/capiRadialGradient.cpp | 61 ++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/test/capi/capiRadialGradient.cpp b/test/capi/capiRadialGradient.cpp index 608f41a..ca31721 100644 --- a/test/capi/capiRadialGradient.cpp +++ b/test/capi/capiRadialGradient.cpp @@ -38,9 +38,9 @@ TEST_CASE("Set gradient center point and radius", "[capiRadialGradient]") float cx, cy, radius; REQUIRE(tvg_radial_gradient_get(gradient, &cx, &cy, &radius) == TVG_RESULT_SUCCESS); - REQUIRE(cx == 10.0); - REQUIRE(cy == 15.0); - REQUIRE(radius == 30.0); + REQUIRE(cx == Approx(10.0).margin(0.000001)); + REQUIRE(cy == Approx(15.0).margin(0.000001)); + REQUIRE(radius == Approx(30.0).margin(0.000001)); REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); } @@ -49,15 +49,18 @@ TEST_CASE("Set gradient in shape", "[capiRadialGradient]") { REQUIRE(tvg_shape_set_radial_gradient(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT); - Tvg_Paint *shape = tvg_shape_new(); - REQUIRE(shape); - Tvg_Gradient *gradient = tvg_radial_gradient_new(); REQUIRE(gradient); + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape); + REQUIRE(tvg_shape_set_radial_gradient(NULL, gradient) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_set_radial_gradient(shape, gradient) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); + Tvg_Gradient *gradient_ret = NULL; + REQUIRE(tvg_shape_get_gradient(shape, &gradient_ret) == TVG_RESULT_SUCCESS); + REQUIRE(gradient_ret); REQUIRE(tvg_shape_set_radial_gradient(shape, NULL) == TVG_RESULT_MEMORY_CORRUPTION); REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); @@ -133,4 +136,46 @@ TEST_CASE("Set/Get gradient spread", "[capiRadialGradient]") REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); REQUIRE(tvg_gradient_del(NULL) == TVG_RESULT_INVALID_ARGUMENT); -} \ No newline at end of file +} + +TEST_CASE("Stroke Radial Gradient", "[capiRadialGradient]") +{ + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape); + + Tvg_Gradient *gradient = tvg_radial_gradient_new(); + REQUIRE(gradient); + + REQUIRE(tvg_radial_gradient_set(gradient, 10.0, 15.0, 30.0) == TVG_RESULT_SUCCESS); + + Tvg_Color_Stop color_stops[2] = + { + {.offset=0.0, .r=0, .g=0, .b=0, .a=255}, + {.offset=1, .r=0, .g=255, .b=0, .a=255}, + }; + + Tvg_Gradient *gradient_ret = NULL; + const Tvg_Color_Stop *color_stops_ret = NULL; + uint32_t color_stops_count_ret = 0; + + REQUIRE(tvg_gradient_set_color_stops(gradient, color_stops, 2) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_shape_set_stroke_radial_gradient(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_set_stroke_radial_gradient(NULL, gradient) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_set_stroke_radial_gradient(shape, gradient) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_shape_get_stroke_gradient(shape, &gradient_ret) == TVG_RESULT_SUCCESS); + REQUIRE(gradient_ret); + + REQUIRE(tvg_gradient_get_color_stops(gradient_ret, &color_stops_ret, &color_stops_count_ret) == TVG_RESULT_SUCCESS); + REQUIRE(color_stops_ret); + REQUIRE(color_stops_count_ret == 2); + + float cx, cy, radius; + REQUIRE(tvg_radial_gradient_get(gradient_ret, &cx, &cy, &radius) == TVG_RESULT_SUCCESS); + REQUIRE(cx == Approx(10.0).margin(0.000001)); + REQUIRE(cy == Approx(15.0).margin(0.000001)); + REQUIRE(radius == Approx(30.0).margin(0.000001)); + + REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); +} -- 2.7.4