Merge branch 'feature/add-unittests' into develop
This commit is contained in:
commit
458de36cbc
@ -6,3 +6,4 @@ include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup()
|
||||
|
||||
add_subdirectory(source)
|
||||
add_subdirectory(test)
|
||||
|
@ -1,5 +1,6 @@
|
||||
[requires]
|
||||
protobuf/3.6.1@bincrafters/stable
|
||||
catch2/2.4.2@bincrafters/stable
|
||||
|
||||
[generators]
|
||||
cmake
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <sstream>
|
||||
|
||||
Age::Age(unsigned int years, unsigned int months)
|
||||
: m_years(years)
|
||||
, m_months(months)
|
||||
: m_years(years)
|
||||
, m_months(months)
|
||||
{
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ Age::Age(const QDate &birth, const QDate &reference)
|
||||
m_years = years;
|
||||
m_months = months;
|
||||
}
|
||||
|
||||
|
||||
bool Age::operator<(const Age &cmp) const
|
||||
{
|
||||
if (m_years == cmp.m_years)
|
||||
@ -47,7 +47,7 @@ bool Age::operator<(const Age &cmp) const
|
||||
|
||||
return m_years < cmp.m_years;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Age::years() const
|
||||
{
|
||||
return m_years;
|
||||
@ -57,7 +57,7 @@ unsigned int Age::months() const
|
||||
{
|
||||
return m_months;
|
||||
}
|
||||
|
||||
|
||||
std::string Age::toString() const
|
||||
{
|
||||
std::ostringstream result;
|
23
source/Age/CMakeLists.txt
Normal file
23
source/Age/CMakeLists.txt
Normal 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
|
||||
)
|
@ -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)
|
||||
|
@ -41,6 +41,7 @@ target_include_directories(${PROJECT_NAME}
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
Age
|
||||
Qt5::Widgets
|
||||
${Protobuf_LIBRARIES}
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Age.h"
|
||||
#include "Age.h"
|
||||
|
||||
#include "MetaDataModel.pb.h"
|
||||
|
||||
|
@ -30,5 +30,6 @@ target_include_directories(${PROJECT_NAME}
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
Age
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Age.h"
|
||||
#include "Age.h"
|
||||
#include <vector>
|
||||
|
||||
class PRMap
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Age.h"
|
||||
#include "Age.h"
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class TestResult
|
||||
|
40
test/Age.cpp
Normal file
40
test/Age.cpp
Normal 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
21
test/CMakeLists.txt
Normal 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
7
test/dummy.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
TEST_CASE("Dummy")
|
||||
{
|
||||
REQUIRE(true == true);
|
||||
}
|
||||
|
2
test/main.cpp
Normal file
2
test/main.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
Reference in New Issue
Block a user