From 009c475fc9691e101e9e09b9cfae8f06970f64ee Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 3 Jul 2021 15:28:14 +0900 Subject: [PATCH] test capi: add Picture unit test --- test/capi/capiPicture.cpp | 122 ++++++++++++++++++++++++++++++++++++++ test/capi/meson.build | 1 + 2 files changed, 123 insertions(+) create mode 100644 test/capi/capiPicture.cpp diff --git a/test/capi/capiPicture.cpp b/test/capi/capiPicture.cpp new file mode 100644 index 00000000..9cb86991 --- /dev/null +++ b/test/capi/capiPicture.cpp @@ -0,0 +1,122 @@ +/* + * 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 +#include "../catch.hpp" + + +TEST_CASE("Load Svg file in Picture", "[capiPicture]") +{ + Tvg_Paint* picture = tvg_picture_new(); + REQUIRE(picture); + + //Negative + REQUIRE(tvg_picture_load(nullptr, EXAMPLE_DIR"/logo.svg") == TVG_RESULT_INVALID_ARGUMENT); + + //Invalid file + REQUIRE(tvg_picture_load(picture, "invalid.svg") == TVG_RESULT_INVALID_ARGUMENT); + + //Load Svg file + REQUIRE(tvg_picture_load(picture, EXAMPLE_DIR"/logo.svg") == TVG_RESULT_SUCCESS); + + float x, y, w, h; + REQUIRE(tvg_picture_get_viewbox(picture, &x, &y, &w, &h) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Load Svg Data in Picture", "[capiPicture]") +{ + static const char* svg = ""; + + Tvg_Paint* picture = tvg_picture_new(); + REQUIRE(picture); + + //Negative + REQUIRE(tvg_picture_load_data(nullptr, svg, strlen(svg), true) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_picture_load_data(picture, nullptr, strlen(svg), true) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_picture_load_data(picture, svg, 0, true) == TVG_RESULT_INVALID_ARGUMENT); + + //Positive + REQUIRE(tvg_picture_load_data(picture, svg, strlen(svg), false) == TVG_RESULT_SUCCESS); + + //Verify Size + float w, h; + REQUIRE(tvg_picture_get_viewbox(picture, nullptr, nullptr, &w, &h) == TVG_RESULT_SUCCESS); + REQUIRE(w == Approx(1000).epsilon(0.0000001)); + REQUIRE(h == Approx(1000).epsilon(0.0000001)); + + REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS); +} + +TEST_CASE("Load Raw file in Picture", "[capiPicture]") +{ + Tvg_Paint* picture = tvg_picture_new(); + REQUIRE(picture); + + //Load Raw Data + FILE* fp = fopen(EXAMPLE_DIR"/rawimage_200x300.raw", "r"); + if (!fp) return; + + uint32_t* data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300)); + + if (data && fread(data, sizeof(uint32_t), 200*300, fp) > 0) { + //Negative + REQUIRE(tvg_picture_load_raw(picture, nullptr, 100, 100, true) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_picture_load_raw(nullptr, data, 200, 300, true) == TVG_RESULT_INVALID_ARGUMENT); + REQUIRE(tvg_picture_load_raw(picture, data, 0, 0, true) == TVG_RESULT_INVALID_ARGUMENT); + + //Positive + REQUIRE(tvg_picture_load_raw(picture, data, 200, 300, true) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_picture_load_raw(picture, data, 200, 300, false) == TVG_RESULT_SUCCESS); + + //Verify Size + float w, h; + REQUIRE(tvg_picture_get_viewbox(picture, nullptr, nullptr, &w, &h) == TVG_RESULT_SUCCESS); + REQUIRE(w == Approx(200).epsilon(0.0000001)); + REQUIRE(h == Approx(300).epsilon(0.0000001)); + } + + REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS); + + fclose(fp); + free(data); +} + +TEST_CASE("Load Png file in Picture", "[capiPicture]") +{ + Tvg_Paint* picture = tvg_picture_new(); + REQUIRE(picture); + + //Invalid file + REQUIRE(tvg_picture_load(picture, "invalid.png") == TVG_RESULT_INVALID_ARGUMENT); + + //Load Png file + REQUIRE(tvg_picture_load(picture, EXAMPLE_DIR"/logo.png") == TVG_RESULT_SUCCESS); + + //Verify Size + float w, h; + REQUIRE(tvg_picture_get_viewbox(picture, nullptr, nullptr, &w, &h) == TVG_RESULT_SUCCESS); + + REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS); +} \ No newline at end of file diff --git a/test/capi/meson.build b/test/capi/meson.build index b3445262..5a47f43b 100644 --- a/test/capi/meson.build +++ b/test/capi/meson.build @@ -4,6 +4,7 @@ test_file = [ 'capiLinearGradient.cpp', 'capiMain.cpp', 'capiPaint.cpp', + 'capiPicture.cpp', 'capiRadialGradient.cpp', 'capiShape.cpp', 'capiSwCanvas.cpp',