#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, CAF_PDM_InitField( &m_eclipseReaderMode,
"eclipseReaderMode", "eclipseReaderMode",
EclipseTextFileReaderModeType( RiaPreferencesSystem::EclipseTextFileReaderMode::FILE ), 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 ) if ( isFaultKeyword )
{ {
// Read data until the FAULTS section is closed with a single / on one line // Read data until the FAULTS section is closed with a single / on one line
const auto& trimmed = ltrim( line ); ltrim( line );
if ( !trimmed.empty() && trimmed[0] == '/' ) if ( !line.empty() && line[0] == '/' )
{ {
return std::make_pair( keywordName, values ); return std::make_pair( keywordName, values );
} }
@ -119,10 +119,10 @@ std::pair<std::string, std::vector<float>>
if ( keywordName.empty() ) if ( keywordName.empty() )
{ {
std::string candidate = trim( line ); trim( line );
if ( !candidate.empty() ) if ( !line.empty() )
{ {
keywordName = candidate; keywordName = line;
if ( keywordName == "FAULTS" ) isFaultKeyword = true; if ( keywordName == "FAULTS" ) isFaultKeyword = true;
} }
continue; 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 ); 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 ) ); 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 ); static std::string_view readLine( const std::string_view& source, const size_t offset, size_t& bytesRead );
// trim from end of string (right) // 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) // 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) // 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 // Parse string data for Eclipse keywords
static std::vector<RifEclipseKeywordContent> parseStringData( const std::string_view& stringData ); static std::vector<RifEclipseKeywordContent> parseStringData( const std::string_view& stringData );

View File

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