test Canvas: Set up unit test based on gtest.

In test directory, set up unit_test based on gtest
First, add a test for SwCanvas generate.
This commit is contained in:
JunsuChoi 2020-10-29 19:45:21 +09:00 committed by Hermet Park
parent d4e9450ec1
commit 9859a48714
5 changed files with 65 additions and 0 deletions

View file

@ -38,16 +38,22 @@ headers = [include_directories('inc'), include_directories('.')]
subdir('inc')
subdir('src')
if get_option('test') == true
subdir('test')
endif
summary = '''
Summary:
thorvg version : @0@
Build type : @1@
Prefix : @2@
Test : @3@
'''.format(
meson.project_version(),
get_option('buildtype'),
get_option('prefix'),
get_option('test'),
)
message(summary)

View file

@ -32,3 +32,8 @@ option('examples',
type: 'boolean',
value: false,
description: 'Enable building examples')
option('test',
type: 'boolean',
value: false,
description: 'Enable building unit tests')

19
test/meson.build Normal file
View file

@ -0,0 +1,19 @@
#TODO:Need to change warning level to 3
override_default = ['warning_level=0', 'werror=false']
gtest_dep = dependency('gtest')
canvas_test_sources = [
'testsuite.cpp',
'test_canvas.cpp',
]
canvas_testsuite = executable('canvasTestSuite',
canvas_test_sources,
include_directories : headers,
override_options : override_default,
dependencies : [gtest_dep, thorvg_lib_dep],
)
test('Canvas Testsuite', canvas_testsuite)

28
test/test_canvas.cpp Normal file
View file

@ -0,0 +1,28 @@
#include <gtest/gtest.h>
#include <iostream>
#include <thread>
#include <thorvg.h>
class CanvasTest : public ::testing::Test {
public:
void SetUp() {
auto threads = std::thread::hardware_concurrency();
//Initialize ThorVG Engine
if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
swCanvas = tvg::SwCanvas::gen();
}
}
void TearDown() {
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
}
public:
std::unique_ptr<tvg::SwCanvas> swCanvas;
tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
};
TEST_F(CanvasTest, GenerateCanvas) {
ASSERT_TRUE(swCanvas != nullptr);
}

7
test/testsuite.cpp Normal file
View file

@ -0,0 +1,7 @@
#include <gtest/gtest.h>
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}