Skip to content

Commit

Permalink
Merge pull request #715 from OPM/dev
Browse files Browse the repository at this point in the history
Pull request for 1.6.0 for dev to master
  • Loading branch information
magnesj committed Jan 11, 2016
2 parents 6115d0a + cb16f3c commit bde4d86
Show file tree
Hide file tree
Showing 377 changed files with 41,364 additions and 4,843 deletions.
147 changes: 82 additions & 65 deletions ApplicationCode/Application/RiaApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

#include "RiuMainWindow.h"
#include "RiuProcessMonitor.h"
#include "RiuSelectionManager.h"
#include "RiuViewer.h"

#include "cafAppEnum.h"
Expand Down Expand Up @@ -207,6 +208,35 @@ RiaApplication* RiaApplication::instance()
}


//--------------------------------------------------------------------------------------------------
/// Return -1 if unit test is not executed, returns 0 if test passed, returns 1 if tests failed
//--------------------------------------------------------------------------------------------------
int RiaApplication::parseArgumentsAndRunUnitTestsIfRequested()
{
cvf::ProgramOptions progOpt;
progOpt.registerOption("unittest", "", "Execute unit tests");
progOpt.setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH);

QStringList arguments = QCoreApplication::arguments();

bool parseOk = progOpt.parse(cvfqt::Utils::toStringVector(arguments));
if (!parseOk)
{
return -1;
}

// Unit testing
// --------------------------------------------------------
if (cvf::Option o = progOpt.option("unittest"))
{
int testReturnValue = launchUnitTestsWithConsole();

return testReturnValue;
}

return -1;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -350,7 +380,6 @@ bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadActi
{
//printf("Create well path collection for oil field %i in loadProject.\n", oilFieldIdx);
oilField->wellPathCollection = new RimWellPathCollection();
oilField->wellPathCollection->setProject(m_project);
}

if (oilField->wellPathCollection) oilField->wellPathCollection->readWellPathFiles();
Expand Down Expand Up @@ -473,7 +502,6 @@ void RiaApplication::addWellPathsToModel(QList<QString> wellPathFilePaths)
{
//printf("Create well path collection.\n");
oilField->wellPathCollection = new RimWellPathCollection();
oilField->wellPathCollection->setProject(m_project);

m_project->updateConnectedEditors();
}
Expand All @@ -496,7 +524,6 @@ void RiaApplication::addWellLogsToModel(const QList<QString>& wellLogFilePaths)
if (oilField->wellPathCollection == NULL)
{
oilField->wellPathCollection = new RimWellPathCollection();
oilField->wellPathCollection->setProject(m_project);

m_project->updateConnectedEditors();
}
Expand Down Expand Up @@ -568,11 +595,20 @@ bool RiaApplication::saveProjectPromptForFileName()
bool RiaApplication::saveProjectAs(const QString& fileName)
{
m_project->fileName = fileName;
m_project->writeFile();

if (!m_project->writeFile())
{
QMessageBox::warning(NULL, "Error when saving project file", QString("Not possible to save project file. Make sure you have sufficient access rights.\n\nProject file location : %1").arg(fileName));

return false;
}

m_preferences->lastUsedProjectFileName = fileName;
caf::PdmSettings::writeFieldsToApplicationStore(m_preferences);

RiuMainWindow* mainWnd = RiuMainWindow::instance();
mainWnd->addRecentFiles(fileName);

return true;
}

Expand Down Expand Up @@ -608,6 +644,8 @@ bool RiaApplication::closeProject(bool askToSaveIfDirty)
}
}

RiuSelectionManager::instance()->deleteAllItems();

mainWnd->cleanupGuiBeforeProjectClose();

caf::EffectGenerator::clearEffectCache();
Expand Down Expand Up @@ -721,7 +759,7 @@ bool RiaApplication::openEclipseCase(const QString& caseName, const QString& cas

analysisModels->updateConnectedEditors();

RiuMainWindow::instance()->setCurrentObjectInTreeView(riv->cellResult());
RiuMainWindow::instance()->selectAsCurrentItem(riv->cellResult());


return true;
Expand Down Expand Up @@ -757,7 +795,7 @@ bool RiaApplication::openInputEclipseCaseFromFileNames(const QStringList& fileNa

analysisModels->updateConnectedEditors();

RiuMainWindow::instance()->setCurrentObjectInTreeView(riv->cellResult());
RiuMainWindow::instance()->selectAsCurrentItem(riv->cellResult());

return true;
}
Expand Down Expand Up @@ -803,7 +841,7 @@ bool RiaApplication::openOdbCaseFromFile(const QString& fileName)

m_project->updateConnectedEditors();

RiuMainWindow::instance()->setCurrentObjectInTreeView(riv->cellResult());
RiuMainWindow::instance()->selectAsCurrentItem(riv->cellResult());

return true;
}
Expand Down Expand Up @@ -1140,34 +1178,36 @@ bool RiaApplication::parseArguments()
return false;
}

// Unit testing
// --------------------------------------------------------
if (cvf::Option o = progOpt.option("unittest"))
{
launchUnitTests();
}

return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::launchUnitTests()
int RiaApplication::launchUnitTests()
{
#ifdef USE_UNIT_TESTS
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);

int argc = QCoreApplication::argc();
testing::InitGoogleTest(&argc, QCoreApplication::argv());

//int result = RUN_ALL_TESTS();
RUN_ALL_TESTS();
// 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
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::launchUnitTestsWithConsole()
int RiaApplication::launchUnitTestsWithConsole()
{
// Following code is taken from cvfAssert.cpp
#ifdef WIN32
Expand Down Expand Up @@ -1215,7 +1255,7 @@ void RiaApplication::launchUnitTestsWithConsole()
}
#endif

