test capi: code refactoring.
authorHermet Park <chuneon.park@samsung.com>
Thu, 17 Jun 2021 05:57:06 +0000 (14:57 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Mon, 21 Jun 2021 02:39:34 +0000 (11:39 +0900)
keep the coding consistency, no logical changes.

Also, renamed tests to avoid conflicts duplicated names.

test/capi/capiLinearGradient.cpp [moved from test/capi/testLinearGradient.cpp with 63% similarity]
test/capi/meson.build
test/meson.build

similarity index 63%
rename from test/capi/testLinearGradient.cpp
rename to test/capi/capiLinearGradient.cpp
index 52c4965..317da58 100644 (file)
  */
 
 #include <thorvg_capi.h>
-#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);
+}
index d84ba93..b344526 100644 (file)
@@ -1,6 +1,7 @@
 test_file = [
    'capiInitializer.cpp',
    'capiFill.cpp',
+   'capiLinearGradient.cpp',
    'capiMain.cpp',
    'capiPaint.cpp',
    'capiRadialGradient.cpp',
index 962cc7e..f4cfcf6 100644 (file)
@@ -3,7 +3,6 @@ test_file = [
     'testInitializer.cpp',
     'testSwCanvas.cpp',
     'testSwCanvasBase.cpp',
-    'capi/testLinearGradient.cpp'
 ]
 
 tests = executable('tvgUnitTests',