From bde0d8e751ced7b271cb44b2f6198049d75b14c8 Mon Sep 17 00:00:00 2001 From: Michal Szczecinski Date: Fri, 4 Jun 2021 13:17:25 +0200 Subject: [PATCH] utc capi: Added linear gradient tests. --- test/capi/testLinearGradient.cpp | 161 +++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 162 insertions(+) create mode 100644 test/capi/testLinearGradient.cpp diff --git a/test/capi/testLinearGradient.cpp b/test/capi/testLinearGradient.cpp new file mode 100644 index 00000000..52c49652 --- /dev/null +++ b/test/capi/testLinearGradient.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "catch.hpp" + +TEST_CASE("Basic Create", "[capiLinearGradient]") +{ + Tvg_Gradient *gradient = NULL; + gradient = tvg_linear_gradient_new(); + REQUIRE(gradient != NULL); + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Set gradient start and end position", "[capiLinearGradient]") +{ + Tvg_Gradient *gradient = NULL; + float x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0; + + gradient = tvg_linear_gradient_new(); + + REQUIRE(gradient != NULL); + REQUIRE(tvg_linear_gradient_set(gradient, 10.0, 20.0, 50.0, 40.0) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_linear_gradient_get(gradient, &x1, &y1, &x2, &y2) == TVG_RESULT_SUCCESS); + REQUIRE(x1 == 10.0); + REQUIRE(y1 == 20.0); + REQUIRE(x2 == 50.0); + REQUIRE(y2 == 40.0); + + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Set gradient in shape", "[capiLinearGradient]") +{ + Tvg_Paint *shape = NULL; + Tvg_Gradient *gradient = NULL; + + REQUIRE(tvg_shape_set_linear_gradient(shape, gradient) == TVG_RESULT_INVALID_ARGUMENT); + + gradient = tvg_linear_gradient_new(); + REQUIRE(gradient != NULL); + REQUIRE(tvg_shape_set_linear_gradient(shape, gradient) == TVG_RESULT_INVALID_ARGUMENT); + + shape = tvg_shape_new(); + REQUIRE(shape != NULL); + + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); + gradient = NULL; + + REQUIRE(tvg_shape_set_linear_gradient(shape, gradient) == TVG_RESULT_MEMORY_CORRUPTION); + REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Set/Get color stops", "[capiLinearGradient]") +{ + Tvg_Paint *shape = NULL; + Tvg_Gradient *gradient = NULL; + + 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}, + }; + + const Tvg_Color_Stop *color_stops_ret = NULL; + uint32_t color_stops_count_ret = 0; + + shape = tvg_shape_new(); + REQUIRE(shape != NULL); + + gradient = tvg_linear_gradient_new(); + REQUIRE(gradient != NULL); + + REQUIRE(tvg_gradient_set_color_stops(gradient, color_stops, 2) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_gradient_get_color_stops(gradient, &color_stops_ret, &color_stops_count_ret) == TVG_RESULT_SUCCESS); + REQUIRE(color_stops_count_ret == 2); + + REQUIRE(color_stops_ret[0].a == 255); + REQUIRE(color_stops_ret[1].g == 255); + + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Clear gradient data", "[capiLinearGradient]") +{ + Tvg_Paint *shape = NULL; + Tvg_Gradient *gradient = NULL; + + 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}, + }; + + const Tvg_Color_Stop *color_stops_ret = NULL; + uint32_t color_stops_count_ret = 0; + + shape = tvg_shape_new(); + REQUIRE(shape != NULL); + + gradient = tvg_linear_gradient_new(); + REQUIRE(gradient != NULL); + + REQUIRE(tvg_gradient_set_color_stops(gradient, color_stops, 2) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_gradient_get_color_stops(gradient, &color_stops_ret, + &color_stops_count_ret) == TVG_RESULT_SUCCESS); + + REQUIRE(color_stops_ret != NULL); + REQUIRE(color_stops_count_ret == 2); + + REQUIRE(tvg_gradient_set_color_stops(gradient, NULL, 0) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_gradient_get_color_stops(gradient, &color_stops_ret, + &color_stops_count_ret) == TVG_RESULT_SUCCESS); + + REQUIRE(color_stops_ret == NULL); + REQUIRE(color_stops_count_ret == 0); + + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Set/Get gradient spread", "[capiLinearGradient]") +{ + Tvg_Gradient *gradient = NULL; + Tvg_Stroke_Fill spread = TVG_STROKE_FILL_REPEAT; + + gradient = tvg_linear_gradient_new(); + REQUIRE(gradient != NULL); + + REQUIRE(tvg_gradient_set_spread(gradient, TVG_STROKE_FILL_PAD) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_gradient_get_spread(gradient, &spread) == TVG_RESULT_SUCCESS); + + REQUIRE(spread == TVG_STROKE_FILL_PAD); + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); + + gradient = NULL; + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_INVALID_ARGUMENT); +} \ No newline at end of file diff --git a/test/meson.build b/test/meson.build index f4cfcf6a..962cc7e7 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,6 +3,7 @@ test_file = [ 'testInitializer.cpp', 'testSwCanvas.cpp', 'testSwCanvasBase.cpp', + 'capi/testLinearGradient.cpp' ] tests = executable('tvgUnitTests',