mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 07:26:03 -06:00
Added unit test to Testing menu
Launch of unit tests (gtests) is also possible from command line parameter "unittest"
This commit is contained in:
parent
f4cfc51de2
commit
63d401b6e6
@ -89,6 +89,11 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
@ -940,6 +945,7 @@ bool RiaApplication::parseArguments()
|
|||||||
progOpt.registerOption("?", "", "Displays help text.");
|
progOpt.registerOption("?", "", "Displays help text.");
|
||||||
progOpt.registerOption("regressiontest", "<folder>", "", cvf::ProgramOptions::SINGLE_VALUE);
|
progOpt.registerOption("regressiontest", "<folder>", "", cvf::ProgramOptions::SINGLE_VALUE);
|
||||||
progOpt.registerOption("updateregressiontestbase", "<folder>", "", cvf::ProgramOptions::SINGLE_VALUE);
|
progOpt.registerOption("updateregressiontestbase", "<folder>", "", cvf::ProgramOptions::SINGLE_VALUE);
|
||||||
|
progOpt.registerOption("unittest", "", "Execute unit tests");
|
||||||
|
|
||||||
progOpt.setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH);
|
progOpt.setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH);
|
||||||
|
|
||||||
@ -1117,10 +1123,82 @@ bool RiaApplication::parseArguments()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unit testing
|
||||||
|
// --------------------------------------------------------
|
||||||
|
if (cvf::Option o = progOpt.option("unittest"))
|
||||||
|
{
|
||||||
|
launchUnitTests();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaApplication::launchUnitTests()
|
||||||
|
{
|
||||||
|
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||||
|
|
||||||
|
int argc = QCoreApplication::argc();
|
||||||
|
testing::InitGoogleTest(&argc, QCoreApplication::argv());
|
||||||
|
|
||||||
|
int result = RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaApplication::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();
|
||||||
|
|
||||||
|
bool redirStdOut = true;
|
||||||
|
bool redirStdErr = true;
|
||||||
|
bool redirStdIn = false;
|
||||||
|
|
||||||
|
if (redirStdOut)
|
||||||
|
{
|
||||||
|
HANDLE stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
int fileDescriptor = _open_osfhandle((intptr_t)stdHandle, _O_TEXT);
|
||||||
|
FILE* fp = _fdopen(fileDescriptor, "w");
|
||||||
|
|
||||||
|
*stdout = *fp;
|
||||||
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (redirStdErr)
|
||||||
|
{
|
||||||
|
HANDLE stdHandle = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
int fileDescriptor = _open_osfhandle((intptr_t)stdHandle, _O_TEXT);
|
||||||
|
FILE* fp = _fdopen(fileDescriptor, "w");
|
||||||
|
|
||||||
|
*stderr = *fp;
|
||||||
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (redirStdIn)
|
||||||
|
{
|
||||||
|
HANDLE stdHandle = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
int fileDescriptor = _open_osfhandle((intptr_t)stdHandle, _O_TEXT);
|
||||||
|
FILE* fp = _fdopen(fileDescriptor, "r");
|
||||||
|
|
||||||
|
*stdin = *fp;
|
||||||
|
setvbuf(stdin, NULL, _IONBF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
|
||||||
|
std::ios::sync_with_stdio();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
launchUnitTests();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
|
@ -159,6 +159,9 @@ public:
|
|||||||
|
|
||||||
bool isRunningRegressionTests() const;
|
bool isRunningRegressionTests() const;
|
||||||
|
|
||||||
|
void launchUnitTests();
|
||||||
|
void launchUnitTestsWithConsole();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum ProjectLoadAction
|
enum ProjectLoadAction
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,8 @@ include_directories(
|
|||||||
${cafPdmCvf_SOURCE_DIR}
|
${cafPdmCvf_SOURCE_DIR}
|
||||||
${CommonCode_SOURCE_DIR}
|
${CommonCode_SOURCE_DIR}
|
||||||
|
|
||||||
|
${ResInsight_SOURCE_DIR}/ThirdParty
|
||||||
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Adm
|
${CMAKE_CURRENT_SOURCE_DIR}/Adm
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Application
|
${CMAKE_CURRENT_SOURCE_DIR}/Application
|
||||||
@ -58,6 +60,8 @@ set( APPLICATION_FILES
|
|||||||
Application/RiaImageCompareReporter.cpp
|
Application/RiaImageCompareReporter.cpp
|
||||||
Application/RiaProjectModifier.cpp
|
Application/RiaProjectModifier.cpp
|
||||||
Application/RiaRegressionTest.cpp
|
Application/RiaRegressionTest.cpp
|
||||||
|
|
||||||
|
${ResInsight_SOURCE_DIR}/ThirdParty/gtest/gtest-all.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
set( USER_INTERFACE_FILES
|
set( USER_INTERFACE_FILES
|
||||||
@ -99,11 +103,16 @@ set( SOCKET_INTERFACE_FILES
|
|||||||
SocketInterface/RiaSocketDataTransfer.cpp
|
SocketInterface/RiaSocketDataTransfer.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set( UNIT_TEST_FILES
|
||||||
|
ProjectDataModel/ProjectDataModel_UnitTests/RimWellLogExtractionCurveImpl-Test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
list( APPEND CPP_SOURCES
|
list( APPEND CPP_SOURCES
|
||||||
${APPLICATION_FILES}
|
${APPLICATION_FILES}
|
||||||
${USER_INTERFACE_FILES}
|
${USER_INTERFACE_FILES}
|
||||||
${SOCKET_INTERFACE_FILES}
|
${SOCKET_INTERFACE_FILES}
|
||||||
|
${UNIT_TEST_FILES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -265,6 +274,7 @@ source_group( "Application" FILES ${APPLICATION_FILES} )
|
|||||||
source_group( "ModelVisualization" FILES ${MODEL_VISUALIZATION_FILES} )
|
source_group( "ModelVisualization" FILES ${MODEL_VISUALIZATION_FILES} )
|
||||||
source_group( "UserInterface" FILES ${USER_INTERFACE_FILES} )
|
source_group( "UserInterface" FILES ${USER_INTERFACE_FILES} )
|
||||||
source_group( "SocketInterface" FILES ${SOCKET_INTERFACE_FILES} )
|
source_group( "SocketInterface" FILES ${SOCKET_INTERFACE_FILES} )
|
||||||
|
source_group( "UnitTests" FILES ${UNIT_TEST_FILES} )
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
@ -46,6 +46,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.h
|
|||||||
${CEE_CURRENT_LIST_DIR}RicWellLogsImportFileFeature.h
|
${CEE_CURRENT_LIST_DIR}RicWellLogsImportFileFeature.h
|
||||||
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicTileWindowsFeature.h
|
${CEE_CURRENT_LIST_DIR}RicTileWindowsFeature.h
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicLaunchUnitTestsFeature.h
|
||||||
|
|
||||||
|
|
||||||
# General delete of any object in a child array field
|
# General delete of any object in a child array field
|
||||||
@ -93,6 +94,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellPathsImportFileFeature.cpp
|
|||||||
${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.cpp
|
${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.cpp
|
||||||
|
|
||||||
${CEE_CURRENT_LIST_DIR}RicTileWindowsFeature.cpp
|
${CEE_CURRENT_LIST_DIR}RicTileWindowsFeature.cpp
|
||||||
|
${CEE_CURRENT_LIST_DIR}RicLaunchUnitTestsFeature.cpp
|
||||||
|
|
||||||
|
|
||||||
# General delete of any object in a child array field
|
# General delete of any object in a child array field
|
||||||
|
53
ApplicationCode/Commands/RicLaunchUnitTestsFeature.cpp
Normal file
53
ApplicationCode/Commands/RicLaunchUnitTestsFeature.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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");
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RicLaunchUnitTestsFeature::isCommandEnabled()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicLaunchUnitTestsFeature::onActionTriggered(bool isChecked)
|
||||||
|
{
|
||||||
|
RiaApplication::instance()->launchUnitTestsWithConsole();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicLaunchUnitTestsFeature::setupActionLook(QAction* actionToSetup)
|
||||||
|
{
|
||||||
|
actionToSetup->setText("Launch Unit Tests");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
38
ApplicationCode/Commands/RicLaunchUnitTestsFeature.h
Normal file
38
ApplicationCode/Commands/RicLaunchUnitTestsFeature.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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:
|
||||||
|
// Overrides
|
||||||
|
virtual bool isCommandEnabled();
|
||||||
|
virtual void onActionTriggered( bool isChecked );
|
||||||
|
virtual void setupActionLook( QAction* actionToSetup );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "../RimWellLogExtractionCurveImpl.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
TEST(RimWellLogExtractionCurveImplTest, Dummy)
|
||||||
|
{
|
||||||
|
std::vector<double> values;
|
||||||
|
values.push_back(0.0);
|
||||||
|
values.push_back(1.0);
|
||||||
|
values.push_back(1.0);
|
||||||
|
|
||||||
|
std::vector< std::pair<size_t, size_t> > valuesIntervals;
|
||||||
|
RimWellLogExtractionCurveImpl::validValuesIntervals(values, valuesIntervals);
|
||||||
|
|
||||||
|
EXPECT_EQ(1, valuesIntervals.size());
|
||||||
|
}
|
@ -489,6 +489,7 @@ void RiuMainWindow::createMenus()
|
|||||||
testMenu->addSeparator();
|
testMenu->addSeparator();
|
||||||
testMenu->addAction(m_showRegressionTestDialog);
|
testMenu->addAction(m_showRegressionTestDialog);
|
||||||
testMenu->addAction(m_executePaintEventPerformanceTest);
|
testMenu->addAction(m_executePaintEventPerformanceTest);
|
||||||
|
testMenu->addAction(cmdFeatureMgr->action("RicLaunchUnitTestsFeature"));
|
||||||
|
|
||||||
// Windows menu
|
// Windows menu
|
||||||
m_windowMenu = menuBar()->addMenu("&Windows");
|
m_windowMenu = menuBar()->addMenu("&Windows");
|
||||||
|
Loading…
Reference in New Issue
Block a user