#2554 Regression Test : Add text file compare tool and display folder in test config

This commit is contained in:
Magne Sjaastad 2018-03-07 09:06:42 +01:00
parent 91428a028d
commit cec745d08a
11 changed files with 321 additions and 4 deletions

View File

@ -20,6 +20,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaSimWellBranchTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaProjectFileVersionTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaStringEncodingTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaTextStringTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaTextFileCompare.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -43,6 +44,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaSimWellBranchTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaProjectFileVersionTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaStringEncodingTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaTextStringTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaTextFileCompare.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -33,6 +33,9 @@ RiaRegressionTest::RiaRegressionTest(void)
CAF_PDM_InitFieldNoDefault(&folderContainingCompareTool, "workingFolder", "Folder containing <b>compare</b>", "", "Location of compare tool from Image Magic suite", "");
folderContainingCompareTool.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
CAF_PDM_InitFieldNoDefault(&folderContainingDiffTool, "folderContainingDiffTool", "Folder containing <b>diff</b>", "", "Location of diff tool used for text compare", "");
folderContainingDiffTool.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
CAF_PDM_InitFieldNoDefault(&regressionTestFolder, "regressionTestFolder", "Regression Test Folder", "", "", "");
regressionTestFolder.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
@ -71,7 +74,7 @@ void RiaRegressionTest::readSettingsFromApplicationStore()
//--------------------------------------------------------------------------------------------------
void RiaRegressionTest::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
if (field == &folderContainingCompareTool || field == &regressionTestFolder)
if (field == &folderContainingDiffTool || field == &folderContainingCompareTool || field == &regressionTestFolder)
{
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>(attribute);
if (myAttr)
@ -80,5 +83,3 @@ void RiaRegressionTest::defineEditorAttribute(const caf::PdmFieldHandle* field,
}
}
}

View File

@ -37,6 +37,7 @@ public:
public:
caf::PdmField<QString> folderContainingCompareTool;
caf::PdmField<QString> folderContainingDiffTool;
caf::PdmField<QString> regressionTestFolder;
caf::PdmField<QString> testFilter;
caf::PdmField<bool> showInteractiveDiffImages;

View File

