utc: testing loading and saving .tvg

Added tests of loading and saving .tvg.
Created testSavers.cpp. Created files tag.tvg and test.tvg. Minor change
in tag.svg.
This commit is contained in:
Michal Maciola 2021-09-02 14:57:22 +02:00 committed by Hermet Park
parent 5c504cbfe6
commit 3ded3e359d
6 changed files with 154 additions and 2 deletions

View file

@ -20,8 +20,8 @@
<polyline fill="none" stroke-width="10"
points="0,0 1000,0 1000,1000 0,1000" />
<line x1="0" y1="0" x2="1000" y2="0" stroke="" />
<path d="M647.5 800C692.5 786 730 786 775 800S857.5 814 902.5 800" stroke="#222f35" stroke-width="2" fill="transparent"/>
<path d="M647.5 800Q711.25 786 775 800T902.5 800" stroke="#222f35" stroke-width="2" fill="transparent"/>
<path d="M647.5 800C692.5 786 730 786 775 800S857.5 814 902.5 800" stroke="#222f35" stroke="url(#grad1)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="white"/>
<path d="M647.5 800Q711.25 786 775 800T902.5 800" stroke="#222f35" stroke="url(#grad2)" stroke-width="2" stroke-dasharray="20 10" stroke-linecap="square" stroke-linejoin="bevel" fill="white"/>
</g>
<image href="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNTAgNTAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBmaWxsPSIjMjIyZjM1IiBjeD0iNTAlIiBjeT0iNTAlIiByPSI1MCUiLz48L3N2Zz4=" height="50" width="50" x="650" y="875" />
<image href="data:image/svg+xml;utf8,%3Csvg viewBox='0 0 50 50' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle fill='%23222f35' cx='50%25' cy='50%25' r='50%25'/%3E%3C/svg%3E" height="50" width="50" x="725" y="875" />

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
test/images/tag.tvg Normal file

Binary file not shown.

BIN
test/images/test.tvg Normal file

Binary file not shown.

View file

@ -4,6 +4,7 @@ test_file = [
'testMain.cpp',
'testPaint.cpp',
'testPicture.cpp',
'testSavers.cpp',
'testScene.cpp',
'testShape.cpp',
'testSwCanvas.cpp',

View file

@ -180,6 +180,50 @@ TEST_CASE("Load JPG file from data", "[tvgPicture]")
free(data);
}
TEST_CASE("Load TVG file from path", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
//Invalid file
REQUIRE(picture->load("invalid.tvg") == Result::InvalidArguments);
REQUIRE(picture->load(TEST_DIR"/tag.tvg") == Result::Success);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000);
REQUIRE(h == 1000);
}
TEST_CASE("Load TVG file from data", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
//Open file
ifstream file(TEST_DIR"/tag.tvg");
REQUIRE(file.is_open());
auto begin = file.tellg();
file.seekg(0, std::ios::end);
auto size = file.tellg() - begin;
auto data = (char*)malloc(size);
file.seekg(0, std::ios::beg);
file.read(data, size);
file.close();
REQUIRE(picture->load(data, size, "", false) == Result::Success);
REQUIRE(picture->load(data, size, "tvg", true) == Result::Success);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000);
REQUIRE(h == 1000);
free(data);
}
TEST_CASE("Picture Size", "[tvgPicture]")
{
auto picture = Picture::gen();
@ -282,6 +326,29 @@ TEST_CASE("Load JPG file and render", "[tvgPicture]")
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
TEST_CASE("Load TVG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
uint32_t buffer[1000*1000];
REQUIRE(canvas->target(buffer, 1000, 1000, 1000, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto pictureTag = Picture::gen();
REQUIRE(pictureTag);
REQUIRE(pictureTag->load(TEST_DIR"/tag.tvg") == Result::Success);
REQUIRE(canvas->push(move(pictureTag)) == Result::Success);
auto pictureTest = Picture::gen();
REQUIRE(pictureTest);
REQUIRE(pictureTest->load(TEST_DIR"/test.tvg") == Result::Success);
REQUIRE(canvas->push(move(pictureTest)) == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
TEST_CASE("Load RAW file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);

84
test/testSavers.cpp Normal file
View file

@ -0,0 +1,84 @@
/*
* 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 <thorvg.h>
#include "catch.hpp"
using namespace tvg;
TEST_CASE("Saver Creation", "[tvgSavers]")
{
auto saver = Saver::gen();
REQUIRE(saver);
}
TEST_CASE("Save empty shape", "[tvgSavers]")
{
auto shape = Shape::gen();
REQUIRE(shape);
auto saver = Saver::gen();
REQUIRE(saver);
REQUIRE(saver->save(move(shape), TEST_DIR"/test.tvg") == Result::Unknown);
}
TEST_CASE("Save svg into tvg", "[tvgSavers]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/tag.svg") == Result::Success);
auto saver = Saver::gen();
REQUIRE(saver);
REQUIRE(saver->save(move(picture), TEST_DIR"/tag.tvg") == Result::Success);
REQUIRE(saver->sync() == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
TEST_CASE("Save scene into tvg", "[tvgSavers]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto picture = tvg::Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(picture->translate(50, 0) == Result::Success);
REQUIRE(picture->scale(2) == Result::Success);
auto mask = tvg::Shape::gen();
REQUIRE(mask);
REQUIRE(mask->appendCircle(400, 400, 15, 15) == Result::Success);
REQUIRE(mask->fill(0, 0, 0, 255) == Result::Success);
REQUIRE(picture->composite(move(mask), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
auto saver = Saver::gen();
REQUIRE(saver);
REQUIRE(saver->save(move(picture), TEST_DIR"/test.tvg") == Result::Success);
REQUIRE(saver->sync() == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}