Add separate target for unit tests for easier test access. Remove unit tests from ResInsight application. (#11184)

Clean up cmake configuration a bit, and pull down gtest when needed, no longer use a thirdparty subfolder
Add a ResInsight-tests target to run the unit tests
This commit is contained in:
jonjenssen 2024-02-11 20:04:04 +01:00 committed by GitHub
parent 5a3894b804
commit 5391179e16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 268 additions and 27095 deletions

View File

@ -240,11 +240,12 @@ jobs:
- name: Stats for buildcache
run: ${{ github.workspace }}/buildcache/bin/buildcache -s
- name: Run Unit Tests
if: matrix.config.execute-unit-tests
shell: bash
run: |
cmakebuild/ApplicationExeCode/ResInsight --unittest
cmakebuild/ApplicationLibCode/UnitTests/ResInsight-tests
- name: (Python) Check types using mypy
if: matrix.config.build-python-module

View File

@ -271,14 +271,14 @@ set(LINK_LIBRARIES
${VIZ_FWK_LIBRARIES}
ApplicationLibCode
Commands
RigGeoMechDataModel
RifGeoMechFileInterface
)
if(RESINSIGHT_ENABLE_GRPC)
list(APPEND LINK_LIBRARIES GrpcInterface)
endif()
list(APPEND LINK_LIBRARIES RigGeoMechDataModel RifGeoMechFileInterface)
if(RESINSIGHT_USE_ODB_API)
add_definitions(-DUSE_ODB_API)
list(APPEND LINK_LIBRARIES RifOdbReader)
@ -317,68 +317,6 @@ endif()
# ##############################################################################
# Copy Dlls on MSVC
# ##############################################################################
if(MSVC)
if(NOT ${RESINSIGHT_ODB_API_DIR} EQUAL "")
set(RESINSIGHT_USE_ODB_API 1)
endif()
# Odb Dlls
if(RESINSIGHT_USE_ODB_API)
# Find all the dlls
file(GLOB RI_ALL_ODB_DLLS ${RESINSIGHT_ODB_API_DIR}/lib/*.dll)
# Strip off the path
foreach(aDLL ${RI_ALL_ODB_DLLS})
get_filename_component(filenameWithExt ${aDLL} NAME)
list(APPEND RI_ODB_DLLS ${filenameWithExt})
endforeach(aDLL)
foreach(aDLL ${RI_ODB_DLLS})
list(APPEND RI_FILENAMES ${RESINSIGHT_ODB_API_DIR}/lib/${aDLL})
endforeach()
endif()
# OpenVDS Dlls
set(OPENVDS_DLL_NAMES openvds segyutils)
foreach(OPENVDS_DLL_NAME ${OPENVDS_DLL_NAMES})
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/bin/msvc_141/${OPENVDS_DLL_NAME}.dll
)
endforeach(OPENVDS_DLL_NAME)
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/bin/msvc_141/SEGYImport.exe
)
# HDF5 Dlls
if(RESINSIGHT_FOUND_HDF5)
set(HDF5_DLL_NAMES hdf5 hdf5_cpp szip zlib)
foreach(HDF5_DLL_NAME ${HDF5_DLL_NAMES})
list(APPEND RI_FILENAMES ${RESINSIGHT_HDF5_DIR}/bin/${HDF5_DLL_NAME}.dll)
endforeach(HDF5_DLL_NAME)
endif()
else()
# Linux
# OpenVDS lib files
list(APPEND RI_FILENAMES ${RESINSIGHT_OPENVDS_API_DIR}/bin/SEGYImport)
set(OPENVDS_LIB_NAMES
libopenvds.so
libopenvds.so.3
libopenvds.so.3.2.7
libopenvds-e1541338.so.3.2.7
libsegyutils.so
libsegyutils.so.3
libsegyutils.so.3.2.7
)
foreach(OPENVDS_LIB_NAME ${OPENVDS_LIB_NAMES})
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/lib64/${OPENVDS_LIB_NAME}
)
endforeach(OPENVDS_LIB_NAME)
endif(MSVC)
# create an empty library target that will be used to copy files to the build
# folder

View File

@ -125,10 +125,6 @@
#include <unistd.h> // for usleep
#endif // WIN32
#ifdef USE_UNIT_TESTS
#include "gtest/gtest.h"
#endif // USE_UNIT_TESTS
// Required to ignore warning of usused variable when defining caf::PdmMarkdownGenerator
#if defined( __clang__ )
#pragma clang diagnostic ignored "-Wunused-variable"
@ -1395,56 +1391,6 @@ void RiaApplication::waitUntilCommandObjectsHasBeenProcessed()
m_commandQueueLock.unlock();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaApplication::launchUnitTests()
{
#ifdef USE_UNIT_TESTS
caf::ProgressInfoBlocker progressBlocker;
cvf::Assert::setReportMode( cvf::Assert::CONSOLE );
int argc = QCoreApplication::arguments().size();
QStringList arguments = QCoreApplication::arguments();
std::vector<std::string> argumentsStd;
for ( QString qstring : arguments )
{
argumentsStd.push_back( qstring.toStdString() );
}
std::vector<char*> argVector;
for ( std::string& string : argumentsStd )
{
argVector.push_back( &string.front() );
}
char** argv = argVector.data();
testing::InitGoogleTest( &argc, argv );
//
// Use the gtest filter to execute a subset of tests
QString filterText = RiaPreferencesSystem::current()->gtestFilter();
if ( !filterText.isEmpty() )
{
::testing::GTEST_FLAG( filter ) = filterText.toStdString();
// Example on filter syntax
//::testing::GTEST_FLAG( filter ) = "*RifCaseRealizationParametersReaderTest*";
}
// Use this macro in main() to run all tests. It returns 0 if all
// tests are successful, or 1 otherwise.
//
// RUN_ALL_TESTS() should be invoked after the command line has been
// parsed by InitGoogleTest().
return RUN_ALL_TESTS();
#else
return -1;
#endif
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1562,14 +1508,6 @@ void RiaApplication::initialize()
caf::SelectionManager::instance()->setPdmRootObject( project() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaApplication::launchUnitTestsWithConsole()
{
return launchUnitTests();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -198,7 +198,6 @@ public:
// Public implementation specific overrides
virtual void initialize();
virtual ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) = 0;
virtual int launchUnitTestsWithConsole();
virtual void addToRecentFiles( const QString& fileName ) {}
virtual void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) = 0;

View File

@ -154,22 +154,6 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments( gsl::n
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
// Unit testing
// --------------------------------------------------------
if ( cvf::Option o = progOpt->option( "unittest" ) )
{
int testReturnValue = launchUnitTestsWithConsole();
if ( testReturnValue == 0 )
{
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
else
{
RiaLogging::error( "Error running unit tests" );
return RiaApplication::ApplicationStatus::EXIT_WITH_ERROR;
}
}
if ( cvf::Option o = progOpt->option( "startdir" ) )
{
CVF_ASSERT( o.valueCount() == 1 );

View File

@ -142,10 +142,6 @@
#include <unistd.h> // for usleep
#endif // WIN32
#ifdef USE_UNIT_TESTS
#include "gtest/gtest.h"
#endif // USE_UNIT_TESTS
//==================================================================================================
///
/// \class RiaGuiApplication
@ -484,22 +480,6 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
// Unit testing
// --------------------------------------------------------
if ( cvf::Option o = progOpt->option( "unittest" ) )
{
int testReturnValue = launchUnitTestsWithConsole();
if ( testReturnValue == 0 )
{
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
else
{
RiaLogging::error( "Error running unit tests" );
return RiaApplication::ApplicationStatus::EXIT_WITH_ERROR;
}
}
if ( cvf::Option o = progOpt->option( "regressiontest" ) )
{
CVF_ASSERT( o.valueCount() == 1 );
@ -891,31 +871,6 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
return ApplicationStatus::KEEP_GOING;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaGuiApplication::launchUnitTestsWithConsole()
{
// Following code is taken from cvfAssert.cpp
#ifdef WIN32
{
// Allocate a new console for this app
// Only one console can be associated with an app, so should fail if a console is already present.
AllocConsole();
FILE* consoleFilePointer;
freopen_s( &consoleFilePointer, "CONOUT$", "w", stdout );
freopen_s( &consoleFilePointer, "CONOUT$", "w", stderr );
// Make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std::ios::sync_with_stdio();
}
#endif
return launchUnitTests();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -127,7 +127,6 @@ public:
// Public RiaApplication overrides
void initialize() override;
ApplicationStatus handleArguments( gsl::not_null<cvf::ProgramOptions*> progOpt ) override;
int launchUnitTestsWithConsole() override;
void addToRecentFiles( const QString& fileName ) override;
void showFormattedTextInMessageBoxOrConsole( const QString& errMsg ) override;

View File

@ -130,9 +130,6 @@ bool RiaArgumentParser::parseArguments( cvf::ProgramOptions* progOpt )
progOpt->registerOption( "updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE );
progOpt->registerOption( "regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE );
#ifdef USE_UNIT_TESTS
progOpt->registerOption( "unittest", "", "System command" );
#endif
progOpt->registerOption( "generate", "[<outputFile>]", "Generate code or documentation", cvf::ProgramOptions::SINGLE_VALUE );
progOpt->registerOption( "ignoreArgs", "", "System command. Ignore all arguments. Mostly for testing purposes" );
progOpt->registerOption( "version", "", "Display the application version string" );

View File

@ -90,23 +90,6 @@ find_package(Eigen3 REQUIRED)
# Defining all the source (and header) files
# ##############################################################################
# Use all h files in the subdirectories to make them available in the project
file(GLOB_RECURSE HEADER_FILES *.h)
set(SOCKET_INTERFACE_FILES
SocketInterface/RiaSocketServer.cpp
SocketInterface/RiaProjectInfoCommands.cpp
SocketInterface/RiaCaseInfoCommands.cpp
SocketInterface/RiaGeometryCommands.cpp
SocketInterface/RiaNNCCommands.cpp
SocketInterface/RiaPropertyDataCommands.cpp
SocketInterface/RiaWellDataCommands.cpp
SocketInterface/RiaSocketTools.cpp
SocketInterface/RiaSocketDataTransfer.cpp
)
list(APPEND CPP_SOURCES ${SOCKET_INTERFACE_FILES} ${UNIT_TEST_FILES})
list(
APPEND
REFERENCED_CMAKE_FILES
@ -159,23 +142,9 @@ list(
UserInterface/AnalysisPlots/CMakeLists_files.cmake
CommandFileInterface/CMakeLists_files.cmake
CommandFileInterface/Core/CMakeLists_files.cmake
SocketInterface/CMakeLists_files.cmake
)
option(RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS
"Include ApplicationCode Unit Tests" OFF
)
mark_as_advanced(FORCE RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS)
if(RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS)
add_definitions(-DUSE_UNIT_TESTS)
list(APPEND REFERENCED_CMAKE_FILES UnitTests/CMakeLists_files.cmake)
list(APPEND CPP_SOURCES
${ResInsight_SOURCE_DIR}/ThirdParty/gtest/gtest-all.cc
)
endif()
# Include source file lists from *.cmake files
foreach(referencedfile ${REFERENCED_CMAKE_FILES})
include(${referencedfile})
@ -235,14 +204,11 @@ if(RESINSIGHT_FOUND_HDF5)
list(APPEND CPP_SOURCES ${HDF5_FILES})
add_definitions(-DUSE_HDF5)
add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB)
if(MSVC)
add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB)
list(APPEND RI_PRIVATE_INCLUDES ${RESINSIGHT_HDF5_DIR}/include)
else()
add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB)
add_definitions(${HDF5_DEFINITIONS})
list(APPEND RI_PRIVATE_INCLUDES ${HDF5_INCLUDE_DIRS})
endif() # MSVC
@ -267,21 +233,9 @@ qt5_wrap_ui(FORM_FILES_CPP ${QT_UI_FILES})
# Create source groups - see also included CMakeLists_files.cmake
# ##############################################################################
source_group("ModelVisualization" FILES ${MODEL_VISUALIZATION_FILES})
source_group("SocketInterface" FILES ${SOCKET_INTERFACE_FILES})
source_group("UnitTests" FILES ${UNIT_TEST_FILES})
list(
APPEND
ALL_SOURCE_FILES
${CPP_SOURCES}
${MOC_SOURCE_FILES}
${FORM_FILES_CPP}
${HEADER_FILES}
${REFERENCED_CMAKE_FILES}
../ResInsightVersion.cmake
.clang-format
.clang-tidy
Adm/RiaVersionInfo.h.cmake
list(APPEND ALL_SOURCE_FILES ${CPP_SOURCES} ${MOC_SOURCE_FILES}
${FORM_FILES_CPP}
)
add_library(${PROJECT_NAME} OBJECT ${ALL_SOURCE_FILES})
@ -291,11 +245,6 @@ mark_as_advanced(FORCE RESINSIGHT_ENABLE_PRECOMPILED_HEADERS)
if(RESINSIGHT_ENABLE_PRECOMPILED_HEADERS)
message("Precompiled Headers is enabled on : ${PROJECT_NAME}")
target_precompile_headers(ApplicationLibCode PRIVATE pch.h)
set_source_files_properties(
${ResInsight_SOURCE_DIR}/ThirdParty/gtest/gtest-all.cc
PROPERTIES SKIP_PRECOMPILE_HEADERS ON
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@ -382,16 +331,14 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif()
target_link_libraries(
${PROJECT_NAME} ${LINK_LIBRARIES} ${EXTERNAL_LINK_LIBRARIES}
${PROJECT_NAME} PUBLIC ${LINK_LIBRARIES} ${EXTERNAL_LINK_LIBRARIES}
)
target_include_directories(
${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Commands
${CMAKE_CURRENT_SOURCE_DIR}/Commands/EclipseCommands
${CMAKE_CURRENT_SOURCE_DIR}/ResultStatisticsCache
${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModelCommands/CommandRouter
${CMAKE_CURRENT_SOURCE_DIR}/UserInterface/AnalysisPlots
${RI_PRIVATE_INCLUDES}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/Adm
@ -437,8 +384,10 @@ target_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel/Completions
${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel/ResultAccessors
${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel/ResultCalculators
${CMAKE_CURRENT_SOURCE_DIR}/ResultStatisticsCache
${CMAKE_CURRENT_SOURCE_DIR}/SocketInterface
${CMAKE_CURRENT_SOURCE_DIR}/UserInterface
${CMAKE_CURRENT_SOURCE_DIR}/UserInterface/AnalysisPlots
${CMAKE_CURRENT_SOURCE_DIR}/GeoMech/GeoMechDataModel
${CMAKE_CURRENT_SOURCE_DIR}/GeoMech/GeoMechVisualization
${CMAKE_CURRENT_SOURCE_DIR}/GeoMech/GeoMechFileInterface
@ -472,3 +421,16 @@ if(RESINSIGHT_ENABLE_UNITY_BUILD)
)
endforeach(fileToExclude)
endif()
# ##############################################################################
# Unit tests
# ##############################################################################
option(RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS
"Include ApplicationLibCode Unit Tests" OFF
)
mark_as_advanced(FORCE RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS)
if(RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS)
enable_testing()
add_subdirectory(UnitTests)
endif()

View File

@ -1,5 +1,4 @@
set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicLaunchUnitTestsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotWindowFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicShowMainWindowFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicTileWindowsFeature.h
@ -24,7 +23,6 @@ set(SOURCE_GROUP_HEADER_FILES
)
set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicLaunchUnitTestsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotWindowFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicShowMainWindowFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicTileWindowsFeature.cpp

View File

@ -1,44 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicLaunchUnitTestsFeature.h"
#include "RiaApplication.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicLaunchUnitTestsFeature, "RicLaunchUnitTestsFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicLaunchUnitTestsFeature::onActionTriggered( bool isChecked )
{
disableModelChangeContribution();
RiaApplication::instance()->launchUnitTestsWithConsole();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicLaunchUnitTestsFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Launch Unit Tests" );
}

View File

@ -1,34 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicLaunchUnitTestsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -315,7 +315,7 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream*
if ( !columnInfoList ) return false;
columnInfoList->clear();
while ( !headerFound )
while ( !headerFound && dataStream->status() == QTextStream::Status::Ok )
{
QString line = dataStream->readLine();
if ( line.trimmed().isEmpty() )
@ -341,7 +341,7 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream*
auto startOfLineWithDataValues = dataStream->pos();
bool hasDataValues = false;
QString nameFromData;
while ( !hasDataValues )
while ( !hasDataValues && !dataStream->atEnd() )
{
QString candidateLine = dataStream->readLine();
@ -374,6 +374,8 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream*
}
}
if ( !hasDataValues ) break;
dataStream->seek( startOfLineWithDataValues );
int colCount = columnHeaders.size();

View File

@ -1,41 +0,0 @@
project(OdbReader_UnitTests)
set(RI_VIZ_FWK_ROOT
../../../Fwk/VizFwk
CACHE PATH "Path to VizFwk"
)
set(RI_GTEST_ROOT
../../../ThirdParty
CACHE PATH "Path to folder containing gtest folder"
)
set(RI_TEST_FILE
""
CACHE FILEPATH "Path to test file"
)
include(${RI_VIZ_FWK_ROOT}/CMake/Utils/ceeDetermineCompilerFlags.cmake)
add_subdirectory(${RI_VIZ_FWK_ROOT}/LibCore buildVizFwk)
add_subdirectory(../../ResultStatisticsCache buildResultStatisticsCache)
add_subdirectory(../OdbReader buildOdbReader)
add_subdirectory(../GeoMechDataModel buildGeoMechDataModel)
add_subdirectory(../GeoMechFileInterface buildGeoMechFileInterface)
add_definitions(-DTEST_FILE="${RI_TEST_FILE}")
include_directories(${RI_VIZ_FWK_ROOT}/LibCore)
include_directories(../../ResultStatisticsCache)
include_directories(../../ReservoirDataModel)
include_directories(../GeoMechFileInterface)
include_directories(../OdbReader)
include_directories(../GeoMechDataModel)
include_directories(${RI_GTEST_ROOT})
set(UNIT_TEST_CPP_SOURCES main.cpp RifOdbReader-Test.cpp
${RI_GTEST_ROOT}/gtest/gtest-all.cc
)
add_executable(${PROJECT_NAME} ${UNIT_TEST_CPP_SOURCES})
target_link_libraries(${PROJECT_NAME} RifOdbReader RifGeoMechFileInterface)
include(../OdbReader/OdbSetup.cmake)

View File

@ -159,7 +159,7 @@ void RigReservoirBuilder::createGridsAndCells( RigEclipseCaseData* eclipseCase )
activeCellInfo->setGridActiveCellCounts( 0, eclipseCase->mainGrid()->globalCellArray().size() );
activeCellInfo->computeDerivedData();
bool useOptimizedVersion = true;
bool useOptimizedVersion = false; // workaround, optimized version causes assert in debug builds
eclipseCase->computeActiveCellBoundingBoxes( useOptimizedVersion );
}

View File

@ -0,0 +1,25 @@
set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RifTextDataTableFormatter.h
)
set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaSocketServer.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaProjectInfoCommands.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaCaseInfoCommands.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGeometryCommands.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaNNCCommands.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaPropertyDataCommands.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaWellDataCommands.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaSocketTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaSocketDataTransfer.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})
source_group(
"SocketInterface"
FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES}
${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake
)

View File

@ -1,11 +1,6 @@
configure_file(
${CMAKE_CURRENT_LIST_DIR}/RiaTestDataDirectory.h.cmake
${CMAKE_BINARY_DIR}/Generated/RiaTestDataDirectory.h
)
# ResInsight unit tests
set(SOURCE_GROUP_HEADER_FILES)
set(SOURCE_GROUP_SOURCE_FILES
set(SOURCE_UNITTEST_FILES
${CMAKE_CURRENT_LIST_DIR}/cvfGeometryTools-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/Ert-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RifcCommandCore-Test.cpp
@ -104,17 +99,113 @@ set(SOURCE_GROUP_SOURCE_FILES
)
if(RESINSIGHT_ENABLE_GRPC)
list(APPEND GPRC_UNIT_TEST_SOURCE_FILES
list(APPEND SOURCE_UNITTEST_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcInterface-Test.cpp
)
list(APPEND SOURCE_GROUP_SOURCE_FILES ${GRPC_UNIT_TEST_SOURCE_FILES})
endif(RESINSIGHT_ENABLE_GRPC)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
# Obsolete test
if(RESINSIGHT_USE_ODB_API_OBSOLETE)
list(APPEND SOURCE_UNITTEST_FILES
${CMAKE_CURRENT_LIST_DIR}/RifOdbReader-Test.cpp
)
endif(RESINSIGHT_USE_ODB_API_OBSOLETE)
list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})
source_group(
"UnitTests" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES}
${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
FetchContent_MakeAvailable(googletest)
# ##############################################################################
# Copy required Dll/.so to output folder
# ##############################################################################
# create an empty library target that will be used to copy files to the build
# folder
add_library(ResInsightDummyTestTarget EXCLUDE_FROM_ALL empty.cpp)
set_property(
TARGET ResInsightDummyTestTarget PROPERTY FOLDER "FileCopyTargetsTest"
)
# create a custom target that copies the files to the build folder
foreach(riFileName ${RI_FILENAMES})
list(
APPEND
copyCommands
COMMAND
${CMAKE_COMMAND}
-E
copy_if_different
${riFileName}
$<TARGET_FILE_DIR:ResInsightDummyTestTarget>
)
endforeach()
add_custom_target(PreBuildFileCopyTest ${copyCommands})
set_property(TARGET PreBuildFileCopyTest PROPERTY FOLDER "FileCopyTargetsTest")
add_executable(ResInsight-tests ${SOURCE_UNITTEST_FILES} main.cpp)
# Make ResInsight-tests depend on the prebuild target.
add_dependencies(ResInsight-tests PreBuildFileCopyTest)
configure_file(
${CMAKE_CURRENT_LIST_DIR}/RiaTestDataDirectory.h.cmake
${CMAKE_BINARY_DIR}/Generated/RiaTestDataDirectory.h
)
target_include_directories(
ResInsight-tests
PUBLIC ${CMAKE_BINARY_DIR}/Generated
"$<TARGET_PROPERTY:ApplicationLibCode,PUBLIC_INCLUDE_DIRECTORIES>"
${RI_PRIVATE_INCLUDES} ${PROJECT_SOURCE_DIR}/Commands
)
target_compile_features(ResInsight-tests PRIVATE cxx_std_20)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND THIRD_PARTY_LIBRARIES rt atomic)
endif()
set(LINK_LIBRARIES
${THIRD_PARTY_LIBRARIES}
${OPENGL_LIBRARIES}
${QT_LIBRARIES}
${OPM_LIBRARIES}
${APP_FWK_LIBRARIES}
${VIZ_FWK_LIBRARIES}
ApplicationLibCode
Commands
RigGeoMechDataModel
RifGeoMechFileInterface
)
if(RESINSIGHT_ENABLE_GRPC)
list(APPEND LINK_LIBRARIES GrpcInterface)
endif()
if(RESINSIGHT_USE_ODB_API)
list(APPEND LINK_LIBRARIES RifOdbReader)
endif()
target_link_libraries(ResInsight-tests PUBLIC ${LINK_LIBRARIES} GTest::gtest)
if(MSVC)
add_custom_command(
TARGET ResInsight-tests
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:ResInsight-tests>
$<TARGET_FILE_DIR:ResInsight-tests>
COMMAND_EXPAND_LISTS
)
endif(MSVC)
add_test(NAME ResInsight-tests COMMAND ResInsight-tests)
install(TARGETS ResInsight-tests DESTINATION ${RESINSIGHT_INSTALL_FOLDER})

View File

@ -0,0 +1,10 @@
//
// This empty file is used by ResInsightDummyTarget
//
// Creating a dummy target with an empty file is used to have a different target than ResInsight.
// This target is used to find the full path to the build folder.
//
// $<TARGET_FILE_DIR:ResInsightDummyTarget>
//
// If we use the ResInsight target ($<TARGET_FILE_DIR:ResInsight>), we get a circular dependency.
//

View File

@ -1,7 +1,6 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015 - Statoil ASA
// Copyright (C) 2015 - Ceetron Solutions AS
// Copyright (C) 2024 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -18,23 +17,23 @@
/////////////////////////////////////////////////////////////////////////////////
#include "gtest/gtest.h"
#include <stdio.h>
#include "cvfTrace.h"
#include "RiaConsoleApplication.h"
#include <QLocale>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int main( int argc, char** argv )
{
cvf::Assert::setReportMode( cvf::Assert::CONSOLE );
RiaApplication* app = new RiaConsoleApplication( argc, argv );
app->initialize();
QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) );
setlocale( LC_NUMERIC, "C" );
testing::InitGoogleTest( &argc, argv );
int result = RUN_ALL_TESTS();
std::cout << "Please press <Enter> to close the window.";
std::cin.get();
return result;
}

View File

@ -516,7 +516,6 @@ void RiuMainWindow::createMenus()
testMenu->addSeparator();
testMenu->addAction( m_showRegressionTestDialog );
testMenu->addAction( m_executePaintEventPerformanceTest );
testMenu->addAction( cmdFeatureMgr->action( "RicLaunchUnitTestsFeature" ) );
testMenu->addAction( cmdFeatureMgr->action( "RicRunCommandFileFeature" ) );
testMenu->addAction( cmdFeatureMgr->action( "RicExportObjectAndFieldKeywordsFeature" ) );
testMenu->addAction( cmdFeatureMgr->action( "RicSaveProjectNoGlobalPathsFeature" ) );
@ -665,7 +664,6 @@ void RiuMainWindow::createToolBars()
{
QToolBar* toolbar = addToolBar( tr( "Test" ) );
toolbar->setObjectName( toolbar->windowTitle() );
toolbar->addAction( cmdFeatureMgr->action( "RicLaunchUnitTestsFeature" ) );
toolbar->addAction( cmdFeatureMgr->action( "RicLaunchRegressionTestsFeature" ) );
toolbar->addAction( cmdFeatureMgr->action( "RicLaunchRegressionTestDialogFeature" ) );
toolbar->addAction( cmdFeatureMgr->action( "RicShowClassNamesFeature" ) );

View File

@ -635,6 +635,72 @@ list(APPEND THIRD_PARTY_LIBRARIES spdlog)
# ##############################################################################
set_property(TARGET ${THIRD_PARTY_LIBRARIES} PROPERTY FOLDER "Thirdparty")
# ##############################################################################
# Build list of DLLs needed for executables
# ##############################################################################
if(MSVC)
if(NOT ${RESINSIGHT_ODB_API_DIR} EQUAL "")
set(RESINSIGHT_USE_ODB_API 1)
endif()
# Odb Dlls
if(RESINSIGHT_USE_ODB_API)
# Find all the dlls
file(GLOB RI_ALL_ODB_DLLS ${RESINSIGHT_ODB_API_DIR}/lib/*.dll)
# Strip off the path
foreach(aDLL ${RI_ALL_ODB_DLLS})
get_filename_component(filenameWithExt ${aDLL} NAME)
list(APPEND RI_ODB_DLLS ${filenameWithExt})
endforeach(aDLL)
foreach(aDLL ${RI_ODB_DLLS})
list(APPEND RI_FILENAMES ${RESINSIGHT_ODB_API_DIR}/lib/${aDLL})
endforeach()
endif()
# OpenVDS Dlls
set(OPENVDS_DLL_NAMES openvds segyutils)
foreach(OPENVDS_DLL_NAME ${OPENVDS_DLL_NAMES})
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/bin/msvc_141/${OPENVDS_DLL_NAME}.dll
)
endforeach(OPENVDS_DLL_NAME)
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/bin/msvc_141/SEGYImport.exe
)
# HDF5 Dlls
if(RESINSIGHT_FOUND_HDF5)
set(HDF5_DLL_NAMES hdf5 hdf5_cpp szip zlib)
foreach(HDF5_DLL_NAME ${HDF5_DLL_NAMES})
list(APPEND RI_FILENAMES ${RESINSIGHT_HDF5_DIR}/bin/${HDF5_DLL_NAME}.dll)
endforeach(HDF5_DLL_NAME)
endif()
else()
# Linux
# OpenVDS lib files
list(APPEND RI_FILENAMES ${RESINSIGHT_OPENVDS_API_DIR}/bin/SEGYImport)
set(OPENVDS_LIB_NAMES
libopenvds.so
libopenvds.so.3
libopenvds.so.3.2.7
libopenvds-e1541338.so.3.2.7
libsegyutils.so
libsegyutils.so.3
libsegyutils.so.3.2.7
)
foreach(OPENVDS_LIB_NAME ${OPENVDS_LIB_NAMES})
list(APPEND RI_FILENAMES
${RESINSIGHT_OPENVDS_API_DIR}/lib64/${OPENVDS_LIB_NAME}
)
endforeach(OPENVDS_LIB_NAME)
endif(MSVC)
# ##############################################################################
# Unity Build
# ##############################################################################

View File

@ -1,16 +1,25 @@
cmake_minimum_required (VERSION 2.8.12)
project ( opm-parser-tests )
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
FetchContent_MakeAvailable(googletest)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set( PROJECT_FILES opm-parser-BasicTest.cpp )
# add the executable
add_executable (${PROJECT_NAME} ${PROJECT_FILES} )
# Languages and global compiler settings
if(CMAKE_VERSION VERSION_LESS 3.8)
message(WARNING "CMake version does not support c++17, guessing -std=c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.11))
# VS 2017 : Disable warnings from from gtest code, using deprecated code related to TR1
@ -21,38 +30,16 @@ CONFIGURE_FILE( ${CMAKE_CURRENT_LIST_DIR}/OpmTestDataDirectory.h.cmake
${CMAKE_BINARY_DIR}/Generated/OpmTestDataDirectory.h
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_BINARY_DIR}/Generated
# ${CMAKE_CURRENT_SOURCE_DIR}/../opm-parser
# ${CMAKE_CURRENT_SOURCE_DIR}/../../custom-opm-common/opm-common
# ${ERT_INCLUDE_DIRS}
# ${Boost_INCLUDE_DIRS}
)
set( PROJECT_FILES
opm-parser_UnitTests.cpp
../../gtest/gtest-all.cc
opm-parser-BasicTest.cpp
)
# add the executable
add_executable (${PROJECT_NAME}
${PROJECT_FILES}
)
source_group("" FILES ${PROJECT_FILES})
target_include_directories (${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/Generated )
target_link_libraries ( ${PROJECT_NAME}
custom-opm-common
GTest::gtest_main
)
# Add dependency of Shlwapi.lib for Windows platforms
if (MSVC)
target_link_libraries(${PROJECT_NAME} Shlwapi)
endif()
endif()
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

View File

@ -1,20 +0,0 @@
#include "gtest/gtest.h"
#include <stdio.h>
#include <iostream>
#include <string>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
char text[5];
std::cin.getline(text, 5);
return result;
}

File diff suppressed because it is too large Load Diff

14813
ThirdParty/gtest/gtest.h vendored

File diff suppressed because it is too large Load Diff