Skip to content

Commit

Permalink
Regression Test: Find relevant objects and show them in Property Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Oct 2, 2024
1 parent f8ce59a commit 7d84c11
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaRegressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ RiaRegressionTest::RiaRegressionTest()
CAF_PDM_InitField( &appendTestsAfterTestFilter, "appendTestsAfterTestFilter", false, "Append All Tests After Test Filter" );

CAF_PDM_InitField( &invalidateExternalFilePaths, "invalidateExternalFilePaths", false, "Invalidate External File Paths" );
CAF_PDM_InitField( &activateObjectsInPropertyEditor, "activateObjectsInPropertyEditor", false, "Activate Objects In Property Editor" );

CAF_PDM_InitFieldNoDefault( &overridePlotEngine, "forcePlotEngine", "Force Plot Engine" );

CAF_PDM_InitField( &exportSnapshots3dViews, "exportSnapshots3dViews", true, "Export Snapshots 3D Views" );
Expand Down
1 change: 1 addition & 0 deletions ApplicationLibCode/Application/Tools/RiaRegressionTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RiaRegressionTest : public caf::PdmObject
caf::PdmField<bool> openReportInBrowser;
caf::PdmField<bool> appendTestsAfterTestFilter;
caf::PdmField<bool> invalidateExternalFilePaths;
caf::PdmField<bool> activateObjectsInPropertyEditor;

caf::PdmField<bool> exportSnapshots3dViews;
caf::PdmField<bool> exportSnapshotsPlots;
Expand Down
84 changes: 84 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaRegressionTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@

#include "Rim3dView.h"
#include "RimCase.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseResultAddress.h"
#include "RimFaultInView.h"
#include "RimMainPlotCollection.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimSimWellInView.h"
#include "RimSummaryCaseMainCollection.h"

#include "RiuDockWidgetTools.h"
#include "RiuMainWindow.h"
Expand All @@ -47,6 +53,7 @@
#include "DockManager.h"

#include "cafMemoryInspector.h"
#include "cafPdmUiTreeView.h"
#include "cafUtils.h"

#include <QDateTime>
Expand Down Expand Up @@ -255,6 +262,11 @@ void RiaRegressionTestRunner::runRegressionTest()

uint64_t usedMemoryBeforeClose = caf::MemoryInspector::getApplicationPhysicalMemoryUsageMiB();

if ( regressionTestConfig.activateObjectsInPropertyEditor )
{
RiaRegressionTestRunner::selectObjectsInProject();
}

app->closeProject();

QApplication::processEvents();
Expand Down Expand Up @@ -632,6 +644,78 @@ QFileInfoList RiaRegressionTestRunner::subDirectoriesForTestExecution( const QDi
return foldersMatchingTestFilter;
}

//--------------------------------------------------------------------------------------------------
/// Find relevant object to show in property editor. Loop through all objects in project and select them, this will activate the Property
/// Editor. Avoid RimSummaryCaseMainCollection, as this container contains all the summary addresses, and can potentially contain extremely
/// many objects
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::selectObjectsInProject()
{
auto project = RimProject::current();
if ( !project ) return;

std::vector<caf::PdmObject*> baseObjects;

auto oilField = project->activeOilField();

std::vector<caf::PdmFieldHandle*> fields = oilField->fields();
for ( auto f : fields )
{
std::vector<caf::PdmObjectHandle*> childObjects = f->children();
for ( auto childObject : childObjects )
{
// Skip RimSummaryCaseMainCollection, as this container contains all the summary addresses, and can potentially contain extemely
// many objects
if ( dynamic_cast<RimSummaryCaseMainCollection*>( childObject ) != nullptr )
{
continue;
}

caf::PdmObject* pdmObjectChild = dynamic_cast<caf::PdmObject*>( childObject );
if ( pdmObjectChild )
{
baseObjects.push_back( pdmObjectChild );
}
}
}

baseObjects.push_back( project->mainPlotCollection() );

std::vector<caf::PdmObject*> allObjects;
for ( auto baseObj : baseObjects )
{
auto objectsForSelection = baseObj->descendantsIncludingThisOfType<caf::PdmObject>();

allObjects.insert( allObjects.end(), objectsForSelection.begin(), objectsForSelection.end() );
}

QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );

auto mainWindow = RiuMainWindow::instance();
auto plotMainWindow = RiuPlotMainWindow::instance();

for ( auto obj : allObjects )
{
if ( dynamic_cast<RimFaultInView*>( obj ) ) continue;
if ( dynamic_cast<RimEclipseResultAddress*>( obj ) ) continue;
if ( dynamic_cast<RimSimWellInView*>( obj ) ) continue;

if ( auto treeView = mainWindow->getTreeViewWithItem( obj ) )
{
treeView->selectItems( { obj } );

QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
}

if ( auto treeView = plotMainWindow->getTreeViewWithItem( obj ) )
{
treeView->selectItems( { obj } );

QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
}
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class RiaRegressionTestRunner
static QString diff2htmlHeaderText( const QString& testRootPath );
QFileInfoList subDirectoriesForTestExecution( const QDir& directory );

static void selectObjectsInProject();

private:
QString m_rootPath;
QStringList m_testFilter;
Expand Down

0 comments on commit 7d84c11

Please sign in to comment.