mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-20 11:48:35 -06:00
Made sure an exception is also thrown for too few columns. Added a test for this use case.
This commit is contained in:
parent
3a5ef7fb86
commit
0da301a785
@ -111,8 +111,9 @@ void RifElementPropertyTableReader::readData( const RifElementPropertyMetadata*
|
||||
if ( file && expectedColumnCount > 0 )
|
||||
{
|
||||
QTextStream stream( file );
|
||||
bool dataBlockFound = false;
|
||||
int lineNo = 0;
|
||||
bool dataBlockFound = false;
|
||||
bool completeDataLineFound = false;
|
||||
int lineNo = 0;
|
||||
QStringList collectedCols;
|
||||
|
||||
// Init data vectors
|
||||
@ -126,6 +127,11 @@ void RifElementPropertyTableReader::readData( const RifElementPropertyMetadata*
|
||||
{
|
||||
if ( collectedCols.size() > 0 && collectedCols.size() != 8 )
|
||||
{
|
||||
if ( dataBlockFound )
|
||||
{
|
||||
throw FileParseException(
|
||||
QString( "Number of columns mismatch at %1:%2" ).arg( metadata->fileName ).arg( lineNo ) );
|
||||
}
|
||||
collectedCols.clear();
|
||||
}
|
||||
|
||||
@ -137,10 +143,11 @@ void RifElementPropertyTableReader::readData( const RifElementPropertyMetadata*
|
||||
}
|
||||
lineNo++;
|
||||
|
||||
if ( !dataBlockFound )
|
||||
if ( !completeDataLineFound )
|
||||
{
|
||||
if ( !line.startsWith( "*" ) && !line.startsWith( "," ) && collectedCols.size() == expectedColumnCount )
|
||||
{
|
||||
completeDataLineFound = true;
|
||||
dataBlockFound = true;
|
||||
}
|
||||
else if ( collectedCols.size() > expectedColumnCount )
|
||||
@ -185,7 +192,7 @@ void RifElementPropertyTableReader::readData( const RifElementPropertyMetadata*
|
||||
}
|
||||
}
|
||||
collectedCols.clear();
|
||||
dataBlockFound = false;
|
||||
completeDataLineFound = false;
|
||||
}
|
||||
|
||||
table->hasData = true;
|
||||
|
@ -36,12 +36,33 @@ TEST( RicElementPropertyTableReaderTest, BasicUsage )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RicElementPropertyTableReaderTest, ParseFailed )
|
||||
TEST( RicElementPropertyTableReaderTest, ParseFailedForTooManyColumns )
|
||||
{
|
||||
try
|
||||
{
|
||||
RifElementPropertyMetadata metadata =
|
||||
RifElementPropertyTableReader::readMetadata( ELEM_PROP_TEST_DATA_DIRECTORY + "ELASTIC_TABLE_error.inp" );
|
||||
RifElementPropertyTableReader::readMetadata( ELEM_PROP_TEST_DATA_DIRECTORY + "ELASTIC_TABLE_error_too_many_columns.inp" );
|
||||
|
||||
RifElementPropertyTable table;
|
||||
RifElementPropertyTableReader::readData( &metadata, &table );
|
||||
|
||||
EXPECT_TRUE( false );
|
||||
}
|
||||
catch ( FileParseException e )
|
||||
{
|
||||
EXPECT_TRUE( e.message.startsWith( "Number of columns mismatch" ) );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RicElementPropertyTableReaderTest, ParseFailedForTooFewColumns )
|
||||
{
|
||||
try
|
||||
{
|
||||
RifElementPropertyMetadata metadata = RifElementPropertyTableReader::readMetadata(
|
||||
ELEM_PROP_TEST_DATA_DIRECTORY + "ELASTIC_TABLE_error_too_few_columns.inp" );
|
||||
|
||||
RifElementPropertyTable table;
|
||||
RifElementPropertyTableReader::readData( &metadata, &table );
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user