From 3fa8f5a705425baa60966d794cc4019526e6c86f Mon Sep 17 00:00:00 2001 From: spo Date: Thu, 26 May 2016 17:38:01 +0300 Subject: [PATCH] Add test for HighModelAPI_Double --- src/ConstructionAPI/Test/TestPoint.cpp | 16 +++--- src/ModelHighAPI/CMakeLists.txt | 3 ++ src/ModelHighAPI/Mock/MockEvents_Listener.h | 16 ++++++ src/ModelHighAPI/ModelHighAPI_Double.cpp | 4 -- src/ModelHighAPI/ModelHighAPI_Double.h | 4 +- src/ModelHighAPI/Test/CMakeLists.txt | 24 +++++++++ src/ModelHighAPI/Test/TestDouble.cpp | 59 +++++++++++++++++++++ 7 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 src/ModelHighAPI/Mock/MockEvents_Listener.h create mode 100644 src/ModelHighAPI/Test/CMakeLists.txt create mode 100644 src/ModelHighAPI/Test/TestDouble.cpp diff --git a/src/ConstructionAPI/Test/TestPoint.cpp b/src/ConstructionAPI/Test/TestPoint.cpp index aeb6657d2..b136b0367 100644 --- a/src/ConstructionAPI/Test/TestPoint.cpp +++ b/src/ConstructionAPI/Test/TestPoint.cpp @@ -8,10 +8,12 @@ #include #include -#include "MockModelAPI_AttributeDouble.h" -#include "MockModelAPI_Data.h" -#include "MockModelAPI_Document.h" -#include "MockModelAPI_Feature.h" +#include + +#include +#include +#include +#include using ::testing::_; using ::testing::Return; @@ -21,12 +23,6 @@ using ::testing::Test; // TODO(spo): should be common function void null_deleter(void *) {} -class MockEvents_Listener : public Events_Listener { -public: - MOCK_METHOD1(processEvent, - void(const std::shared_ptr& theMessage)); -}; - class ConstructionAPI_Point_Constructor_Test : public Test { public: MockEvents_Listener aErrorListener; diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index 404e8f8a2..9ae3be6ef 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -16,6 +16,7 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES Config Events + ModelAPI ) ADD_DEFINITIONS(-DMODELHIGHAPI_EXPORTS) @@ -59,3 +60,5 @@ INCLUDE(UnitTest) ADD_UNIT_TESTS( TestDouble.py ) + +ADD_SUBDIRECTORY (Test) diff --git a/src/ModelHighAPI/Mock/MockEvents_Listener.h b/src/ModelHighAPI/Mock/MockEvents_Listener.h new file mode 100644 index 000000000..cf5c1ab8d --- /dev/null +++ b/src/ModelHighAPI/Mock/MockEvents_Listener.h @@ -0,0 +1,16 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef MockEvents_Listener_H_ +#define MockEvents_Listener_H_ + +#include + +#include + +class MockEvents_Listener : public Events_Listener { +public: + MOCK_METHOD1(processEvent, + void(const std::shared_ptr& theMessage)); +}; + +#endif // MockEvents_Listener_H_ diff --git a/src/ModelHighAPI/ModelHighAPI_Double.cpp b/src/ModelHighAPI/ModelHighAPI_Double.cpp index ca1f661a9..b40b89e0c 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Double.cpp @@ -11,10 +11,6 @@ //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- -ModelHighAPI_Double::ModelHighAPI_Double() -{ -} - ModelHighAPI_Double::ModelHighAPI_Double(double theValue) : myValue(theValue) { diff --git a/src/ModelHighAPI/ModelHighAPI_Double.h b/src/ModelHighAPI/ModelHighAPI_Double.h index f39e50445..3f84a72f8 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.h +++ b/src/ModelHighAPI/ModelHighAPI_Double.h @@ -22,10 +22,8 @@ class ModelAPI_AttributeDouble; class ModelHighAPI_Double { public: - /// Default constructor - ModelHighAPI_Double(); /// Constructor for double - ModelHighAPI_Double(double theValue); + ModelHighAPI_Double(double theValue = 0.); /// Constructor for std::string ModelHighAPI_Double(const std::string & theValue); /// Constructor for char * diff --git a/src/ModelHighAPI/Test/CMakeLists.txt b/src/ModelHighAPI/Test/CMakeLists.txt new file mode 100644 index 000000000..2af368b68 --- /dev/null +++ b/src/ModelHighAPI/Test/CMakeLists.txt @@ -0,0 +1,24 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +include(GTest) + +set(PROJECT_SOURCES + TestDouble.cpp +) + +include_directories( + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/Mock +) + +set(PROJECT_LIBRARIES + ModelHighAPI +) + +set(PACKAGE_NAME "ModelHighAPI") +set(TARGET_NAME "Test${PACKAGE_NAME}") + +add_executable(${TARGET_NAME} ${PROJECT_SOURCES}) +target_link_libraries(${TARGET_NAME} ${PROJECT_LIBRARIES} ${GTEST_LIBRARY}) + +GTEST_ADD_TESTS(${CMAKE_BINARY_DIR}/bin/${TARGET_NAME} "" ${PROJECT_SOURCES}) diff --git a/src/ModelHighAPI/Test/TestDouble.cpp b/src/ModelHighAPI/Test/TestDouble.cpp new file mode 100644 index 000000000..23c47a5d3 --- /dev/null +++ b/src/ModelHighAPI/Test/TestDouble.cpp @@ -0,0 +1,59 @@ +#include +#include + +#include + +#include + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRefOfCopy; +using ::testing::Test; + +// TODO(spo): should be common function +void null_deleter(void *) {} + +class HighModelAPI_Double_Test : public Test { +public: + MockModelAPI_AttributeDouble aMockAttributeDouble; + std::shared_ptr anAttributeDouble; + + HighModelAPI_Double_Test() { + anAttributeDouble = std::shared_ptr(&aMockAttributeDouble, &null_deleter); + } + + ~HighModelAPI_Double_Test() { + } +}; + +TEST_F(HighModelAPI_Double_Test, Default) { + ModelHighAPI_Double aValue; + + EXPECT_CALL(aMockAttributeDouble, setValue(0.)); + + aValue.fillAttribute(anAttributeDouble); +} + +TEST_F(HighModelAPI_Double_Test, Double) { + ModelHighAPI_Double aValue(100); + + EXPECT_CALL(aMockAttributeDouble, setValue(100.)); + + aValue.fillAttribute(anAttributeDouble); +} + +TEST_F(HighModelAPI_Double_Test, Char) { + ModelHighAPI_Double aValue("20"); + + EXPECT_CALL(aMockAttributeDouble, setText("20")); + + aValue.fillAttribute(anAttributeDouble); +} + +TEST_F(HighModelAPI_Double_Test, String) { + ModelHighAPI_Double aValue(std::string("x + 30")); + + EXPECT_CALL(aMockAttributeDouble, setText("x + 30")); + + aValue.fillAttribute(anAttributeDouble); +} -- 2.39.2