#8143 Review feedback

This commit is contained in:
Magne Sjaastad 2021-10-13 15:35:59 +02:00
parent 04b19e3ad7
commit 6bfdcebf0b
4 changed files with 73 additions and 71 deletions

View File

@ -98,7 +98,7 @@ RiaPreferencesSystem::RiaPreferencesSystem()
CAF_PDM_InitField( &m_eclipseReaderMode,
"eclipseReaderMode",
EclipseTextFileReaderModeType( RiaPreferencesSystem::EclipseTextFileReaderMode::FILE ),
"Default Summary Import Option",
"Eclipse Text File Import mode (GRDECL)",
"",
"",
"" );

View File

@ -106,8 +106,8 @@ std::pair<std::string, std::vector<float>>
if ( isFaultKeyword )
{
// Read data until the FAULTS section is closed with a single / on one line
const auto& trimmed = ltrim( line );
if ( !trimmed.empty() && trimmed[0] == '/' )
ltrim( line );
if ( !line.empty() && line[0] == '/' )
{
return std::make_pair( keywordName, values );
}
@ -119,10 +119,10 @@ std::pair<std::string, std::vector<float>>
if ( keywordName.empty() )
{
std::string candidate = trim( line );
if ( !candidate.empty() )
trim( line );
if ( !line.empty() )
{
keywordName = candidate;
keywordName = line;
if ( keywordName == "FAULTS" ) isFaultKeyword = true;
}
continue;
@ -225,25 +225,24 @@ std::string_view RifEclipseTextFileReader::readLine( const std::string_view& sou
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string& RifEclipseTextFileReader::rtrim( std::string& s, const char* t /*= ws */ )
void RifEclipseTextFileReader::rtrim( std::string& s, const char* t /*= ws */ )
{
s.erase( s.find_last_not_of( t ) + 1 );
return s;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string& RifEclipseTextFileReader::ltrim( std::string& s, const char* t /*= ws */ )
void RifEclipseTextFileReader::ltrim( std::string& s, const char* t /*= ws */ )
{
s.erase( 0, s.find_first_not_of( t ) );
return s;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string& RifEclipseTextFileReader::trim( std::string& s, const char* t /*= ws */ )
void RifEclipseTextFileReader::trim( std::string& s, const char* t /*= ws */ )
{
return ltrim( rtrim( s, t ), t );
rtrim( s, t );
ltrim( s, t );
}

View File

@ -58,13 +58,13 @@ public:
static std::string_view readLine( const std::string_view& source, const size_t offset, size_t& bytesRead );
// trim from end of string (right)
static std::string& rtrim( std::string& s, const char* t = m_whiteSpace );
static void rtrim( std::string& s, const char* t = m_whiteSpace );
// trim from beginning of string (left)
static std::string& ltrim( std::string& s, const char* t = m_whiteSpace );
static void ltrim( std::string& s, const char* t = m_whiteSpace );
// trim from both ends of string (right then left)
static std::string& trim( std::string& s, const char* t = m_whiteSpace );
static void trim( std::string& s, const char* t = m_whiteSpace );
// Parse string data for Eclipse keywords
static std::vector<RifEclipseKeywordContent> parseStringData( const std::string_view& stringData );

View File

@ -33,8 +33,9 @@
//--------------------------------------------------------------------------------------------------
TEST( RifEclipseTextFileReader, DISABLED_ReadKeywordsAndValuesPerformanceTest )
{
// std::string filename = "d:/scratchMsj/2021-10-13-norne-1M-single-grdecl/GRID.GRDECL";
// std::string filename = "e:/project/2021-10-13-norne-1M-single-grdecl/GRID.GRDECL";
// Remove DISABLED_ from the name of the test to run this performance test
// Intended to be executed locally
std::string filename = "c:/temp/GRID.GRDECL";
size_t iterationCount = 10;
@ -84,11 +85,8 @@ TEST( RifEclipseTextFileReader, DISABLED_ReadKeywordsAndValuesPerformanceTest )
//--------------------------------------------------------------------------------------------------
TEST( RifEclipseTextFileReader, ReadKeywordsAndValuesFromFile )
{
QString qtFileName = QString( "%1/RifEclipseTextFileParser/GRID.GRDECL" ).arg( TEST_DATA_DIR );
// "e:/gitroot-ceesol/ResInsight-regression-test/ModelData/TestCase_Ascii_no_map_axis/geocell.grdecl";
// filename = "d:/scratch/R5_H25_C1_aug_grid.grdecl";
std::string filename = qtFileName.toStdString();
QString qtFileName = QString( "%1/RifEclipseTextFileParser/GRID.GRDECL" ).arg( TEST_DATA_DIR );
std::string filename = qtFileName.toStdString();
auto objects = RifEclipseTextFileReader::readKeywordAndValues( filename );
@ -102,55 +100,60 @@ TEST( RifEclipseTextFileReader, ReadKeywordsAndValuesFromFile )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( RifEclipseTextFileReader, ReadLine )
TEST( RifEclipseTextFileReader, ReadLine_EmptyString )
{
{
// Empty string
std::string fileContent;
size_t offset = 0;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
std::string fileContent;
size_t offset = 0;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
EXPECT_EQ( size_t( 0 ), bytesRead );
EXPECT_EQ( size_t( 0 ), line.size() );
}
{
// Offset too large
std::string fileContent = "f";
size_t offset = 10;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
EXPECT_EQ( size_t( 0 ), bytesRead );
EXPECT_EQ( size_t( 0 ), line.size() );
}
{
// One line, no line break
std::string fileContent = "file content";
size_t offset = 0;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
EXPECT_EQ( size_t( 12 ), bytesRead );
EXPECT_EQ( size_t( 12 ), line.size() );
}
{
// two lines with line break
std::string fileContent = "file content\n next Line";
size_t offset = 0;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
// bytesRead includes line break
EXPECT_EQ( size_t( 13 ), bytesRead );
EXPECT_EQ( size_t( 12 ), line.size() );
auto secondLine = RifEclipseTextFileReader::readLine( fileContent, offset + bytesRead, bytesRead );
EXPECT_EQ( size_t( 10 ), bytesRead );
EXPECT_EQ( size_t( 9 ), secondLine.size() );
}
EXPECT_EQ( size_t( 0 ), bytesRead );
EXPECT_EQ( size_t( 0 ), line.size() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( RifEclipseTextFileReader, ReadLine_TooLargeOffset )
{
std::string fileContent = "f";
size_t offset = 10;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
EXPECT_EQ( size_t( 0 ), bytesRead );
EXPECT_EQ( size_t( 0 ), line.size() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( RifEclipseTextFileReader, ReadLine_SingleLineNoLineBreak )
{
std::string fileContent = "file content";
size_t offset = 0;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
EXPECT_EQ( size_t( 12 ), bytesRead );
EXPECT_EQ( size_t( 12 ), line.size() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( RifEclipseTextFileReader, ReadLine_TwoLinesWithLineBreak )
{
std::string fileContent = "file content\n next Line";
size_t offset = 0;
size_t bytesRead = 0;
auto line = RifEclipseTextFileReader::readLine( fileContent, offset, bytesRead );
// bytesRead includes line break
EXPECT_EQ( size_t( 13 ), bytesRead );
EXPECT_EQ( size_t( 12 ), line.size() );
auto secondLine = RifEclipseTextFileReader::readLine( fileContent, offset + bytesRead, bytesRead );
EXPECT_EQ( size_t( 10 ), bytesRead );
EXPECT_EQ( size_t( 9 ), secondLine.size() );
}