Merge branch 'feature/add-unittests' into develop

This commit is contained in:
Michael Mandl 2018-11-25 14:32:40 +01:00
commit 458de36cbc
15 changed files with 107 additions and 9 deletions

View file

@ -6,3 +6,4 @@ include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_subdirectory(source)
add_subdirectory(test)

View file

@ -1,5 +1,6 @@
[requires]
protobuf/3.6.1@bincrafters/stable
catch2/2.4.2@bincrafters/stable
[generators]
cmake

23
source/Age/CMakeLists.txt Normal file
View file

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.6)
project(Age LANGUAGES CXX)
find_package(Qt5Core REQUIRED)
add_library(${PROJECT_NAME}
Age.cpp
)
set_target_properties(${PROJECT_NAME}
PROPERTIES CXX_STANDARD 14
)
target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
)

View file

@ -37,7 +37,6 @@ add_executable(${PROJECT_NAME} WIN32
LogoTest.cpp
DataModel.cpp
mainwindow.cpp
Age.cpp
${LOGO_TEST_UI}
${LOGO_TEST_QRC}
${DataModel_PROTO_SRCS}
@ -57,6 +56,7 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE
Age
CheckableItem
CheckableTest
CheckableTestModel
@ -73,6 +73,7 @@ target_link_libraries(${PROJECT_NAME}
${Protobuf_LIBRARIES}
)
add_subdirectory(Age)
add_subdirectory(CheckableItem)
add_subdirectory(CheckableTest)
add_subdirectory(CheckableTestModel)

View file

@ -41,6 +41,7 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE
Age
Qt5::Widgets
${Protobuf_LIBRARIES}
)

View file

@ -1,6 +1,6 @@
#pragma once
#include "../Age.h"
#include "Age.h"
#include "MetaDataModel.pb.h"

View file

@ -30,5 +30,6 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE
Age
Qt5::Widgets
)

View file

@ -1,6 +1,6 @@
#pragma once
#include "../Age.h"
#include "Age.h"
#include <vector>
class PRMap

View file

@ -1,6 +1,6 @@
#pragma once
#include "../Age.h"
#include "Age.h"
#include <QAbstractTableModel>
class TestResult

40
test/Age.cpp Normal file
View file

@ -0,0 +1,40 @@
#include <catch2/catch.hpp>
#include "Age.h"
TEST_CASE("default initialization")
{
Age age;
REQUIRE(age.years() == 0);
REQUIRE(age.months() == 0);
REQUIRE(age.toString() == "0;0");
Age age2;
REQUIRE(!(age < age));
REQUIRE(!(age < age2));
}
TEST_CASE("year/month initialization")
{
for (unsigned int year = 0; year <= 100; ++year)
{
for (unsigned int month = 0; month < 12; ++month)
{
Age age(year, month);
REQUIRE(age.years() == year);
REQUIRE(age.months() == month);
}
}
}
TEST_CASE("age by reference")
{
QDate birth(1970, 1, 1);
QDate reference(1980, 1, 1);
Age age(birth, reference);
REQUIRE(age.years() == 10);
REQUIRE(age.months() == 0);
}

21
test/CMakeLists.txt Normal file
View file

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.5)
project(run-tests)
find_package(Catch2 REQUIRED)
add_executable(${PROJECT_NAME}
main.cpp
dummy.cpp
Age.cpp
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
Catch2::Catch2
Age
)
include(CTest)
include(Catch)
catch_discover_tests(${PROJECT_NAME})

7
test/dummy.cpp Normal file
View file

@ -0,0 +1,7 @@
#include <catch2/catch.hpp>
TEST_CASE("Dummy")
{
REQUIRE(true == true);
}

2
test/main.cpp Normal file
View file

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>