From ae44d03eee2ddca75ccc7d794b0d2e5a5bab9f39 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 16 Jun 2021 12:51:07 +0900 Subject: [PATCH 01/16] tset capi: code refactoring. revise coding style. --- test/capi/capiInitializer.cpp | 4 +- test/capi/capiPaint.cpp | 131 ++++++++++++++++++++---------------------- test/capi/capiShape.cpp | 91 +++++++++++++---------------- test/capi/capiSwCanvas.cpp | 13 ++--- 4 files changed, 109 insertions(+), 130 deletions(-) diff --git a/test/capi/capiInitializer.cpp b/test/capi/capiInitializer.cpp index 2ac4e03..e7cf9ef 100644 --- a/test/capi/capiInitializer.cpp +++ b/test/capi/capiInitializer.cpp @@ -25,6 +25,6 @@ TEST_CASE("Basic capi initialization", "[capiInitializer]") { - REQUIRE(tvg_engine_init(TVG_ENGINE_SW | TVG_ENGINE_GL, 0) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_engine_term(TVG_ENGINE_SW | TVG_ENGINE_GL) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); } diff --git a/test/capi/capiPaint.cpp b/test/capi/capiPaint.cpp index 697d0b3..27eb6b9 100644 --- a/test/capi/capiPaint.cpp +++ b/test/capi/capiPaint.cpp @@ -52,20 +52,19 @@ TEST_CASE("Paint Translate", "[capiPaintTranslate]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - Tvg_Matrix matrix_get; - float tx = 20, ty = 30; - - REQUIRE(tvg_paint_translate(paint, tx, ty) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_transform(paint, &matrix_get) == TVG_RESULT_SUCCESS); - REQUIRE(fabs(matrix_get.e11 - 1.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e12 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e13 - tx) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e21 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e22 - 1.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e23 - ty) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e31 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e32 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e33 - 1.0f) < UTC_EPSILON); + Tvg_Matrix matrix; + + REQUIRE(tvg_paint_translate(paint, 20, 30) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS); + REQUIRE(fabs(matrix.e11 - 1.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e12 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e13 - 20) < UTC_EPSILON); + REQUIRE(fabs(matrix.e21 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e22 - 1.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e23 - 30) < UTC_EPSILON); + REQUIRE(fabs(matrix.e31 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e32 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e33 - 1.0f) < UTC_EPSILON); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -75,20 +74,19 @@ TEST_CASE("Paint Scale", "[capiPaintScale]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - Tvg_Matrix matrix_get; - float scale = 2.5f; + Tvg_Matrix matrix; - REQUIRE(tvg_paint_scale(paint, scale) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_transform(paint, &matrix_get) == TVG_RESULT_SUCCESS); - REQUIRE(fabs(matrix_get.e11 - scale) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e12 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e13 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e21 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e22 - scale) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e23 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e31 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e32 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e33 - 1.0f) < UTC_EPSILON); + REQUIRE(tvg_paint_scale(paint, 2.5f) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS); + REQUIRE(fabs(matrix.e11 - 2.5f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e12 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e13 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e21 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e22 - 2.5f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e23 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e31 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e32 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e33 - 1.0f) < UTC_EPSILON); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -98,20 +96,19 @@ TEST_CASE("Paint Rotate", "[capiPaintRotate]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - Tvg_Matrix matrix_get; - float degree = 180.0f; + Tvg_Matrix matrix; - REQUIRE(tvg_paint_rotate(paint, degree) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_transform(paint, &matrix_get) == TVG_RESULT_SUCCESS); - REQUIRE(fabs(matrix_get.e11 - -1.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e12 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e13 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e21 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e22 - -1.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e23 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e31 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e32 - 0.0f) < UTC_EPSILON); - REQUIRE(fabs(matrix_get.e33 - 1.0f) < UTC_EPSILON); + REQUIRE(tvg_paint_rotate(paint, 180.0f) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS); + REQUIRE(fabs(matrix.e11 - -1.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e12 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e13 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e21 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e22 - -1.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e23 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e31 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e32 - 0.0f) < UTC_EPSILON); + REQUIRE(fabs(matrix.e33 - 1.0f) < UTC_EPSILON); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -121,22 +118,19 @@ TEST_CASE("Paint Opacity", "[capiPaintOpacity]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - uint8_t opacity_set, opacity_get; + uint8_t opacity; - opacity_set = 0; - REQUIRE(tvg_paint_set_opacity(paint, opacity_set) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_opacity(paint, &opacity_get) == TVG_RESULT_SUCCESS); - REQUIRE(opacity_get == opacity_get); + REQUIRE(tvg_paint_set_opacity(paint, 0) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_opacity(paint, &opacity) == TVG_RESULT_SUCCESS); + REQUIRE(0 == opacity); - opacity_set = 128; - REQUIRE(tvg_paint_set_opacity(paint, opacity_set) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_opacity(paint, &opacity_get) == TVG_RESULT_SUCCESS); - REQUIRE(opacity_get == opacity_get); + REQUIRE(tvg_paint_set_opacity(paint, 128) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_opacity(paint, &opacity) == TVG_RESULT_SUCCESS); + REQUIRE(128 == opacity); - opacity_set = 255; - REQUIRE(tvg_paint_set_opacity(paint, opacity_set) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_opacity(paint, &opacity_get) == TVG_RESULT_SUCCESS); - REQUIRE(opacity_get == opacity_get); + REQUIRE(tvg_paint_set_opacity(paint, 255) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_opacity(paint, &opacity) == TVG_RESULT_SUCCESS); + REQUIRE(255 == opacity); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -146,27 +140,26 @@ TEST_CASE("Paint Bounds", "[capiPaintBounds]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - float x = 0, y = 10, w = 20, h = 100; - float x_get, y_get, w_get, h_get; + float x, y, w, h; - REQUIRE(tvg_shape_append_rect(paint, x, y, w, h, 0, 0) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_bounds(paint, &x_get, &y_get, &w_get, &h_get) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_append_rect(paint, 0, 10, 20, 100, 0, 0) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_bounds(paint, &x, &y, &w, &h) == TVG_RESULT_SUCCESS); - REQUIRE(x == x_get); - REQUIRE(y == y_get); - REQUIRE(w == w_get); - REQUIRE(h == h_get); + REQUIRE(x == 0); + REQUIRE(y == 10); + REQUIRE(w == 20); + REQUIRE(h == 100); REQUIRE(tvg_shape_reset(paint) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_move_to(paint, x, y) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_line_to(paint, x + w, y + h) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_paint_get_bounds(paint, &x_get, &y_get, &w_get, &h_get) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_move_to(paint, 0, 10) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_line_to(paint, 20, 110) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_get_bounds(paint, &x, &y, &w, &h) == TVG_RESULT_SUCCESS); - REQUIRE(x == x_get); - REQUIRE(y == y_get); - REQUIRE(w == w_get); - REQUIRE(h == h_get); + REQUIRE(x == 0); + REQUIRE(y == 10); + REQUIRE(w == 20); + REQUIRE(h == 100); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); -} +} \ No newline at end of file diff --git a/test/capi/capiShape.cpp b/test/capi/capiShape.cpp index 0554cd3..65f7838 100644 --- a/test/capi/capiShape.cpp +++ b/test/capi/capiShape.cpp @@ -96,17 +96,15 @@ TEST_CASE("Stroke width", "[capiStrokeWidth]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - float stroke_set, stroke_get; + float stroke; - stroke_set = 0.0f; - REQUIRE(tvg_shape_set_stroke_width(paint, stroke_set) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_width(paint, &stroke_get) == TVG_RESULT_SUCCESS); - REQUIRE(stroke_get == stroke_get); + REQUIRE(tvg_shape_set_stroke_width(paint, 0.0f) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_width(paint, &stroke) == TVG_RESULT_SUCCESS); + REQUIRE(stroke == 0.0f); - stroke_set = 5.0f; - REQUIRE(tvg_shape_set_stroke_width(paint, stroke_set) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_width(paint, &stroke_get) == TVG_RESULT_SUCCESS); - REQUIRE(stroke_get == stroke_get); + REQUIRE(tvg_shape_set_stroke_width(paint, 5.0f) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_width(paint, &stroke) == TVG_RESULT_SUCCESS); + REQUIRE(stroke == 5.0f); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -116,15 +114,14 @@ TEST_CASE("Stroke color", "[capiStrokeColor]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - uint8_t r = 255, g = 255, b = 255, a = 255; - uint8_t r_get, g_get, b_get, a_get; + uint8_t r, g, b, a; - REQUIRE(tvg_shape_set_stroke_color(paint, r, g, b, a) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_color(paint, &r_get, &g_get, &b_get, &a_get) == TVG_RESULT_SUCCESS); - REQUIRE(r == r_get); - REQUIRE(g == g_get); - REQUIRE(b == b_get); - REQUIRE(a == a_get); + REQUIRE(tvg_shape_set_stroke_color(paint, 100, 200, 50, 1) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_color(paint, &r, &g, &b, &a) == TVG_RESULT_SUCCESS); + REQUIRE(r == 100); + REQUIRE(g == 200); + REQUIRE(b == 50); + REQUIRE(a == 1); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -134,15 +131,15 @@ TEST_CASE("Stroke dash", "[capiStrokeDash]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - float dashPattern[2] = {20, 10}; - float* dashPattern_get; + float dash[2] = {20, 10}; + float* dash_get; uint32_t cnt; - REQUIRE(tvg_shape_set_stroke_dash(paint, dashPattern, 2) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_dash(paint, (const float**) &dashPattern_get, &cnt) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_set_stroke_dash(paint, dash, 2) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_dash(paint, (const float**) &dash_get, &cnt) == TVG_RESULT_SUCCESS); REQUIRE(cnt == 2); for (uint32_t i = 0; i < cnt; i++) { - REQUIRE(dashPattern_get[i] == dashPattern[i]); + REQUIRE(dash_get[i] == dash[i]); } REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); @@ -153,17 +150,15 @@ TEST_CASE("Stroke cap", "[capiStrokeCap]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - Tvg_Stroke_Cap cap, cap_get; + Tvg_Stroke_Cap cap; - cap = TVG_STROKE_CAP_ROUND; - REQUIRE(tvg_shape_set_stroke_cap(paint, cap) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_cap(paint, &cap_get) == TVG_RESULT_SUCCESS); - REQUIRE(cap == cap_get); + REQUIRE(tvg_shape_set_stroke_cap(paint, TVG_STROKE_CAP_ROUND) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_cap(paint, &cap) == TVG_RESULT_SUCCESS); + REQUIRE(cap == TVG_STROKE_CAP_ROUND); - cap = TVG_STROKE_CAP_BUTT; - REQUIRE(tvg_shape_set_stroke_cap(paint, cap) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_cap(paint, &cap_get) == TVG_RESULT_SUCCESS); - REQUIRE(cap == cap_get); + REQUIRE(tvg_shape_set_stroke_cap(paint, TVG_STROKE_CAP_BUTT) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_cap(paint, &cap) == TVG_RESULT_SUCCESS); + REQUIRE(cap == TVG_STROKE_CAP_BUTT); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -173,17 +168,15 @@ TEST_CASE("Stroke join", "[capiStrokeJoin]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - Tvg_Stroke_Join join, join_get; + Tvg_Stroke_Join join; - join = TVG_STROKE_JOIN_BEVEL; - REQUIRE(tvg_shape_set_stroke_join(paint, join) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_join(paint, &join_get) == TVG_RESULT_SUCCESS); - REQUIRE(join == join_get); + REQUIRE(tvg_shape_set_stroke_join(paint, TVG_STROKE_JOIN_BEVEL) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_join(paint, &join) == TVG_RESULT_SUCCESS); + REQUIRE(join == TVG_STROKE_JOIN_BEVEL); - join = TVG_STROKE_JOIN_MITER; - REQUIRE(tvg_shape_set_stroke_join(paint, join) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_join(paint, &join_get) == TVG_RESULT_SUCCESS); - REQUIRE(join == join_get); + REQUIRE(tvg_shape_set_stroke_join(paint, TVG_STROKE_JOIN_MITER) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_join(paint, &join) == TVG_RESULT_SUCCESS); + REQUIRE(join == TVG_STROKE_JOIN_MITER); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -193,15 +186,14 @@ TEST_CASE("Fill color", "[capiFillColor]") Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); - uint8_t r = 255, g = 255, b = 255, a = 255; - uint8_t r_get, g_get, b_get, a_get; + uint8_t r, g, b, a; - REQUIRE(tvg_shape_set_fill_color(paint, r, g, b, a) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_fill_color(paint, &r_get, &g_get, &b_get, &a_get) == TVG_RESULT_SUCCESS); - REQUIRE(r == r_get); - REQUIRE(g == g_get); - REQUIRE(b == b_get); - REQUIRE(a == a_get); + REQUIRE(tvg_shape_set_fill_color(paint, 129, 190, 57, 20) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_fill_color(paint, &r, &g, &b, &a) == TVG_RESULT_SUCCESS); + REQUIRE(r == 129); + REQUIRE(g == 190); + REQUIRE(b == 57); + REQUIRE(a == 20); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -224,5 +216,4 @@ TEST_CASE("Fill rule", "[capiFillRule]") REQUIRE(rule == rule_get); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); -} - +} \ No newline at end of file diff --git a/test/capi/capiSwCanvas.cpp b/test/capi/capiSwCanvas.cpp index b784ba6..2bb85cb 100644 --- a/test/capi/capiSwCanvas.cpp +++ b/test/capi/capiSwCanvas.cpp @@ -25,10 +25,7 @@ TEST_CASE("Canvas initialization", "[capiCanvas]") { - static uint32_t width = 200; - static uint32_t height = 200; - - uint32_t* buffer = (uint32_t*) malloc(sizeof(uint32_t) * width * height); + uint32_t* buffer = (uint32_t*) malloc(sizeof(uint32_t) * 200 * 200); REQUIRE(buffer); REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS); @@ -36,13 +33,11 @@ TEST_CASE("Canvas initialization", "[capiCanvas]") Tvg_Canvas* canvas = tvg_swcanvas_create(); REQUIRE(canvas); - REQUIRE(tvg_swcanvas_set_target(canvas, buffer, width, width, height, TVG_COLORSPACE_ARGB8888) == TVG_RESULT_SUCCESS); - - REQUIRE(tvg_canvas_draw(canvas) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_canvas_sync(canvas) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_swcanvas_set_target(canvas, buffer, 200, 200, 200, TVG_COLORSPACE_ARGB8888) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_canvas_clear(canvas, true) == TVG_RESULT_SUCCESS); REQUIRE(tvg_canvas_destroy(canvas) == TVG_RESULT_SUCCESS); REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); } + +//TODO: ++ more apis verification. \ No newline at end of file -- 2.7.4 From d8aaac1bdc07848c3748990f8532b6ca557257fe Mon Sep 17 00:00:00 2001 From: Michal Maciola Date: Wed, 16 Jun 2021 11:15:08 +0200 Subject: [PATCH 02/16] utc capi: added capiSwCanvas test cases --- test/capi/capiSwCanvas.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/test/capi/capiSwCanvas.cpp b/test/capi/capiSwCanvas.cpp index 2bb85cb..a0b9992 100644 --- a/test/capi/capiSwCanvas.cpp +++ b/test/capi/capiSwCanvas.cpp @@ -23,7 +23,29 @@ #include #include "../catch.hpp" -TEST_CASE("Canvas initialization", "[capiCanvas]") +TEST_CASE("Canvas missing initialization", "[capiSwCanvas]") +{ + Tvg_Canvas* canvas = tvg_swcanvas_create(); + REQUIRE(!canvas); +} + +TEST_CASE("Basic canvas", "[capiSwCanvas]") +{ + REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS); + + Tvg_Canvas* canvas = tvg_swcanvas_create(); + REQUIRE(canvas); + + Tvg_Canvas* canvas2 = tvg_swcanvas_create(); + REQUIRE(canvas2); + + REQUIRE(tvg_canvas_destroy(canvas) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_canvas_destroy(canvas2) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Canvas initialization", "[capiSwCanvas]") { uint32_t* buffer = (uint32_t*) malloc(sizeof(uint32_t) * 200 * 200); REQUIRE(buffer); @@ -40,4 +62,45 @@ TEST_CASE("Canvas initialization", "[capiCanvas]") REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); } -//TODO: ++ more apis verification. \ No newline at end of file +TEST_CASE("Canvas draw", "[capiSwCanvas]") +{ + uint32_t* buffer = (uint32_t*) malloc(sizeof(uint32_t) * 200 * 200); + REQUIRE(buffer); + + REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS); + + Tvg_Canvas* canvas = tvg_swcanvas_create(); + REQUIRE(canvas); + + REQUIRE(tvg_canvas_draw(canvas) == TVG_RESULT_INSUFFICIENT_CONDITION); + REQUIRE(tvg_canvas_sync(canvas) == TVG_RESULT_INSUFFICIENT_CONDITION); + + REQUIRE(tvg_swcanvas_set_target(canvas, buffer, 200, 200, 200, TVG_COLORSPACE_ARGB8888) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_draw(canvas) == TVG_RESULT_INSUFFICIENT_CONDITION); + REQUIRE(tvg_canvas_sync(canvas) == TVG_RESULT_INSUFFICIENT_CONDITION); + + Tvg_Paint* paint = tvg_shape_new(); + REQUIRE(paint); + + REQUIRE(tvg_canvas_push(canvas, paint) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_draw(canvas) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_canvas_sync(canvas) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_canvas_clear(canvas, true) == TVG_RESULT_SUCCESS); + + Tvg_Paint* paint2 = tvg_shape_new(); + REQUIRE(paint); + + REQUIRE(tvg_shape_append_rect(paint2, 0, 0, 100, 100, 0, 0) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_set_fill_color(paint2, 255, 255, 255, 255) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_push(canvas, paint2) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_draw(canvas) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_canvas_sync(canvas) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_destroy(canvas) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); +} -- 2.7.4 From e247749424d3be05b70857968588d5b60310b811 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Wed, 16 Jun 2021 15:54:12 +0200 Subject: [PATCH 03/16] svg_loader: adding check if stroke-dasharray attribute != none The stroke-dasharray value equal to "none" was causing a segfault during a conversion to float. Fixed now. --- src/loaders/svg/tvgSvgLoader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index 175fb20..6f0bcb6 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -236,6 +236,8 @@ _PARSE_TAG(SvgFillRule, fillRule, FillRule, fillRuleTags, SvgFillRule::Winding) static inline void _parseDashArray(const char *str, SvgDash* dash) { + if (!strncmp(str, "none", 4)) return; + char *end = nullptr; while (*str) { -- 2.7.4 From a814e7d068a8213a95f7be053923dde00609fafe Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Wed, 16 Jun 2021 16:16:02 +0200 Subject: [PATCH 04/16] svg_loader: after reading an unsupported style attribute no other values were loaded After finding an unsupported style attribute the log is printed (on request) and processing of other values continues. --- src/loaders/svg/tvgXmlParser.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/loaders/svg/tvgXmlParser.cpp b/src/loaders/svg/tvgXmlParser.cpp index 6694842..b3bc069 100644 --- a/src/loaders/svg/tvgXmlParser.cpp +++ b/src/loaders/svg/tvgXmlParser.cpp @@ -503,7 +503,14 @@ bool simpleXmlParseW3CAttribute(const char* buf, simpleXMLAttributeCb func, cons } if (key[0]) { - if (!func((void*)data, key, val)) return false; + +#ifdef THORVG_LOG_ENABLED + if (!func((void*)data, key, val)) { + if (!_isIgnoreUnsupportedLogAttributes(key, val)) printf("SVG: Unsupported attributes used [Elements type: %s][Id : %s][Attribute: %s][Value: %s]\n", simpleXmlNodeTypeToString(((SvgLoaderData*)data)->svgParse->node->type).c_str(), ((SvgLoaderData*)data)->svgParse->node->id ? ((SvgLoaderData*)data)->svgParse->node->id->c_str() : "NO_ID", key, val ? val : "NONE"); + } +#else + func((void*)data, key, val); +#endif } buf = next + 1; -- 2.7.4 From 8b1f82eec2a242e4f11ce26b189f484d4326573a Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 17 Jun 2021 01:12:57 +0200 Subject: [PATCH 05/16] svg_loader: fixing color parsing For colors given in a style attribute in the format "rgb(rrr, ggg, bbb)" a parsing was incorect. Now fixed. --- src/loaders/svg/tvgSvgLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index 6f0bcb6..9e8f0a7 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -277,7 +277,7 @@ static unsigned char _parserColor(const char* value, char** end) { float r; - r = svgUtilStrtof(value + 4, end); + r = svgUtilStrtof(value, end); *end = _skipSpace(*end, nullptr); if (**end == '%') r = 255 * r / 100; *end = _skipSpace(*end, nullptr); -- 2.7.4 From 58798c6f9ab783257cf06a8a4468a7d6f5487399 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 17 Jun 2021 01:30:45 +0200 Subject: [PATCH 06/16] svg_loader: key and value in the simpleXmlParseW3CAttribute needed to be cleared out of spaces --- src/loaders/svg/tvgXmlParser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/loaders/svg/tvgXmlParser.cpp b/src/loaders/svg/tvgXmlParser.cpp index b3bc069..8ee5dcd 100644 --- a/src/loaders/svg/tvgXmlParser.cpp +++ b/src/loaders/svg/tvgXmlParser.cpp @@ -503,6 +503,10 @@ bool simpleXmlParseW3CAttribute(const char* buf, simpleXMLAttributeCb func, cons } if (key[0]) { + key = const_cast(_simpleXmlSkipWhiteSpace(key, key + strlen(key))); + key[_simpleXmlUnskipWhiteSpace(key + strlen(key) , key) - key] = '\0'; + val = const_cast(_simpleXmlSkipWhiteSpace(val, val + strlen(val))); + val[_simpleXmlUnskipWhiteSpace(val + strlen(val) , val) - val] = '\0'; #ifdef THORVG_LOG_ENABLED if (!func((void*)data, key, val)) { -- 2.7.4 From 8eecf899ccb5c1d00c69c77ec8719dfdc2b49989 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Thu, 17 Jun 2021 12:04:12 +0900 Subject: [PATCH 07/16] common Scene: return FailedAllocation if it really failed at memory allocation. Due to change of f0ecc67, the return type of reserve() is changed to bool, which can return the result for the fail case. --- src/lib/tvgScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/tvgScene.cpp b/src/lib/tvgScene.cpp index 873053b..afe67d1 100644 --- a/src/lib/tvgScene.cpp +++ b/src/lib/tvgScene.cpp @@ -56,7 +56,7 @@ Result Scene::push(unique_ptr paint) noexcept Result Scene::reserve(uint32_t size) noexcept { - pImpl->paints.reserve(size); + if (!pImpl->paints.reserve(size)) return Result::FailedAllocation; return Result::Success; } -- 2.7.4 From 27b33077277b7a299f57a2c675b0e0f09cdfafd9 Mon Sep 17 00:00:00 2001 From: Michal Szczecinski Date: Fri, 4 Jun 2021 13:17:25 +0200 Subject: [PATCH 08/16] utc capi: Added radial gradient tests. --- test/capi/testRadialGradient.cpp | 160 +++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 161 insertions(+) create mode 100644 test/capi/testRadialGradient.cpp diff --git a/test/capi/testRadialGradient.cpp b/test/capi/testRadialGradient.cpp new file mode 100644 index 0000000..125d32f --- /dev/null +++ b/test/capi/testRadialGradient.cpp @@ -0,0 +1,160 @@ +/* + * 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", "[capiRadialGradient]") +{ + Tvg_Gradient *gradient = NULL; + gradient = tvg_radial_gradient_new(); + REQUIRE(gradient != NULL); + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Set gradient center point and radius", "[capiRadialGradient]") +{ + Tvg_Gradient *gradient = NULL; + float cx = 0.0, cy = 0.0, radius = 0.0; + + gradient = tvg_radial_gradient_new(); + + REQUIRE(gradient != NULL); + REQUIRE(tvg_radial_gradient_set(gradient, 10.0, 15.0, 30.0) == TVG_RESULT_SUCCESS); + + 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(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Set gradient in shape", "[capiRadialGradient]") +{ + Tvg_Paint *shape = NULL; + Tvg_Gradient *gradient = NULL; + + REQUIRE(tvg_shape_set_radial_gradient(shape, gradient) == TVG_RESULT_INVALID_ARGUMENT); + + gradient = tvg_radial_gradient_new(); + REQUIRE(gradient != NULL); + REQUIRE(tvg_shape_set_radial_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_radial_gradient(shape, gradient) == TVG_RESULT_MEMORY_CORRUPTION); + REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Set/Get color stops", "[capiRadialGradient]") +{ + 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_radial_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", "[capiRadialGradient]") +{ + 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_radial_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", "[capiRadialGradient]") +{ + Tvg_Gradient *gradient = NULL; + Tvg_Stroke_Fill spread = TVG_STROKE_FILL_REPEAT; + + gradient = tvg_radial_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 d349757..9054ddd 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,6 +3,7 @@ test_file = [ 'testInitializer.cpp', 'testSwCanvas.cpp', 'testSwCanvasBase.cpp', + 'capi/testRadialGradient.cpp' ] tests = executable('tvgUnitTests', -- 2.7.4 From 626411c81291c0bab799bfe45a3daf0371abcdc2 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 17 Jun 2021 14:38:27 +0900 Subject: [PATCH 09/16] test capi: code refactoring. keep the coding consistency, no logical changes. --- ...stRadialGradient.cpp => capiRadialGradient.cpp} | 102 ++++++++------------- test/capi/meson.build | 1 + test/meson.build | 3 +- 3 files changed, 41 insertions(+), 65 deletions(-) rename test/capi/{testRadialGradient.cpp => capiRadialGradient.cpp} (65%) diff --git a/test/capi/testRadialGradient.cpp b/test/capi/capiRadialGradient.cpp similarity index 65% rename from test/capi/testRadialGradient.cpp rename to test/capi/capiRadialGradient.cpp index 125d32f..608f41a 100644 --- a/test/capi/testRadialGradient.cpp +++ b/test/capi/capiRadialGradient.cpp @@ -21,26 +21,22 @@ */ #include -#include "catch.hpp" +#include "../catch.hpp" TEST_CASE("Basic Create", "[capiRadialGradient]") { - Tvg_Gradient *gradient = NULL; - gradient = tvg_radial_gradient_new(); - REQUIRE(gradient != NULL); + Tvg_Gradient *gradient = tvg_radial_gradient_new(); + REQUIRE(gradient); REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); } TEST_CASE("Set gradient center point and radius", "[capiRadialGradient]") { - Tvg_Gradient *gradient = NULL; - float cx = 0.0, cy = 0.0, radius = 0.0; - - gradient = tvg_radial_gradient_new(); - - REQUIRE(gradient != NULL); + Tvg_Gradient *gradient = tvg_radial_gradient_new(); + REQUIRE(gradient); REQUIRE(tvg_radial_gradient_set(gradient, 10.0, 15.0, 30.0) == TVG_RESULT_SUCCESS); + float cx, cy, radius; REQUIRE(tvg_radial_gradient_get(gradient, &cx, &cy, &radius) == TVG_RESULT_SUCCESS); REQUIRE(cx == 10.0); REQUIRE(cy == 15.0); @@ -51,47 +47,39 @@ TEST_CASE("Set gradient center point and radius", "[capiRadialGradient]") TEST_CASE("Set gradient in shape", "[capiRadialGradient]") { - Tvg_Paint *shape = NULL; - Tvg_Gradient *gradient = NULL; + REQUIRE(tvg_shape_set_radial_gradient(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT); + + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape); - REQUIRE(tvg_shape_set_radial_gradient(shape, gradient) == TVG_RESULT_INVALID_ARGUMENT); - - gradient = tvg_radial_gradient_new(); - REQUIRE(gradient != NULL); - REQUIRE(tvg_shape_set_radial_gradient(shape, gradient) == TVG_RESULT_INVALID_ARGUMENT); + Tvg_Gradient *gradient = tvg_radial_gradient_new(); + REQUIRE(gradient); - shape = tvg_shape_new(); - REQUIRE(shape != NULL); + REQUIRE(tvg_shape_set_radial_gradient(NULL, gradient) == TVG_RESULT_INVALID_ARGUMENT); REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); - gradient = NULL; - REQUIRE(tvg_shape_set_radial_gradient(shape, gradient) == TVG_RESULT_MEMORY_CORRUPTION); + REQUIRE(tvg_shape_set_radial_gradient(shape, NULL) == TVG_RESULT_MEMORY_CORRUPTION); REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); } TEST_CASE("Set/Get color stops", "[capiRadialGradient]") { - Tvg_Paint *shape = NULL; - Tvg_Gradient *gradient = NULL; + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape); - Tvg_Color_Stop color_stops[2] = - { + Tvg_Gradient *gradient = tvg_radial_gradient_new(); + REQUIRE(gradient); + + 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_radial_gradient_new(); - REQUIRE(gradient != NULL); + const Tvg_Color_Stop *color_stops_ret; + uint32_t color_stops_count_ret; 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); @@ -104,36 +92,27 @@ TEST_CASE("Set/Get color stops", "[capiRadialGradient]") TEST_CASE("Clear gradient data", "[capiRadialGradient]") { - Tvg_Paint *shape = NULL; - Tvg_Gradient *gradient = NULL; + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape); + + Tvg_Gradient *gradient = tvg_radial_gradient_new(); + REQUIRE(gradient); - Tvg_Color_Stop color_stops[2] = - { + 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_radial_gradient_new(); - REQUIRE(gradient != NULL); + const Tvg_Color_Stop *color_stops_ret; + uint32_t color_stops_count_ret; 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(tvg_gradient_get_color_stops(gradient, &color_stops_ret, &color_stops_count_ret) == TVG_RESULT_SUCCESS); + REQUIRE(color_stops_ret); 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(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); @@ -143,18 +122,15 @@ TEST_CASE("Clear gradient data", "[capiRadialGradient]") TEST_CASE("Set/Get gradient spread", "[capiRadialGradient]") { - Tvg_Gradient *gradient = NULL; - Tvg_Stroke_Fill spread = TVG_STROKE_FILL_REPEAT; - - gradient = tvg_radial_gradient_new(); - REQUIRE(gradient != NULL); + Tvg_Gradient *gradient = tvg_radial_gradient_new(); + REQUIRE(gradient); REQUIRE(tvg_gradient_set_spread(gradient, TVG_STROKE_FILL_PAD) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_gradient_get_spread(gradient, &spread) == TVG_RESULT_SUCCESS); + Tvg_Stroke_Fill spread; + 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); + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_gradient_del(NULL) == TVG_RESULT_INVALID_ARGUMENT); } \ No newline at end of file diff --git a/test/capi/meson.build b/test/capi/meson.build index 2826462..d84ba93 100644 --- a/test/capi/meson.build +++ b/test/capi/meson.build @@ -3,6 +3,7 @@ test_file = [ 'capiFill.cpp', 'capiMain.cpp', 'capiPaint.cpp', + 'capiRadialGradient.cpp', 'capiShape.cpp', 'capiSwCanvas.cpp', ] diff --git a/test/meson.build b/test/meson.build index 9054ddd..f4cfcf6 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,7 +3,6 @@ test_file = [ 'testInitializer.cpp', 'testSwCanvas.cpp', 'testSwCanvasBase.cpp', - 'capi/testRadialGradient.cpp' ] tests = executable('tvgUnitTests', @@ -15,4 +14,4 @@ test('Unit Tests', tests) if get_option('bindings').contains('capi') == true subdir('capi') -endif \ No newline at end of file +endif -- 2.7.4 From e2c3ecec6803de709a6e2e737e8b14fc4ac930bd Mon Sep 17 00:00:00 2001 From: Michal Szczecinski Date: Fri, 4 Jun 2021 13:17:25 +0200 Subject: [PATCH 10/16] 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 0000000..52c4965 --- /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 f4cfcf6..962cc7e 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', -- 2.7.4 From 1d3688f66e6e4ca87c8bbaa1bf60b9fe27ddb8d7 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 17 Jun 2021 14:57:06 +0900 Subject: [PATCH 11/16] test capi: code refactoring. keep the coding consistency, no logical changes. Also, renamed tests to avoid conflicts duplicated names. --- ...stLinearGradient.cpp => capiLinearGradient.cpp} | 106 ++++++++------------- test/capi/meson.build | 1 + test/meson.build | 1 - 3 files changed, 42 insertions(+), 66 deletions(-) rename test/capi/{testLinearGradient.cpp => capiLinearGradient.cpp} (63%) diff --git a/test/capi/testLinearGradient.cpp b/test/capi/capiLinearGradient.cpp similarity index 63% rename from test/capi/testLinearGradient.cpp rename to test/capi/capiLinearGradient.cpp index 52c4965..317da58 100644 --- a/test/capi/testLinearGradient.cpp +++ b/test/capi/capiLinearGradient.cpp @@ -21,26 +21,23 @@ */ #include -#include "catch.hpp" +#include "../catch.hpp" -TEST_CASE("Basic Create", "[capiLinearGradient]") +TEST_CASE("Linear Gradient Basic Create", "[capiLinearGradient]") { - Tvg_Gradient *gradient = NULL; - gradient = tvg_linear_gradient_new(); - REQUIRE(gradient != NULL); + Tvg_Gradient *gradient = tvg_linear_gradient_new(); + REQUIRE(gradient); REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); } -TEST_CASE("Set gradient start and end position", "[capiLinearGradient]") +TEST_CASE("Linear 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(); + Tvg_Gradient *gradient = tvg_linear_gradient_new(); - REQUIRE(gradient != NULL); + REQUIRE(gradient); REQUIRE(tvg_linear_gradient_set(gradient, 10.0, 20.0, 50.0, 40.0) == TVG_RESULT_SUCCESS); - + + float x1, y1, x2, y2; REQUIRE(tvg_linear_gradient_get(gradient, &x1, &y1, &x2, &y2) == TVG_RESULT_SUCCESS); REQUIRE(x1 == 10.0); REQUIRE(y1 == 20.0); @@ -50,31 +47,30 @@ TEST_CASE("Set gradient start and end position", "[capiLinearGradient]") REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); } -TEST_CASE("Set gradient in shape", "[capiLinearGradient]") +TEST_CASE("Linear Gradient in shape", "[capiLinearGradient]") { - Tvg_Paint *shape = NULL; - Tvg_Gradient *gradient = NULL; + REQUIRE(tvg_shape_set_linear_gradient(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT); - 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); + Tvg_Gradient *gradient = tvg_linear_gradient_new(); + REQUIRE(gradient); + REQUIRE(tvg_shape_set_linear_gradient(NULL, gradient) == TVG_RESULT_INVALID_ARGUMENT); - shape = tvg_shape_new(); - REQUIRE(shape != NULL); + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape); REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); - gradient = NULL; - REQUIRE(tvg_shape_set_linear_gradient(shape, gradient) == TVG_RESULT_MEMORY_CORRUPTION); + REQUIRE(tvg_shape_set_linear_gradient(shape, NULL) == TVG_RESULT_MEMORY_CORRUPTION); REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); } -TEST_CASE("Set/Get color stops", "[capiLinearGradient]") +TEST_CASE("Linear Gradient color stops", "[capiLinearGradient]") { - Tvg_Paint *shape = NULL; - Tvg_Gradient *gradient = NULL; + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape); + + Tvg_Gradient *gradient = tvg_linear_gradient_new(); + REQUIRE(gradient); Tvg_Color_Stop color_stops[2] = { @@ -82,20 +78,12 @@ TEST_CASE("Set/Get color stops", "[capiLinearGradient]") {.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); + const Tvg_Color_Stop *color_stops_ret; + uint32_t color_stops_count_ret; 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); @@ -103,10 +91,13 @@ TEST_CASE("Set/Get color stops", "[capiLinearGradient]") REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); } -TEST_CASE("Clear gradient data", "[capiLinearGradient]") +TEST_CASE("Linear Gradient clear data", "[capiLinearGradient]") { - Tvg_Paint *shape = NULL; - Tvg_Gradient *gradient = NULL; + Tvg_Paint *shape = tvg_shape_new(); + REQUIRE(shape != NULL); + + Tvg_Gradient *gradient = tvg_linear_gradient_new(); + REQUIRE(gradient != NULL); Tvg_Color_Stop color_stops[2] = { @@ -117,24 +108,13 @@ TEST_CASE("Clear gradient data", "[capiLinearGradient]") 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(tvg_gradient_get_color_stops(gradient, &color_stops_ret, &color_stops_count_ret) == TVG_RESULT_SUCCESS); + REQUIRE(color_stops_ret); 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(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); @@ -142,20 +122,16 @@ TEST_CASE("Clear gradient data", "[capiLinearGradient]") REQUIRE(tvg_paint_del(shape) == TVG_RESULT_SUCCESS); } -TEST_CASE("Set/Get gradient spread", "[capiLinearGradient]") +TEST_CASE("Linear Gradient spread", "[capiLinearGradient]") { - Tvg_Gradient *gradient = NULL; - Tvg_Stroke_Fill spread = TVG_STROKE_FILL_REPEAT; - - gradient = tvg_linear_gradient_new(); - REQUIRE(gradient != NULL); + Tvg_Gradient *gradient = tvg_linear_gradient_new(); + REQUIRE(gradient); + Tvg_Stroke_Fill spread; 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 + REQUIRE(tvg_gradient_del(gradient) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_gradient_del(NULL) == TVG_RESULT_INVALID_ARGUMENT); +} diff --git a/test/capi/meson.build b/test/capi/meson.build index d84ba93..b344526 100644 --- a/test/capi/meson.build +++ b/test/capi/meson.build @@ -1,6 +1,7 @@ test_file = [ 'capiInitializer.cpp', 'capiFill.cpp', + 'capiLinearGradient.cpp', 'capiMain.cpp', 'capiPaint.cpp', 'capiRadialGradient.cpp', diff --git a/test/meson.build b/test/meson.build index 962cc7e..f4cfcf6 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,7 +3,6 @@ test_file = [ 'testInitializer.cpp', 'testSwCanvas.cpp', 'testSwCanvasBase.cpp', - 'capi/testLinearGradient.cpp' ] tests = executable('tvgUnitTests', -- 2.7.4 From d19317ec80e657d2991a6b555734781821b7cdee Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Thu, 17 Jun 2021 17:07:52 +0900 Subject: [PATCH 12/16] infra CI: Fix test flag of test build test -> tests --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index d680a16..629da8a 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -64,6 +64,6 @@ jobs: - name: Build run: | - meson . build -Dtest=true --errorlogs + meson . build -Dtests=true --errorlogs cd build sudo ninja -C . install test -- 2.7.4 From 7331d2e34ce91a02c7c4a2747a16bd856897c4ca Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Thu, 17 Jun 2021 17:31:41 +0900 Subject: [PATCH 13/16] infra CI: Upload unit test result to artifact Users can download the unit test result list from PR-> Checks -> Build Test -> Artifacts. --- .github/workflows/actions.yml | 9 +++++++-- test/meson.build | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 629da8a..863ef10 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -24,7 +24,7 @@ jobs: cd build sudo ninja -C . install - example_build: + examples: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 @@ -43,7 +43,7 @@ jobs: cd build sudo ninja -C . install - test_build: + unit_test: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 @@ -67,3 +67,8 @@ jobs: meson . build -Dtests=true --errorlogs cd build sudo ninja -C . install test + + - uses: actions/upload-artifact@v2 + with: + name: UnitTestReport + path: build/meson-logs/testlog.txt diff --git a/test/meson.build b/test/meson.build index f4cfcf6..ab0b7f5 100644 --- a/test/meson.build +++ b/test/meson.build @@ -10,7 +10,7 @@ tests = executable('tvgUnitTests', include_directories : headers, link_with : thorvg_lib) -test('Unit Tests', tests) +test('Unit Tests', tests, args : ['--success']) if get_option('bindings').contains('capi') == true subdir('capi') -- 2.7.4 From 4c90fc86c076a3435528b28739de278947dbaa1b Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Thu, 17 Jun 2021 15:39:41 +0900 Subject: [PATCH 14/16] test Scene: Add tvg::Scene unit tests - Creation - Push - Reserve - Clear --- test/meson.build | 1 + test/testScene.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 test/testScene.cpp diff --git a/test/meson.build b/test/meson.build index ab0b7f5..263a8af 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,6 +1,7 @@ test_file = [ 'testMain.cpp', 'testInitializer.cpp', + 'testScene.cpp', 'testSwCanvas.cpp', 'testSwCanvasBase.cpp', ] diff --git a/test/testScene.cpp b/test/testScene.cpp new file mode 100644 index 0000000..cc98a24 --- /dev/null +++ b/test/testScene.cpp @@ -0,0 +1,99 @@ +/* + * 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" + +using namespace tvg; + +TEST_CASE("Scene Creation", "[tvgScene]") +{ + auto scene = Scene::gen(); + REQUIRE(scene); +} + +TEST_CASE("Pushing Paints Into Scene", "[tvgScene]") +{ + auto scene = Scene::gen(); + REQUIRE(scene); + + REQUIRE(scene->push(move(Shape::gen())) == Result::Success); + REQUIRE(scene->push(move(Picture::gen())) == Result::Success); + REQUIRE(scene->push(move(Scene::gen())) == Result::Success); + + //Negative case 1 + REQUIRE(scene->push(nullptr) == Result::MemoryCorruption); + + //Negative case 2 + std::unique_ptr shape = nullptr; + REQUIRE(scene->push(move(shape)) == Result::MemoryCorruption); +} + +TEST_CASE("Scene Memory Reservation", "[tvgScene]") +{ + auto scene = Scene::gen(); + REQUIRE(scene); + + REQUIRE(scene->reserve(10) == Result::Success); + REQUIRE(scene->reserve(1000) == Result::Success); + REQUIRE(scene->reserve(100) == Result::Success); + REQUIRE(scene->reserve(0) == Result::Success); + + REQUIRE(scene->reserve(-1) == Result::FailedAllocation); +} + +TEST_CASE("Scene Clear", "[tvgScene]") +{ + auto scene = Scene::gen(); + REQUIRE(scene); + + REQUIRE(scene->push(move(Shape::gen())) == Result::Success); + REQUIRE(scene->clear() == Result::Success); +} + +TEST_CASE("Scene Clear And Reuse Shape", "[tvgScene]") +{ + REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success); + + auto canvas = SwCanvas::gen(); + REQUIRE(canvas); + + auto scene = Scene::gen(); + REQUIRE(scene); + Scene *pScene = scene.get(); + + auto shape = Shape::gen(); + REQUIRE(shape); + Shape* pShape = shape.get(); + + REQUIRE(scene->push(move(shape)) == Result::Success); + REQUIRE(canvas->push(move(scene)) == Result::Success); + REQUIRE(canvas->update(nullptr) == Result::Success); + + //No deallocate shape. + REQUIRE(pScene->clear(false) == Result::Success); + + //Reuse shape. + REQUIRE(pScene->push(std::unique_ptr(pShape)) == Result::Success); + + REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success); +} -- 2.7.4 From 1686bb909fbe51fa306fb1acb8064a40d9895a94 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Fri, 18 Jun 2021 00:53:49 +0200 Subject: [PATCH 15/16] svg_loader: radial gradient transformation support For now the gradient radius is scales like x-axis - it has to be changed after issue #37 will be resolved. --- src/loaders/svg/tvgSvgLoader.cpp | 2 ++ src/loaders/svg/tvgSvgSceneBuilder.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index 9e8f0a7..8c3afb6 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -1870,6 +1870,8 @@ static bool _attrParseRadialGradientNode(void* data, const char* key, const char grad->ref = _idFromHref(value); } else if (!strcmp(key, "gradientUnits") && !strcmp(value, "userSpaceOnUse")) { grad->userSpace = true; + } else if (!strcmp(key, "gradientTransform")) { + grad->transform = _parseTransformationMatrix(value); } else { return false; } diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index 445c667..6c6b52f 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -114,8 +114,15 @@ static unique_ptr _applyRadialGradientProperty(SvgStyleGradient* g->radial->fy = g->radial->fy * rh + ry; } - //TODO: Radial gradient transformation is not yet supported. - //if (g->transform) {} + //TODO: Radial gradient transformation - all tests possible after rx/ry implementation + if (g->transform) { + auto cx = g->radial->cx * g->transform->e11 + g->radial->cy * g->transform->e12 + g->transform->e13; + g->radial->cy = g->radial->cx * g->transform->e21 + g->radial->cy * g->transform->e22 + g->transform->e23; + g->radial->cx = cx; + + auto sx = sqrt(pow(g->transform->e11, 2) + pow(g->transform->e21, 2)); + g->radial->r *= sx; + } //TODO: Tvg is not support to focal //if (g->radial->fx != 0 && g->radial->fy != 0) { -- 2.7.4 From 8e8de74276326f7a17ee1460f1fc5d7689b96144 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 21 Jun 2021 12:00:13 +0900 Subject: [PATCH 16/16] bump up version Change-Id: I7ab9e0002ba57626f502878ccae23e4c3fc8af6a --- packaging/thorvg.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/thorvg.spec b/packaging/thorvg.spec index eaea879..0b6a98a 100644 --- a/packaging/thorvg.spec +++ b/packaging/thorvg.spec @@ -1,6 +1,6 @@ Name: thorvg Summary: Thor Vector Graphics Library -Version: 0.2.0 +Version: 0.2.1 Release: 1 Group: Graphics System/Rendering Engine License: MIT -- 2.7.4