diff --git a/meson.build b/meson.build index 8cff0aa2..3673c53d 100644 --- a/meson.build +++ b/meson.build @@ -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) diff --git a/meson_options.txt b/meson_options.txt index d784bb28..b14e3b59 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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') diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 00000000..61286fc0 --- /dev/null +++ b/test/meson.build @@ -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) diff --git a/test/test_canvas.cpp b/test/test_canvas.cpp new file mode 100644 index 00000000..e74ac89b --- /dev/null +++ b/test/test_canvas.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +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 swCanvas; + tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw; +}; + +TEST_F(CanvasTest, GenerateCanvas) { + ASSERT_TRUE(swCanvas != nullptr); +} + diff --git a/test/testsuite.cpp b/test/testsuite.cpp new file mode 100644 index 00000000..5633721c --- /dev/null +++ b/test/testsuite.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} +