test: fix broken plugin support.

The thorvg test should not attempt to perform features
that were not enabled, as this will cause them to fail.

@Issues: https://github.com/thorvg/thorvg/issues/1251
This commit is contained in:
Hermet Park 2023-04-06 19:34:07 +09:00
parent 9102f66948
commit f0ae3e9cee
22 changed files with 455 additions and 224 deletions

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"
TEST_CASE("Basic capi initialization", "[capiInitializer]")

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"
TEST_CASE("Linear Gradient Basic Create", "[capiLinearGradient]")

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"

View file

@ -22,9 +22,51 @@
#include <thorvg_capi.h>
#include <string.h>
#include "config.h"
#include "../catch.hpp"
TEST_CASE("Load Raw file in Picture", "[capiPicture]")
{
Tvg_Paint* picture = tvg_picture_new();
REQUIRE(picture);
//Load Raw Data
FILE* fp = fopen(TEST_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_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
REQUIRE(w == Approx(200).epsilon(0.0000001));
REQUIRE(h == Approx(300).epsilon(0.0000001));
float wNew = 500.0f, hNew = 500.0f;
REQUIRE(tvg_picture_set_size(picture, wNew, hNew) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_picture_get_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
REQUIRE(w == Approx(wNew).epsilon(0.0000001));
REQUIRE(h == Approx(hNew).epsilon(0.0000001));
}
REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS);
fclose(fp);
free(data);
}
#ifdef THORVG_SVG_LOADER_SUPPORT
TEST_CASE("Load Svg file in Picture", "[capiPicture]")
{
Tvg_Paint* picture = tvg_picture_new();
@ -87,44 +129,9 @@ TEST_CASE("Load Svg Data in Picture", "[capiPicture]")
REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS);
}
TEST_CASE("Load Raw file in Picture", "[capiPicture]")
{
Tvg_Paint* picture = tvg_picture_new();
REQUIRE(picture);
#endif
//Load Raw Data
FILE* fp = fopen(TEST_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_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
REQUIRE(w == Approx(200).epsilon(0.0000001));
REQUIRE(h == Approx(300).epsilon(0.0000001));
float wNew = 500.0f, hNew = 500.0f;
REQUIRE(tvg_picture_set_size(picture, wNew, hNew) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_picture_get_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
REQUIRE(w == Approx(wNew).epsilon(0.0000001));
REQUIRE(h == Approx(hNew).epsilon(0.0000001));
}
REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS);
fclose(fp);
free(data);
}
#ifdef THORVG_PNG_LOADER_SUPPORT
TEST_CASE("Load Png file in Picture", "[capiPicture]")
{
@ -147,3 +154,5 @@ TEST_CASE("Load Png file in Picture", "[capiPicture]")
REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS);
}
#endif

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"
TEST_CASE("Basic Create", "[capiRadialGradient]")

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"
@ -33,6 +34,8 @@ TEST_CASE("Create and delete a Saver", "[capiSaver]")
REQUIRE(tvg_saver_del(saver) == TVG_RESULT_SUCCESS);
}
#ifdef THORVG_TVG_SAVER_SUPPORT
TEST_CASE("Save a paint into a file", "[capiSaver]")
{
Tvg_Saver* saver = tvg_saver_new();
@ -97,3 +100,5 @@ TEST_CASE("Synchronize a Saver", "[capiSaver]")
REQUIRE(tvg_saver_del(saver) == TVG_RESULT_SUCCESS);
}
#endif

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"
TEST_CASE("Create a Scene", "[capiScene]")

View file

@ -21,6 +21,7 @@
*/
#include <thorvg_capi.h>
#include "config.h"
#include "../catch.hpp"
TEST_CASE("Multiple shapes", "[capiShapes]")

View file

@ -23,6 +23,8 @@
#include <thorvg_capi.h>
#include "../catch.hpp"
#ifdef THORVG_SW_RASTER_SUPPORT
TEST_CASE("Canvas missing initialization", "[capiSwCanvas]")
{
Tvg_Canvas* canvas = tvg_swcanvas_create();
@ -150,3 +152,5 @@ TEST_CASE("Canvas update, clear and reuse", "[capiSwCanvas]")
REQUIRE(tvg_engine_term(TVG_ENGINE_SW) == TVG_RESULT_SUCCESS);
}
#endif