launchUnitTests();
return launchUnitTests();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1334,7 +1374,7 @@ void RiaApplication::slotWorkerProcessFinished(int exitCode, QProcess::ExitStatu
}

// If multiple cases are present, invoke launchProcess() which will set next current case, and run script on this case
if (m_currentCaseIds.size() > 0)
if (!m_currentCaseIds.empty())
{
launchProcess(m_currentProgram, m_currentArguments);
}
Expand All @@ -1353,7 +1393,7 @@ bool RiaApplication::launchProcess(const QString& program, const QStringList& ar
if (m_workerProcess == NULL)
{
// If multiple cases are present, pop the first case ID from the list and set as current case
if (m_currentCaseIds.size() > 0)
if (!m_currentCaseIds.empty())
{
int nextCaseId = m_currentCaseIds.front();
m_currentCaseIds.pop_front();
Expand Down Expand Up @@ -1619,6 +1659,10 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)

clearViewsScheduledForUpdate();

//riv->updateCurrentTimeStepAndRedraw();
riv->createDisplayModelAndRedraw();
viewer->repaint();

QString fileName = cas->caseUserDescription() + "-" + riv->name();
fileName.replace(" ", "_");

Expand Down Expand Up @@ -1713,6 +1757,19 @@ void RiaApplication::runRegressionTest(const QString& testRootPath)

RiaImageCompareReporter imageCompareReporter;

// Minor workaround
// Use registry to define if interactive diff images should be created
// Defined by user in RiaRegressionTest
{
QSettings settings;

bool useInteractiveDiff = settings.value("showInteractiveDiffImages").toBool();
if (useInteractiveDiff)
{
imageCompareReporter.showInteractiveOnly();
}
}

for (int dirIdx = 0; dirIdx < folderList.size(); ++dirIdx)
{
QDir testCaseFolder(folderList[dirIdx].filePath());
Expand All @@ -1731,21 +1788,6 @@ void RiaApplication::runRegressionTest(const QString& testRootPath)
// Open HTML report
QDesktopServices::openUrl(htmlReportFileName);

// Keep current preferences values to be able to restore when regression tests are completed
std::vector<QVariant> preferencesValues;
{
std::vector<caf::PdmFieldHandle*> fields;
this->preferences()->fields(fields);
for (size_t i = 0; i < fields.size(); i++)
{
QVariant v = fields[i]->uiCapability()->uiValue();
preferencesValues.push_back(v);
}
}

// Set preferences to make sure regression tests behave identical
this->preferences()->configureForRegressionTests();

for (int dirIdx = 0; dirIdx < folderList.size(); ++dirIdx)
{
QDir testCaseFolder(folderList[dirIdx].filePath());
Expand Down Expand Up @@ -1785,18 +1827,6 @@ void RiaApplication::runRegressionTest(const QString& testRootPath)

closeProject(false);
}

// Restore preferences
{
std::vector<caf::PdmFieldHandle*> fields;
this->preferences()->fields(fields);
CVF_ASSERT(fields.size() == preferencesValues.size());

for (size_t i = 0; i < preferencesValues.size(); i++)
{
fields[i]->uiCapability()->setValueFromUi(preferencesValues[i]);
}
}
}

m_runningRegressionTests = false;
Expand Down Expand Up @@ -1925,7 +1955,7 @@ bool RiaApplication::addEclipseCases(const QStringList& fileNames)

if (gridCaseGroup->statisticsCaseCollection()->reservoirs.size() > 0)
{
RiuMainWindow::instance()->setCurrentObjectInTreeView(gridCaseGroup->statisticsCaseCollection()->reservoirs[0]);
RiuMainWindow::instance()->selectAsCurrentItem(gridCaseGroup->statisticsCaseCollection()->reservoirs[0]);
}

return true;
Expand Down Expand Up @@ -2158,16 +2188,16 @@ void RiaApplication::executeCommandObjects()
{
toBeRemoved->redo();

it++;
++it;
m_commandQueue.remove(toBeRemoved);
}
else
{
it++;
++it;
}
}

if (m_commandQueue.size() > 0)
if (!m_commandQueue.empty())
{
std::list< RimCommandObject* >::iterator it = m_commandQueue.begin();

Expand Down Expand Up @@ -2245,19 +2275,6 @@ void RiaApplication::regressionTestConfigureProject()
// This size is set to match the regression test reference images
riv->viewer()->setFixedSize(1000, 745);
}

RimEclipseView* resvView = dynamic_cast<RimEclipseView*>(riv);

if (resvView)
{
resvView->faultCollection->setShowFaultsOutsideFilters(false);

caf::PdmUiFieldHandle* uiFieldHandle = resvView->faultResultSettings->showCustomFaultResult.uiCapability();
if (uiFieldHandle)
{
uiFieldHandle->setValueFromUi(false);
}
}
}
}
}
5 changes: 3 additions & 2 deletions ApplicationCode/Application/RiaApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class RiaApplication : public QApplication
~RiaApplication();
static RiaApplication* instance();

int parseArgumentsAndRunUnitTestsIfRequested();
bool parseArguments();

void executeRegressionTests(const QString& regressionTestPath);
Expand Down Expand Up @@ -159,8 +160,8 @@ class RiaApplication : public QApplication

bool isRunningRegressionTests() const;

void launchUnitTests();
void launchUnitTestsWithConsole();
int launchUnitTests();
int launchUnitTestsWithConsole();

private:
enum ProjectLoadAction
Expand Down
Loading

0 comments on commit bde4d86

Please sign in to comment.