@ -0,0 +1,139 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 Statoil 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
// 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 "RiaTextFileCompare.h"
#include "cafUtils.h"
#include <QProcess>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaTextFileCompare::RiaTextFileCompare(const QString& pathToDiffTool)
: m_pathToDiffTool(pathToDiffTool)
{
reset();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaTextFileCompare::~RiaTextFileCompare() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaTextFileCompare::reset()
{
m_lastError = IC_NO_ERROR;
m_errorMsg.clear();
m_errorDetails.clear();
m_diffOutput.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaTextFileCompare::runComparison(const QString& baseFolder, const QString& generatedFolder)
{
reset();
QString fullFilePath = "diff";
if (!m_pathToDiffTool.isEmpty())
{
fullFilePath = m_pathToDiffTool + "/" + fullFilePath;
}
// Run compare recursively with '-r'
QString args = "-r";
QString completeCommand = QString("\"%1\" %2 %3 %4").arg(fullFilePath).arg(baseFolder).arg(generatedFolder).arg(args);
// Launch process and wait
QProcess proc;
proc.start(completeCommand);
proc.waitForFinished(30000);
QProcess::ProcessError procError = proc.error();
if (procError != QProcess::UnknownError)
{
m_lastError = SEVERE_ERROR;
m_errorMsg = "Error running 'diff' tool process";
m_errorDetails = completeCommand;
return false;
}
QByteArray stdErr = proc.readAllStandardError();
int procExitCode = proc.exitCode();
if (procExitCode == 0)
{
return true;
}
else if (procExitCode == 1)
{
QByteArray stdOut = proc.readAllStandardOutput();
m_diffOutput = stdOut;
return false;
}
else
{
stdErr = stdErr.simplified();
// Report non-severe error
m_lastError = IC_ERROR;
m_errorMsg = "Error running 'diff' tool process";
m_errorDetails = stdErr;
return false;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaTextFileCompare::ErrorType RiaTextFileCompare::error() const
{
return m_lastError;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaTextFileCompare::errorMessage() const
{
return m_errorMsg;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaTextFileCompare::errorDetails() const
{
return m_errorDetails;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaTextFileCompare::diffOutput() const
{
return m_diffOutput;
}

View File

@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 Statoil 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
// 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 <QString>
//==================================================================================================
//
// Execute text compare between to folders recursively using the external tool 'diff'
//
//==================================================================================================
class RiaTextFileCompare
{
public:
enum ErrorType
{
IC_NO_ERROR, // No error occurred
IC_ERROR, // An error occurred
SEVERE_ERROR // Severe error occurred, it is likely that another call to compare() will also fail
};
public:
explicit RiaTextFileCompare(const QString& pathToDiffTool);
~RiaTextFileCompare();
bool runComparison(const QString& baseFolder, const QString& generatedFolder);
ErrorType error() const;
QString errorMessage() const;
QString errorDetails() const;
QString diffOutput() const;
private:
void reset();
private:
const QString m_pathToDiffTool;
ErrorType m_lastError;
QString m_errorMsg;
QString m_errorDetails;
QString m_diffOutput;
};

View File

@ -38,7 +38,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaProjectFileVersionTools-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyTableReader-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RimRelocatePath-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RigTransmissibilityCondenser-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseUnitTools-Test
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseUnitTools-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaTextFileCompare-Test.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,68 @@
#include "gtest/gtest.h"
#include "RiaRegressionTest.h"
#include "RiaTestDataDirectory.h"
#include "RiaTextFileCompare.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RiaTextFileCompareTest, BasicCompareWithDiff)
{
RiaRegressionTest regTestConfig;
regTestConfig.readSettingsFromApplicationStore();
QString folderContainingDiff = regTestConfig.folderContainingDiffTool();
QString baseFolder = QString("%1/TextCompare/base").arg(TEST_DATA_DIR);
QString referenceFolder = QString("%1/TextCompare/reference").arg(TEST_DATA_DIR);
RiaTextFileCompare compare(folderContainingDiff);
bool noDifference = compare.runComparison(baseFolder, referenceFolder);
EXPECT_FALSE(noDifference);
QString diffOutput = compare.diffOutput();
EXPECT_FALSE(diffOutput.isEmpty());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RiaTextFileCompareTest, BasicCompareNoDiff)
{
RiaRegressionTest regTestConfig;
regTestConfig.readSettingsFromApplicationStore();
QString folderContainingDiff = regTestConfig.folderContainingDiffTool();
QString baseFolder = QString("%1/TextCompare/base/folderB").arg(TEST_DATA_DIR);
QString referenceFolder = QString("%1/TextCompare/reference/folderB").arg(TEST_DATA_DIR);
RiaTextFileCompare compare(folderContainingDiff);
bool noDifference = compare.runComparison(baseFolder, referenceFolder);
EXPECT_TRUE(noDifference);
QString diffOutput = compare.diffOutput();
EXPECT_TRUE(diffOutput.isEmpty());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RiaTextFileCompareTest, BasicCompareError)
{
RiaRegressionTest regTestConfig;
regTestConfig.readSettingsFromApplicationStore();
QString folderContainingDiff = regTestConfig.folderContainingDiffTool();
QString baseFolder = QString("%1/TextCompare/baseDoesNotExist").arg(TEST_DATA_DIR);
QString referenceFolder = QString("%1/TextCompare/reference/folderB").arg(TEST_DATA_DIR);
RiaTextFileCompare compare(folderContainingDiff);
bool noDifference = compare.runComparison(baseFolder, referenceFolder);
EXPECT_FALSE(noDifference);
QString error = compare.errorMessage();
EXPECT_FALSE(error.isEmpty());
}

View File

@ -0,0 +1,12 @@
some text
some more text
some more text
some more text some more text some more text
some more text
some more text
some more text
some more text

View File

@ -0,0 +1,12 @@
some text
some more text
some more text
some more text some more text some more text
some more text
some more text
some more text
some more text

View File

@ -0,0 +1,12 @@
some text
some more text
some more text somthing has changed
some more text some more text some more text
some more text
some more text
some more text
some more text

View File

@ -0,0 +1,12 @@
some text
some more text
some more text
some more text some more text some more text
some more text
some more text
some more text
some more text