mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
Replace the QString* errorMessage out-parameter with std::expected<RigFormationNames, QString> in RifFormationNamesReader, and propagate the pattern to RimFormationNames::readFormationNamesFile() which now returns std::expected<void, QString>. Fatal errors (file cannot be opened, FMU line-parse failure) return std::unexpected. Malformed .lyr lines are still skipped so the rest of the file loads, with warnings logged via RiaLogging instead of collected in the out-parameter. RimFormationNamesCollection::readAllFormationNames() now logs errors it previously discarded.
80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
#include "gtest/gtest.h"
|
|
|
|
#include "RiaTestDataDirectory.h"
|
|
#include "RifFormationNamesReader.h"
|
|
#include "RigFormationNames.h"
|
|
|
|
#include "cvfColor3.h"
|
|
|
|
#include <QDir>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
TEST( RifFormationNamesReader, ReadLYRFileWithoutColor )
|
|
{
|
|
QDir baseFolder( TEST_DATA_DIR );
|
|
|
|
const QString filename( "RifFormationNamesReader/Norne_ATW2013.lyr" );
|
|
const QString filePath = baseFolder.absoluteFilePath( filename );
|
|
EXPECT_TRUE( QFile::exists( filePath ) );
|
|
|
|
auto fm = RifFormationNamesReader::readFormationNamesFile( filePath );
|
|
ASSERT_TRUE( fm.has_value() );
|
|
|
|
QString formationName_K1 = fm->formationNameFromKLayerIdx( 0 );
|
|
int formationIndex = fm->formationIndexFromKLayerIdx( 1 );
|
|
|
|
EXPECT_TRUE( formationName_K1 == "Garn 3" );
|
|
EXPECT_EQ( 1, formationIndex );
|
|
}
|
|
|
|
TEST( RifFormationNamesReader, ReadLYRFileWithColorName )
|
|
{
|
|
QDir baseFolder( TEST_DATA_DIR );
|
|
|
|
const QString filename( "RifFormationNamesReader/Norne_ATW2013ColorName.lyr" );
|
|
const QString filePath = baseFolder.absoluteFilePath( filename );
|
|
EXPECT_TRUE( QFile::exists( filePath ) );
|
|
|
|
auto fm = RifFormationNamesReader::readFormationNamesFile( filePath );
|
|
ASSERT_TRUE( fm.has_value() );
|
|
|
|
QString formationName_K1 = fm->formationNameFromKLayerIdx( 1 );
|
|
int formationIndex = fm->formationIndexFromKLayerIdx( 1 );
|
|
|
|
cvf::Color3f formationColor;
|
|
bool colorPresent = fm->formationColorFromKLayerIdx( 1, &formationColor );
|
|
EXPECT_TRUE( colorPresent );
|
|
|
|
EXPECT_TRUE( formationName_K1 == "Garn 2" );
|
|
EXPECT_EQ( 1, formationIndex );
|
|
EXPECT_EQ( 1.0f, formationColor.r() );
|
|
EXPECT_EQ( 0.0f, formationColor.g() );
|
|
EXPECT_EQ( 0.0f, formationColor.b() );
|
|
}
|
|
|
|
TEST( RifFormationNamesReader, ReadLYRFileWithColorHTML )
|
|
{
|
|
QDir baseFolder( TEST_DATA_DIR );
|
|
|
|
const QString filename( "RifFormationNamesReader/Norne_ATW2013ColorHTML.lyr" );
|
|
const QString filePath = baseFolder.absoluteFilePath( filename );
|
|
EXPECT_TRUE( QFile::exists( filePath ) );
|
|
|
|
auto fm = RifFormationNamesReader::readFormationNamesFile( filePath );
|
|
ASSERT_TRUE( fm.has_value() );
|
|
|
|
QString formationName_K1 = fm->formationNameFromKLayerIdx( 1 );
|
|
int formationIndex = fm->formationIndexFromKLayerIdx( 1 );
|
|
|
|
cvf::Color3f formationColor;
|
|
bool colorPresent = fm->formationColorFromKLayerIdx( 1, &formationColor );
|
|
EXPECT_TRUE( colorPresent );
|
|
|
|
EXPECT_TRUE( formationName_K1 == "Garn 2" );
|
|
EXPECT_EQ( 1, formationIndex );
|
|
EXPECT_EQ( 1.0f, formationColor.r() );
|
|
EXPECT_EQ( 0.0f, formationColor.g() );
|
|
EXPECT_EQ( 0.0f, formationColor.b() );
|
|
}
|