mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3910 Unit test for reg exp validator
This commit is contained in:
parent
10da90350f
commit
975cd15c32
@ -237,6 +237,15 @@ void RimWellPathCompletions::setUnitSystemSpecificDefaults()
|
||||
m_perforationCollection->setUnitSystemSpecificDefaults();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QRegExp RimWellPathCompletions::wellNameForExportRegExp()
|
||||
{
|
||||
QRegExp rx("[\\w\\-\\_]{1,8}");
|
||||
return rx;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -295,9 +304,8 @@ void RimWellPathCompletions::defineEditorAttribute(const caf::PdmFieldHandle* fi
|
||||
caf::PdmUiLineEditorAttribute* lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>(attribute);
|
||||
if (field == &m_wellNameForExport && lineEditorAttr)
|
||||
{
|
||||
QRegExp rx("[\\w\\-\\_]{1,8}");
|
||||
QRegExpValidator* validator = new QRegExpValidator(nullptr);
|
||||
validator->setRegExp(rx);
|
||||
validator->setRegExp(wellNameForExportRegExp());
|
||||
lineEditorAttr->validator = validator;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
bool hasCompletions() const;
|
||||
|
||||
void setUnitSystemSpecificDefaults();
|
||||
|
||||
static QRegExp wellNameForExportRegExp();
|
||||
protected:
|
||||
void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName) override;
|
||||
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||
|
@ -53,6 +53,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCellDividingTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/Intersect-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifPerforationIntervalReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimWellPathCompletions-Test.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
50
ApplicationCode/UnitTests/RimWellPathCompletions-Test.cpp
Normal file
50
ApplicationCode/UnitTests/RimWellPathCompletions-Test.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RimWellPathCompletions.h"
|
||||
|
||||
#include <QRegExpValidator>
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RimWellPathCompletions, WellNameRegExp)
|
||||
{
|
||||
std::vector<QString> validNames = { "RASASD", "gf0sdf", "sd-ASD12", "1-AA_b" };
|
||||
std::vector<QString> invalidNames = { ".AdSD", "+gf0sdf", "sd ASD12", "ABCDEFGHIJKL" };
|
||||
|
||||
QRegExp rx = RimWellPathCompletions::wellNameForExportRegExp();
|
||||
EXPECT_TRUE(rx.isValid());
|
||||
|
||||
for (QString validName : validNames)
|
||||
{
|
||||
EXPECT_TRUE(rx.exactMatch(validName));
|
||||
}
|
||||
for (QString invalidName : invalidNames)
|
||||
{
|
||||
EXPECT_FALSE(rx.exactMatch(invalidName));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(RimWellPathCompletions, WellNameRegExpValidator)
|
||||
{
|
||||
std::vector<QString> validNames = {"RASASD", "gf0sdf", "sd-ASD12", "1-AA_b"};
|
||||
std::vector<QString> invalidNames = {".AdSD", "+gf0sdf", "sd ASD12", "ABCDEFGHIJKL"};
|
||||
QString emptyString = "";
|
||||
|
||||
QRegExp rx = RimWellPathCompletions::wellNameForExportRegExp();
|
||||
QRegExpValidator validator;
|
||||
validator.setRegExp(rx);
|
||||
|
||||
for (QString validName : validNames)
|
||||
{
|
||||
int dummyPos;
|
||||
EXPECT_EQ(QValidator::Acceptable, validator.validate(validName, dummyPos));
|
||||
}
|
||||
for (QString invalidName : invalidNames)
|
||||
{
|
||||
int dummyPos;
|
||||
EXPECT_EQ(QValidator::Invalid, validator.validate(invalidName, dummyPos));
|
||||
}
|
||||
|
||||
int dummyPos;
|
||||
EXPECT_EQ(QValidator::Intermediate, validator.validate(emptyString, dummyPos));
|
||||
}
|
Loading…
Reference in New Issue
Block a user