mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
tests: introduce catch2 unit tests infrastructure.
Catch2 is a multi-paradigm test framework for C++. It is primarily distributed as a single header file, very easy and simple to adopt this to thorvg project. This patch introduces catch2 infrastsructure and one prototype as a sample. You can refer "testInitializer.cpp", how to add unit test! while ignoring else files such as "catch2.hpp", "testMain.cpp" Also, enable Unit-tests with meson option when you change any thorvg code. $meson build -Dtests=true. launch tvgUnitTest in the build result then verify 100% coverage before submitting any patches.
This commit is contained in:
parent
efa0035fe6
commit
6b7aa8ad9e
6 changed files with 18028 additions and 2 deletions
12
meson.build
12
meson.build
|
@ -47,16 +47,24 @@ headers = [include_directories('inc'), include_directories('.')]
|
|||
subdir('inc')
|
||||
subdir('src')
|
||||
|
||||
if get_option('tests') == true
|
||||
subdir('test')
|
||||
endif
|
||||
|
||||
summary = '''
|
||||
|
||||
Summary:
|
||||
thorvg version : @0@
|
||||
Build type : @1@
|
||||
ThorVG version : @0@
|
||||
Build Type : @1@
|
||||
Prefix : @2@
|
||||
Tests : @3@
|
||||
Examples : @4@
|
||||
'''.format(
|
||||
meson.project_version(),
|
||||
get_option('buildtype'),
|
||||
get_option('prefix'),
|
||||
get_option('tests'),
|
||||
get_option('examples'),
|
||||
)
|
||||
|
||||
message(summary)
|
||||
|
|
|
@ -33,6 +33,11 @@ option('examples',
|
|||
value: false,
|
||||
description: 'Enable building examples')
|
||||
|
||||
option('tests',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
description: 'Enable building Unit Tests')
|
||||
|
||||
option('log',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
|
|
17937
test/catch.hpp
Normal file
17937
test/catch.hpp
Normal file
File diff suppressed because it is too large
Load diff
11
test/meson.build
Normal file
11
test/meson.build
Normal file
|
@ -0,0 +1,11 @@
|
|||
test_file = [
|
||||
'testMain.cpp',
|
||||
'testInitializer.cpp',
|
||||
]
|
||||
|
||||
tests = executable('tvgUnitTests',
|
||||
test_file,
|
||||
include_directories : headers,
|
||||
link_with : thorvg_lib)
|
||||
|
||||
test('Unit Tests', tests)
|
60
test/testInitializer.cpp
Normal file
60
test/testInitializer.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2020-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("Basic initialization", "[tvgInitializer]")
|
||||
{
|
||||
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
|
||||
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
|
||||
}
|
||||
|
||||
TEST_CASE("Multiple initialization", "[tvgInitializer]")
|
||||
{
|
||||
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
|
||||
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
|
||||
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
|
||||
|
||||
REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
|
||||
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
|
||||
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
|
||||
}
|
||||
|
||||
TEST_CASE("Negative termination", "[tvgInitializer]")
|
||||
{
|
||||
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::InsufficientCondition);
|
||||
}
|
||||
|
||||
TEST_CASE("Many threads", "[tvgInitializer]")
|
||||
{
|
||||
REQUIRE(Initializer::init(CanvasEngine::Sw, -1) == Result::FailedAllocation);
|
||||
REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::InsufficientCondition);
|
||||
}
|
||||
|
||||
TEST_CASE("Invalid engine", "[tvgInitializer]")
|
||||
{
|
||||
REQUIRE(Initializer::init(CanvasEngine(0), 0) == Result::InvalidArguments);
|
||||
}
|
5
test/testMain.cpp
Normal file
5
test/testMain.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
// The only purpose of this file is to DEFINE the catch config so it can include main()
|
||||
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
|
||||
#include "catch.hpp"
|
Loading…
Add table
Reference in a new issue