2015-04-23 13:24:15 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2024-02-11 20:04:04 +01:00
|
|
|
// Copyright (C) 2024 Equinor ASA
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-04-23 13:24:15 +02:00
|
|
|
// 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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-04-23 13:24:15 +02:00
|
|
|
// 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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-04-23 13:24:15 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
2024-02-11 20:04:04 +01:00
|
|
|
#include "RiaConsoleApplication.h"
|
2024-10-13 13:28:28 +02:00
|
|
|
#include "RiaQuantityInfoTools.h"
|
2024-07-22 11:33:38 +02:00
|
|
|
#include "RiaRegressionTestRunner.h"
|
2024-02-11 20:04:04 +01:00
|
|
|
|
2026-08-14 07:39:22 +02:00
|
|
|
#include "RimProject.h"
|
|
|
|
|
|
2024-02-11 20:04:04 +01:00
|
|
|
#include <QLocale>
|
2026-08-14 07:39:22 +02:00
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// The project is a global object shared by all tests. A test leaving data behind in the project
|
|
|
|
|
/// makes the outcome of the tests running after it depend on the test order, and the test order is
|
|
|
|
|
/// not the same on all platforms.
|
|
|
|
|
///
|
|
|
|
|
/// Fail the test that leaves data behind, and close the project so the tests after it are unaffected.
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
class RiaProjectIsolationListener : public testing::EmptyTestEventListener
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
void OnTestEnd( const testing::TestInfo& ) override
|
|
|
|
|
{
|
|
|
|
|
RimProject* project = RimProject::current();
|
|
|
|
|
if ( !project ) return;
|
|
|
|
|
|
|
|
|
|
const QString leftovers = leftoverDescription( project );
|
|
|
|
|
if ( leftovers.isEmpty() ) return;
|
|
|
|
|
|
|
|
|
|
RiaApplication::instance()->closeProject();
|
|
|
|
|
|
|
|
|
|
ADD_FAILURE() << "The test left data behind in the shared project: " << leftovers.toStdString()
|
|
|
|
|
<< ". Call RiaApplication::instance()->closeProject() before the test completes.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString leftoverDescription( RimProject* project )
|
|
|
|
|
{
|
|
|
|
|
QStringList leftovers;
|
|
|
|
|
|
|
|
|
|
auto appendCount = [&leftovers]( const QString& description, size_t count )
|
|
|
|
|
{
|
|
|
|
|
if ( count > 0 ) leftovers.append( QString( "%1 %2" ).arg( count ).arg( description ) );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
appendCount( "grid case(s)", project->allGridCases().size() );
|
|
|
|
|
appendCount( "summary case(s)", project->allSummaryCases().size() );
|
|
|
|
|
appendCount( "summary ensemble(s)", project->summaryEnsembles().size() );
|
|
|
|
|
appendCount( "well path(s)", project->allWellPaths().size() );
|
|
|
|
|
appendCount( "view(s)", project->allViews().size() );
|
|
|
|
|
|
|
|
|
|
if ( !project->fileName().isEmpty() ) leftovers.append( "a project file name" );
|
|
|
|
|
|
|
|
|
|
return leftovers.join( ", " );
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-04-23 13:24:15 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-04-23 13:24:15 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
int main( int argc, char** argv )
|
2015-04-23 13:24:15 +02:00
|
|
|
{
|
2024-07-22 11:33:38 +02:00
|
|
|
// Create feature manager before the application object is created
|
|
|
|
|
RiaRegressionTestRunner::createSingleton();
|
2024-10-13 13:28:28 +02:00
|
|
|
RiaQuantityInfoTools::initializeSummaryKeywords();
|
2024-07-22 11:33:38 +02:00
|
|
|
|
2024-02-11 20:04:04 +01:00
|
|
|
RiaApplication* app = new RiaConsoleApplication( argc, argv );
|
|
|
|
|
app->initialize();
|
2015-04-23 13:24:15 +02:00
|
|
|
|
2024-02-11 20:04:04 +01:00
|
|
|
QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) );
|
|
|
|
|
setlocale( LC_NUMERIC, "C" );
|
2015-04-23 13:24:15 +02:00
|
|
|
|
2024-02-11 20:04:04 +01:00
|
|
|
testing::InitGoogleTest( &argc, argv );
|
2026-08-14 07:39:22 +02:00
|
|
|
|
|
|
|
|
// OnTestEnd is dispatched in reverse order of appending, so the listener appended last is the
|
|
|
|
|
// first to see the end of a test. The failure it reports is then part of the printed test result.
|
|
|
|
|
testing::UnitTest::GetInstance()->listeners().Append( new RiaProjectIsolationListener );
|
|
|
|
|
|
2015-04-23 13:24:15 +02:00
|
|
|
int result = RUN_ALL_TESTS();
|
|
|
|
|
return result;
|
|
|
|
|
}
|