#1719 Fix issue with commands without parameters in command file

This commit is contained in:
Bjørnar Grip Fjær
2017-08-04 13:58:32 +02:00
parent 37456bfa9b
commit 5e48494c9b
2 changed files with 61 additions and 23 deletions

View File

@@ -55,45 +55,55 @@ void RicfObjectCapability::readFields(QTextStream& inputStream,
while ( !inputStream.atEnd() && !isLastArgumentRead )
{
// Read field keyword
bool fieldDataFound = true;
bool fieldDataFound = false;
bool isEndOfArgumentFound = false;
QString keyword;
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
while ( !inputStream.atEnd() )
{
QChar currentChar;
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if ( currentChar.isSpace() )
while (!inputStream.atEnd())
{
// Must skip to, and read "="
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if ( currentChar != QChar('=') )
if (currentChar == QChar('=') || currentChar == QChar(')') || currentChar == QChar(',') || currentChar.isSpace())
{
// Error message: Missing "=" after argument name
errorMessageContainer->addError("Can't find the '=' after the argument named: \"" + keyword + "\" in the command: \"" + errorMessageContainer->currentCommand + "\"" );
fieldDataFound = false;
if (currentChar == QChar(')') )
{
isLastArgumentRead = true;
}
else if (currentChar == QChar(',') )
{
isEndOfArgumentFound = true;
}
break;
}
break;
else
{
keyword += currentChar;
}
}
if ( currentChar == QChar('=') )
if (currentChar.isSpace())
{
break;
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
}
keyword += currentChar;
if (currentChar == QChar('='))
{
fieldDataFound = true;
}
else if (currentChar == QChar(')'))
{
if (!keyword.isNull())
{
errorMessageContainer->addError(QString("Can't find the '=' after the argument named '%1' in the command '%2'").arg(keyword).arg(errorMessageContainer->currentCommand));
}
isLastArgumentRead = true;
}
else if (currentChar == QChar(','))
{
errorMessageContainer->addError(QString("Can't find the '=' after the argument named '%1' in the command '%2'").arg(keyword).arg(errorMessageContainer->currentCommand));
isEndOfArgumentFound = true;
}
else
{
errorMessageContainer->addError(QString("Can't find the '=' after the argument named '%1' in the command '%2'").arg(keyword).arg(errorMessageContainer->currentCommand));
}
}
if ( readFields.count(keyword) )

View File

@@ -117,6 +117,12 @@ TEST(RicfCommands, ErrorMessages)
EXPECT_EQ((size_t)2, objects.size());
EXPECT_EQ((size_t)5, errors.m_messages.size());
// Errors should be:
// Line 1 : TesCommand1 does not exist
// Line 2 : Unreadable value for argument IntArgument
// Line 3 : Can't find = after argument named TextA (space withing argument name)
// Line 4 : Can't find = after argument named DoubleArgument
// Line 5 : Missing quotes around TextArgument value
for (const auto& msg: errors.m_messages)
{
@@ -137,3 +143,25 @@ TEST(RicfCommands, ErrorMessages)
delete(obj);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RicfCommands, EmptyArgumentList)
{
// Ensure no error messages when command with no arguments is read
QString commandString("TestCommand1()");
QTextStream inputStream(&commandString);
RicfMessages errors;
auto objects = RicfCommandFileReader::readCommands(inputStream, caf::PdmDefaultObjectFactory::instance(), &errors);
EXPECT_EQ((size_t)1, objects.size());
EXPECT_EQ((size_t)0, errors.m_messages.size());
for (auto obj : objects)
{
delete(obj);
}
}