From 58ad09a07a50f00f7272a0cbae7bae7c9c3065ed Mon Sep 17 00:00:00 2001 From: Michal Maciola <71131832+mmaciola@users.noreply.github.com> Date: Thu, 15 Jul 2021 17:34:54 +0200 Subject: [PATCH] test capi: added missing canvas, paint and shape tests Added tests for tvg_canvas_reserve, tvg_canvas_update_paint, tvg_paint_duplicate, tvg_paint_set_composite_method, tvg_shape_cubic_to, tvg_shape_close --- test/capi/capiPaint.cpp | 65 ++++++++++++++++++++++++++++++++++---- test/capi/capiShape.cpp | 50 ++++++++++++++++++++++++++++- test/capi/capiSwCanvas.cpp | 42 ++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 8 deletions(-) diff --git a/test/capi/capiPaint.cpp b/test/capi/capiPaint.cpp index dced66c1..0ec9c609 100644 --- a/test/capi/capiPaint.cpp +++ b/test/capi/capiPaint.cpp @@ -24,7 +24,7 @@ #include "../catch.hpp" -TEST_CASE("Paint Transform", "[capiPaintTransform]") +TEST_CASE("Paint Transform", "[capiPaint]") { Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); @@ -46,7 +46,7 @@ TEST_CASE("Paint Transform", "[capiPaintTransform]") REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } -TEST_CASE("Paint Translate", "[capiPaintTranslate]") +TEST_CASE("Paint Translate", "[capiPaint]") { Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); @@ -68,7 +68,7 @@ TEST_CASE("Paint Translate", "[capiPaintTranslate]") REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } -TEST_CASE("Paint Scale", "[capiPaintScale]") +TEST_CASE("Paint Scale", "[capiPaint]") { Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); @@ -90,7 +90,7 @@ TEST_CASE("Paint Scale", "[capiPaintScale]") REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } -TEST_CASE("Paint Rotate", "[capiPaintRotate]") +TEST_CASE("Paint Rotate", "[capiPaint]") { Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); @@ -112,7 +112,7 @@ TEST_CASE("Paint Rotate", "[capiPaintRotate]") REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } -TEST_CASE("Paint Opacity", "[capiPaintOpacity]") +TEST_CASE("Paint Opacity", "[capiPaint]") { Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); @@ -134,7 +134,7 @@ TEST_CASE("Paint Opacity", "[capiPaintOpacity]") REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } -TEST_CASE("Paint Bounds", "[capiPaintBounds]") +TEST_CASE("Paint Bounds", "[capiPaint]") { Tvg_Paint* paint = tvg_shape_new(); REQUIRE(paint); @@ -161,4 +161,55 @@ TEST_CASE("Paint Bounds", "[capiPaintBounds]") REQUIRE(h == 100); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); -} \ No newline at end of file +} + +TEST_CASE("Paint Dupliction", "[capiPaint]") +{ + Tvg_Paint* paint = tvg_shape_new(); + REQUIRE(paint); + + REQUIRE(tvg_paint_set_opacity(paint, 0) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_paint_translate(paint, 200, 100) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_scale(paint, 2.2f) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_rotate(paint, 90.0f) == TVG_RESULT_SUCCESS); + + Tvg_Paint* paint_copy = tvg_paint_duplicate(paint); + REQUIRE(paint_copy); + + uint8_t opacity; + REQUIRE(tvg_paint_get_opacity(paint_copy, &opacity) == TVG_RESULT_SUCCESS); + REQUIRE(0 == opacity); + + Tvg_Matrix matrix; + REQUIRE(tvg_paint_get_transform(paint, &matrix) == TVG_RESULT_SUCCESS); + REQUIRE(matrix.e11 == Approx(0.0f).margin(0.000001)); + REQUIRE(matrix.e12 == Approx(-2.2f).margin(0.000001)); + REQUIRE(matrix.e13 == Approx(200.0f).margin(0.000001)); + REQUIRE(matrix.e21 == Approx(2.2f).margin(0.000001)); + REQUIRE(matrix.e22 == Approx(0.0f).margin(0.000001)); + REQUIRE(matrix.e23 == Approx(100.0f).margin(0.000001)); + REQUIRE(matrix.e31 == Approx(0.0f).margin(0.000001)); + REQUIRE(matrix.e32 == Approx(0.0f).margin(0.000001)); + REQUIRE(matrix.e33 == Approx(1.0f).margin(0.000001)); + + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_del(paint_copy) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Paint Clip Path Composite Method", "[capiPaint]") +{ + Tvg_Paint* paint = tvg_shape_new(); + REQUIRE(paint); + + Tvg_Paint* target = tvg_shape_new(); + REQUIRE(target); + + REQUIRE(tvg_paint_set_composite_method(paint, NULL, TVG_COMPOSITE_METHOD_NONE) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_set_composite_method(paint, target, TVG_COMPOSITE_METHOD_NONE) == TVG_RESULT_INVALID_ARGUMENT); + + REQUIRE(tvg_paint_set_composite_method(paint, target, TVG_COMPOSITE_METHOD_CLIP_PATH) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_set_composite_method(paint, NULL, TVG_COMPOSITE_METHOD_CLIP_PATH) == TVG_RESULT_INVALID_ARGUMENT); + + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); +} diff --git a/test/capi/capiShape.cpp b/test/capi/capiShape.cpp index 65f7838e..84172dee 100644 --- a/test/capi/capiShape.cpp +++ b/test/capi/capiShape.cpp @@ -35,6 +35,22 @@ TEST_CASE("Multiple shapes", "[capiShapes]") REQUIRE(tvg_shape_append_circle(paint, 100, 100, 0, 0) == TVG_RESULT_SUCCESS); REQUIRE(tvg_shape_append_arc(paint, 100, 100, 50, 90, 90, 0) == TVG_RESULT_SUCCESS); + //Invalid paint + REQUIRE(tvg_shape_append_rect(NULL, 0, 0, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_append_circle(NULL, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_append_arc(NULL, 0, 0, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT); + + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Shape reset", "[capiShapes]") +{ + Tvg_Paint* paint = tvg_shape_new(); + REQUIRE(paint); + + REQUIRE(tvg_shape_reset(NULL) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_reset(paint) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -88,6 +104,27 @@ TEST_CASE("Shape path", "[capiShapePath]") REQUIRE(pts_get[i].y == pts[i].y); } + //Invalid paint + REQUIRE(tvg_shape_append_path(NULL, NULL, 0, NULL, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_get_path_coords(NULL, NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT); + + REQUIRE(tvg_shape_reset(paint) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_shape_move_to(paint, 0, 10) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_line_to(paint, 100, 110) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_line_to(paint, 100, 10) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_close(paint) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_shape_move_to(paint, 100, 0) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_cubic_to(paint, 150, 0, 200, 50, 200, 100) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_close(paint) == TVG_RESULT_SUCCESS); + + //Invalid paint + REQUIRE(tvg_shape_move_to(NULL, 0, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_line_to(NULL, 0, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_cubic_to(NULL, 0, 0, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_close(NULL) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -106,6 +143,11 @@ TEST_CASE("Stroke width", "[capiStrokeWidth]") REQUIRE(tvg_shape_get_stroke_width(paint, &stroke) == TVG_RESULT_SUCCESS); REQUIRE(stroke == 5.0f); + //Invalid paint or width pointer + REQUIRE(tvg_shape_set_stroke_width(NULL, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_get_stroke_width(NULL, &stroke) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_get_stroke_width(paint, NULL) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -123,6 +165,12 @@ TEST_CASE("Stroke color", "[capiStrokeColor]") REQUIRE(b == 50); REQUIRE(a == 1); + //Invalid paint or no color pointers + REQUIRE(tvg_shape_set_stroke_color(NULL, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_get_stroke_color(NULL, &r, &g, &b, &a) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_shape_get_stroke_color(paint, &r, &g, &b, NULL) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_color(paint, NULL, NULL, NULL, &a) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } @@ -216,4 +264,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 a0b9992a..e35a8722 100644 --- a/test/capi/capiSwCanvas.cpp +++ b/test/capi/capiSwCanvas.cpp @@ -45,6 +45,25 @@ TEST_CASE("Basic canvas", "[capiSwCanvas]") REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); } +TEST_CASE("Memory Reservation", "[capiSwCanvas]") +{ + REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS); + + Tvg_Canvas* canvas = tvg_swcanvas_create(); + REQUIRE(canvas); + + REQUIRE(tvg_canvas_reserve(canvas, 1) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_canvas_reserve(canvas, 10) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_canvas_reserve(canvas, 100) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_canvas_reserve(canvas, 0) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_reserve(canvas, -1) == TVG_RESULT_FAILED_ALLOCATION); + + REQUIRE(tvg_canvas_destroy(canvas) == 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); @@ -104,3 +123,26 @@ TEST_CASE("Canvas draw", "[capiSwCanvas]") REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); } + +TEST_CASE("Canvas update, clear and reuse", "[capiSwCanvas]") +{ + REQUIRE(tvg_engine_init(TVG_ENGINE_SW, 0) == TVG_RESULT_SUCCESS); + + Tvg_Canvas* canvas = tvg_swcanvas_create(); + REQUIRE(canvas); + + Tvg_Paint* paint = tvg_shape_new(); + REQUIRE(paint); + + REQUIRE(tvg_canvas_push(canvas, paint) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_update_paint(canvas, paint) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_clear(canvas, false) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_push(canvas, paint) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_canvas_destroy(canvas) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS); +}