File diff suppressed because one or more lines are too long

View file

@ -21,10 +21,10 @@
*/
#include <thorvg.h>
#include "config.h"
#include "catch.hpp"
using namespace tvg;
#include <stdio.h>
TEST_CASE("Accessor Creation", "[tvgAccessor]")
{
@ -35,6 +35,7 @@ TEST_CASE("Accessor Creation", "[tvgAccessor]")
REQUIRE(accessor2);
}
#ifdef THORVG_SVG_LOADER_SUPPORT
TEST_CASE("Set", "[tvgAccessor]")
{
@ -75,3 +76,5 @@ TEST_CASE("Set", "[tvgAccessor]")
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
#endif

View file

@ -21,7 +21,7 @@
*/
#include <thorvg.h>
#include <memory>
#include "config.h"
#include "catch.hpp"
using namespace tvg;

View file

@ -21,6 +21,7 @@
*/
#include <thorvg.h>
#include "config.h"
#include "catch.hpp"
using namespace tvg;

View file

@ -21,6 +21,7 @@
*/
#include <thorvg.h>
#include "config.h"
#include "catch.hpp"
using namespace tvg;

View file

@ -21,8 +21,9 @@
*/
#include <thorvg.h>
#include <string.h>
#include <fstream>
#include <cstring>
#include "config.h"
#include "catch.hpp"
using namespace tvg;
@ -39,49 +40,12 @@ TEST_CASE("Picture Creation", "[tvgPicture]")
REQUIRE(picture->identifier() != Scene::identifier());
}
TEST_CASE("Load SVG file", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
//Invalid file
REQUIRE(picture->load("invalid.svg") == Result::InvalidArguments);
//Load Svg file
REQUIRE(picture->load(TEST_DIR"/logo.svg") == Result::Success);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
}
TEST_CASE("Load SVG Data", "[tvgPicture]")
{
static const char* svg = "<svg height=\"1000\" viewBox=\"0 0 1000 1000\" width=\"1000\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M.10681413.09784845 1000.0527.01592069V1000.0851L.06005738 999.9983Z\" fill=\"#ffffff\" stroke-width=\"3.910218\"/><g fill=\"#252f35\"><g stroke-width=\"3.864492\"><path d=\"M256.61221 100.51736H752.8963V386.99554H256.61221Z\"/><path d=\"M201.875 100.51736H238.366478V386.99554H201.875Z\"/><path d=\"M771.14203 100.51736H807.633508V386.99554H771.14203Z\"/></g><path d=\"M420.82388 380H588.68467V422.805317H420.82388Z\" stroke-width=\"3.227\"/><path d=\"m420.82403 440.7101v63.94623l167.86079 25.5782V440.7101Z\"/><path d=\"M420.82403 523.07258V673.47362L588.68482 612.59701V548.13942Z\"/></g><g fill=\"#222f35\"><path d=\"M420.82403 691.37851 588.68482 630.5019 589 834H421Z\"/><path d=\"m420.82403 852.52249h167.86079v28.64782H420.82403v-28.64782 0 0\"/><path d=\"m439.06977 879.17031c0 0-14.90282 8.49429-18.24574 15.8161-4.3792 9.59153 0 31.63185 0 31.63185h167.86079c0 0 4.3792-22.04032 0-31.63185-3.34292-7.32181-18.24574-15.8161-18.24574-15.8161z\"/></g><g fill=\"#ffffff\"><path d=\"m280 140h15v55l8 10 8-10v-55h15v60l-23 25-23-25z\"/><path d=\"m335 140v80h45v-50h-25v10h10v30h-15v-57h18v-13z\"/></g></svg>";
auto picture = Picture::gen();
REQUIRE(picture);
//Negative cases
REQUIRE(picture->load(nullptr, 100, "") == Result::InvalidArguments);
REQUIRE(picture->load(svg, 0, "") == Result::InvalidArguments);
//Positive cases
REQUIRE(picture->load(svg, strlen(svg), "svg") == Result::Success);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000);
REQUIRE(h == 1000);
}
TEST_CASE("Load RAW Data", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
string path(TEST_DIR"/rawimage_200x300.raw");
ifstream file(path);
ifstream file(TEST_DIR"/rawimage_200x300.raw");
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
@ -106,14 +70,42 @@ TEST_CASE("Load RAW Data", "[tvgPicture]")
free(data);
}
TEST_CASE("Load RAW file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
ifstream file(TEST_DIR"/rawimage_200x300.raw");
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
if (!data) return;
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
file.close();
REQUIRE(picture->load(data, 200, 300, false) == Result::Success);
REQUIRE(picture->size(100, 150) == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
free(data);
}
TEST_CASE("Texture mesh", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
string path(TEST_DIR"/rawimage_200x300.raw");
ifstream file(path);
ifstream file(TEST_DIR"/rawimage_200x300.raw");
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
@ -169,6 +161,140 @@ TEST_CASE("Texture mesh", "[tvgPicture]")
free(data);
}
TEST_CASE("Picture Size", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::InsufficientCondition);
//Primary
ifstream file(TEST_DIR"/rawimage_200x300.raw");
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
file.close();
REQUIRE(picture->load(data, 200, 300, false) == Result::Success);
REQUIRE(picture->size(nullptr, nullptr) == Result::Success);
REQUIRE(picture->size(100, 100) == Result::Success);
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 100);
REQUIRE(h == 100);
free(data);
//Secondary
ifstream file2(TEST_DIR"/rawimage_250x375.raw");
if (!file2.is_open()) return;
data = (uint32_t*)malloc(sizeof(uint32_t) * (250*375));
file2.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 250 * 375);
file2.close();
REQUIRE(picture->load(data, 250, 375, false) == Result::Success);
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(picture->size(w, h) == Result::Success);
free(data);
}
TEST_CASE("Picture Duplication", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
//Primary
ifstream file(TEST_DIR"/rawimage_200x300.raw");
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
file.close();
REQUIRE(picture->load(data, 200, 300, false) == Result::Success);
REQUIRE(picture->size(100, 100) == Result::Success);
auto dup = unique_ptr<Picture>((Picture*)picture->duplicate());
REQUIRE(dup);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 100);
REQUIRE(h == 100);
free(data);
}
#ifdef THORVG_SVG_LOADER_SUPPORT
TEST_CASE("Load SVG file", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
//Invalid file
REQUIRE(picture->load("invalid.svg") == Result::InvalidArguments);
//Load Svg file
REQUIRE(picture->load(TEST_DIR"/logo.svg") == Result::Success);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
}
TEST_CASE("Load SVG Data", "[tvgPicture]")
{
static const char* svg = "<svg height=\"1000\" viewBox=\"0 0 1000 1000\" width=\"1000\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M.10681413.09784845 1000.0527.01592069V1000.0851L.06005738 999.9983Z\" fill=\"#ffffff\" stroke-width=\"3.910218\"/><g fill=\"#252f35\"><g stroke-width=\"3.864492\"><path d=\"M256.61221 100.51736H752.8963V386.99554H256.61221Z\"/><path d=\"M201.875 100.51736H238.366478V386.99554H201.875Z\"/><path d=\"M771.14203 100.51736H807.633508V386.99554H771.14203Z\"/></g><path d=\"M420.82388 380H588.68467V422.805317H420.82388Z\" stroke-width=\"3.227\"/><path d=\"m420.82403 440.7101v63.94623l167.86079 25.5782V440.7101Z\"/><path d=\"M420.82403 523.07258V673.47362L588.68482 612.59701V548.13942Z\"/></g><g fill=\"#222f35\"><path d=\"M420.82403 691.37851 588.68482 630.5019 589 834H421Z\"/><path d=\"m420.82403 852.52249h167.86079v28.64782H420.82403v-28.64782 0 0\"/><path d=\"m439.06977 879.17031c0 0-14.90282 8.49429-18.24574 15.8161-4.3792 9.59153 0 31.63185 0 31.63185h167.86079c0 0 4.3792-22.04032 0-31.63185-3.34292-7.32181-18.24574-15.8161-18.24574-15.8161z\"/></g><g fill=\"#ffffff\"><path d=\"m280 140h15v55l8 10 8-10v-55h15v60l-23 25-23-25z\"/><path d=\"m335 140v80h45v-50h-25v10h10v30h-15v-57h18v-13z\"/></g></svg>";
auto picture = Picture::gen();
REQUIRE(picture);
//Negative cases
REQUIRE(picture->load(nullptr, 100, "") == Result::InvalidArguments);
REQUIRE(picture->load(svg, 0, "") == Result::InvalidArguments);
//Positive cases
REQUIRE(picture->load(svg, strlen(svg), "svg") == Result::Success);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000);
REQUIRE(h == 1000);
}
TEST_CASE("Load SVG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
auto buffer = new uint32_t[1000*1000];
if (!buffer) return;
REQUIRE(canvas->target(buffer, 1000, 1000, 1000, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/tag.svg") == Result::Success);
REQUIRE(picture->size(100, 100) == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(canvas->draw() == Result::Success);
REQUIRE(canvas->sync() == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
delete[] buffer;
}
#endif
#ifdef THORVG_PNG_LOADER_SUPPORT
TEST_CASE("Load PNG file from path", "[tvgPicture]")
{
auto picture = Picture::gen();
@ -210,6 +336,32 @@ TEST_CASE("Load PNG file from data", "[tvgPicture]")
free(data);
}
TEST_CASE("Load PNG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(picture->opacity(192) == Result::Success);
REQUIRE(picture->scale(5.0) == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
#endif
#ifdef THORVG_JPG_LOADER_SUPPORT
TEST_CASE("Load JPG file from path", "[tvgPicture]")
{
auto picture = Picture::gen();
@ -254,6 +406,30 @@ TEST_CASE("Load JPG file from data", "[tvgPicture]")
free(data);
}
TEST_CASE("Load JPG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
#endif
#ifdef THORVG_TVG_LOADER_SUPPORT
TEST_CASE("Load TVG file from path", "[tvgPicture]")
{
auto picture = Picture::gen();
@ -298,113 +474,6 @@ TEST_CASE("Load TVG file from data", "[tvgPicture]")
free(data);
}
TEST_CASE("Picture Size", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::InsufficientCondition);
REQUIRE(picture->load(TEST_DIR"/logo.svg") == Result::Success);
REQUIRE(picture->size(nullptr, nullptr) == Result::Success);
REQUIRE(picture->size(100, 100) == Result::Success);
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 100);
REQUIRE(h == 100);
REQUIRE(picture->load(TEST_DIR"/tiger.svg") == Result::Success);
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(picture->size(w, h) == Result::Success);
}
TEST_CASE("Picture Duplication", "[tvgPicture]")
{
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/logo.svg") == Result::Success);
REQUIRE(picture->size(100, 100) == Result::Success);
auto dup = unique_ptr<Picture>((Picture*)picture->duplicate());
REQUIRE(dup);
float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 100);
REQUIRE(h == 100);
}
TEST_CASE("Load SVG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
auto buffer = new uint32_t[1000*1000];
if (!buffer) return;
REQUIRE(canvas->target(buffer, 1000, 1000, 1000, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/tag.svg") == Result::Success);
REQUIRE(picture->size(100, 100) == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(canvas->draw() == Result::Success);
REQUIRE(canvas->sync() == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
delete[] buffer;
}
TEST_CASE("Load PNG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(picture->opacity(192) == Result::Success);
REQUIRE(picture->scale(5.0) == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
TEST_CASE("Load JPG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
TEST_CASE("Load TVG file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
@ -432,34 +501,4 @@ TEST_CASE("Load TVG file and render", "[tvgPicture]")
delete[] buffer;
}
TEST_CASE("Load RAW file and render", "[tvgPicture]")
{
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
auto canvas = SwCanvas::gen();
REQUIRE(canvas);
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
auto picture = Picture::gen();
REQUIRE(picture);
string path(TEST_DIR"/rawimage_200x300.raw");
ifstream file(path);
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
if (!data) return;
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
file.close();
REQUIRE(picture->load(data, 200, 300, false) == Result::Success);
REQUIRE(picture->size(100, 150) == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
free(data);
}
#endif

View file

@ -21,9 +21,12 @@
*/
#include <thorvg.h>
#include <fstream>
#include "config.h"
#include "catch.hpp"
using namespace tvg;
using namespace std;
TEST_CASE("Saver Creation", "[tvgSavers]")
{
@ -31,6 +34,8 @@ TEST_CASE("Saver Creation", "[tvgSavers]")
REQUIRE(saver);
}
#ifdef THORVG_TVG_SAVER_SUPPORT
TEST_CASE("Save empty shape", "[tvgSavers]")
{
auto shape = Shape::gen();
@ -65,7 +70,14 @@ TEST_CASE("Save scene into tvg", "[tvgSavers]")
auto picture = tvg::Picture::gen();
REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success);
ifstream file(TEST_DIR"/rawimage_200x300.raw");
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
file.close();
REQUIRE(picture->load(data, 200, 300, false) == Result::Success);
REQUIRE(picture->translate(50, 0) == Result::Success);
REQUIRE(picture->scale(2) == Result::Success);
@ -81,4 +93,8 @@ TEST_CASE("Save scene into tvg", "[tvgSavers]")
REQUIRE(saver->sync() == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
free(data);
}
#endif

View file

@ -21,6 +21,7 @@
*/
#include <thorvg.h>
#include "config.h"
#include "catch.hpp"
using namespace tvg;

View file

@ -21,6 +21,7 @@
*/
#include <thorvg.h>
#include "config.h"
#include "catch.hpp"
using namespace tvg;

View file

@ -21,6 +21,7 @@
*/
#include <thorvg.h>
#include "config.h"
#include "catch.hpp"
using namespace tvg;

View file

@ -21,6 +21,7 @@
*/
#include <thorvg.h>
#include "config.h"
#include "catch.hpp"
using namespace tvg;

View file

@ -21,10 +21,14 @@
*/
#include <thorvg.h>
#include <fstream>
#include "config.h"
#include "catch.hpp"
using namespace tvg;
using namespace std;
#ifdef THORVG_SW_RASTER_SUPPORT
TEST_CASE("Basic draw", "[tvgSwEngine]")
{
@ -100,11 +104,17 @@ TEST_CASE("Image Draw", "[tvgSwEngine]")
uint32_t buffer[100*100];
REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
//raw image
ifstream file(TEST_DIR"/rawimage_200x300.raw");
if (!file.is_open()) return;
auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
file.close();
//Not transformed images
auto basicPicture = Picture::gen();
REQUIRE(basicPicture);
REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(basicPicture->load(data, 200, 300, false) == Result::Success);
auto rectMask = tvg::Shape::gen();
REQUIRE(rectMask);
REQUIRE(rectMask->appendRect(10, 10, 30, 30, 0, 0) == Result::Success);
@ -160,7 +170,8 @@ TEST_CASE("Image Draw", "[tvgSwEngine]")
// Transformed images
basicPicture = Picture::gen();
REQUIRE(basicPicture);
REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(basicPicture->load(data, 200, 300, false) == Result::Success);
REQUIRE(basicPicture->rotate(45) == Result::Success);
rectMask = tvg::Shape::gen();
REQUIRE(rectMask);
@ -217,7 +228,7 @@ TEST_CASE("Image Draw", "[tvgSwEngine]")
// Upscaled images
basicPicture = Picture::gen();
REQUIRE(basicPicture);
REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(basicPicture->load(data, 200, 300, false) == Result::Success);
REQUIRE(basicPicture->scale(2) == Result::Success);
rectMask = tvg::Shape::gen();
REQUIRE(rectMask);
@ -274,7 +285,7 @@ TEST_CASE("Image Draw", "[tvgSwEngine]")
// Downscaled images
basicPicture = Picture::gen();
REQUIRE(basicPicture);
REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(basicPicture->load(data, 200, 300, false) == Result::Success);
REQUIRE(basicPicture->scale(0.2f) == Result::Success);
rectMask = tvg::Shape::gen();
REQUIRE(rectMask);
@ -332,6 +343,8 @@ TEST_CASE("Image Draw", "[tvgSwEngine]")
REQUIRE(canvas->sync() == Result::Success);
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
free(data);
}
@ -995,3 +1008,5 @@ TEST_CASE("RLE Filling ClipPath", "[tvgSwEngine]")
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
}
#endif