From efbe8c0a9e9250d7d37fb8b37fcc4770094ad040 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 12 Jun 2021 02:01:18 +0900 Subject: [PATCH] tests capi: revise the show-case & infrastructure. Change-Id: I0ea2ba3d7099bcb2a4bce052259e3e6a266eb6dc --- test/capi/{testFill.cpp => capiFill.cpp} | 62 ++++++++++++++------------------ test/capi/capiMain.cpp | 5 +++ test/capi/meson.build | 11 ++++++ test/meson.build | 6 +++- 4 files changed, 48 insertions(+), 36 deletions(-) rename test/capi/{testFill.cpp => capiFill.cpp} (54%) create mode 100644 test/capi/capiMain.cpp create mode 100644 test/capi/meson.build diff --git a/test/capi/testFill.cpp b/test/capi/capiFill.cpp similarity index 54% rename from test/capi/testFill.cpp rename to test/capi/capiFill.cpp index bbb2b94..9e2e1f8 100644 --- a/test/capi/testFill.cpp +++ b/test/capi/capiFill.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved. + * 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 @@ -21,61 +21,53 @@ */ #include -#include "catch.hpp" +#include "../catch.hpp" -#define TEST_R 120 -#define TEST_G 154 -#define TEST_B 180 -#define TEST_A 100 -TEST_CASE("Set/Get fill color", "[tvgCapiShapeFill]") +TEST_CASE("Set/Get fill color", "[capiShapeFill]") { - Tvg_Paint *paint = NULL; - paint = tvg_shape_new(); + Tvg_Paint *paint = tvg_shape_new(); + REQUIRE(paint); - uint8_t r = 0, g = 0, b = 0, a = 0; - - REQUIRE(paint != NULL); - REQUIRE(tvg_shape_set_fill_color(paint, TEST_R, TEST_G, TEST_B, TEST_A) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_set_fill_color(paint, 120, 154, 180, 100) == TVG_RESULT_SUCCESS); + uint8_t r = 0, g = 0, b = 0, a = 0; REQUIRE(tvg_shape_get_fill_color(paint, &r, &g, &b, &a) == TVG_RESULT_SUCCESS); - REQUIRE(r == TEST_R); - REQUIRE(g == TEST_G); - REQUIRE(b == TEST_B); - REQUIRE(a == TEST_A); + + REQUIRE(r == 120); + REQUIRE(g == 154); + REQUIRE(b == 180); + REQUIRE(a == 100); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } -TEST_CASE("Set/Get fill color on invalid shape", "[tvgCapiShapeFill]") +TEST_CASE("Set/Get fill color on invalid shape", "[capiShapeFill]") { - Tvg_Paint *paint = NULL; - - uint8_t r = 0, g = 0, b = 0, a = 0; + REQUIRE(tvg_shape_set_fill_color(NULL, 120, 154, 180, 100) == TVG_RESULT_INVALID_ARGUMENT); - REQUIRE(tvg_shape_set_fill_color(paint, TEST_R, TEST_G, TEST_B, TEST_A) == TVG_RESULT_INVALID_ARGUMENT); - REQUIRE(tvg_shape_get_fill_color(paint, &r, &g, &b, &a) == TVG_RESULT_INVALID_ARGUMENT); + uint8_t r, g, b, a; + REQUIRE(tvg_shape_get_fill_color(NULL, &r, &g, &b, &a) == TVG_RESULT_INVALID_ARGUMENT); } -TEST_CASE("Set/Get shape fill rule", "[tvgCapiShapeFill]") +TEST_CASE("Set/Get shape fill rule", "[capiShapeFill]") { - Tvg_Paint *paint = NULL; - Tvg_Fill_Rule rule = TVG_FILL_RULE_WINDING; + Tvg_Paint *paint = tvg_shape_new(); + REQUIRE(paint); - paint = tvg_shape_new(); - - REQUIRE(paint != NULL); REQUIRE(tvg_shape_set_fill_rule(paint, TVG_FILL_RULE_EVEN_ODD) == TVG_RESULT_SUCCESS); + + Tvg_Fill_Rule rule = TVG_FILL_RULE_WINDING; REQUIRE(tvg_shape_get_fill_rule(paint, &rule) == TVG_RESULT_SUCCESS); REQUIRE(rule == TVG_FILL_RULE_EVEN_ODD); + REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); } -TEST_CASE("Set/Get shape fill rule on invalid object", "[tvgCapiShapeFill]") +TEST_CASE("Set/Get shape fill rule on invalid object", "[capiShapeFill]") { - Tvg_Paint *paint = NULL; - Tvg_Fill_Rule rule = TVG_FILL_RULE_WINDING; + REQUIRE(tvg_shape_set_fill_rule(NULL, TVG_FILL_RULE_EVEN_ODD) == TVG_RESULT_INVALID_ARGUMENT); - REQUIRE(tvg_shape_set_fill_rule(paint, TVG_FILL_RULE_EVEN_ODD) == TVG_RESULT_INVALID_ARGUMENT); - REQUIRE(tvg_shape_get_fill_rule(paint, &rule) == TVG_RESULT_INVALID_ARGUMENT); -} \ No newline at end of file + Tvg_Fill_Rule rule; + REQUIRE(tvg_shape_get_fill_rule(NULL, &rule) == TVG_RESULT_INVALID_ARGUMENT); +} diff --git a/test/capi/capiMain.cpp b/test/capi/capiMain.cpp new file mode 100644 index 0000000..3f2c8b5 --- /dev/null +++ b/test/capi/capiMain.cpp @@ -0,0 +1,5 @@ +// The only purpose of this file is to DEFINE the catch config so it can include main() + +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file + +#include "../catch.hpp" diff --git a/test/capi/meson.build b/test/capi/meson.build new file mode 100644 index 0000000..150e3eb --- /dev/null +++ b/test/capi/meson.build @@ -0,0 +1,11 @@ +test_file = [ + 'capiMain.cpp', + 'capiFill.cpp', +] + +tests = executable('capiUnitTests', + test_file, + include_directories : headers, + link_with : thorvg_lib) + +test('Capi Unit Tests', tests) diff --git a/test/meson.build b/test/meson.build index 360f1fb..d55ecab 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,7 +3,6 @@ test_file = [ 'testInitializer.cpp', 'testSwCanvas.cpp', 'testSwCanvasBase.cpp', - 'capi/testFill.cpp', ] tests = executable('tvgUnitTests', @@ -12,3 +11,8 @@ tests = executable('tvgUnitTests', link_with : thorvg_lib) test('Unit Tests', tests) + +if get_option('bindings').contains('capi') == true + subdir('capi') +endif + -- 2.7.4