#3513 System : Add test code for RicfObjectCapability::writeFields

This commit is contained in:
Magne Sjaastad 2018-11-07 10:38:00 +01:00
parent 95aaa35383
commit 54434d8f7d
3 changed files with 53 additions and 1 deletions

View File

@ -200,11 +200,12 @@ void RicfObjectCapability::writeFields(QTextStream& outputStream) const
if ( writtenFieldCount >= 1 )
{
outputStream << ", ";
++writtenFieldCount;
}
outputStream << keyword << " = ";
rcfField->writeFieldData(outputStream);
writtenFieldCount++;
}
}
}

View File

@ -142,5 +142,16 @@ std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream&
//--------------------------------------------------------------------------------------------------
void RicfCommandFileReader::writeCommands(QTextStream& outputStream, const std::vector<RicfCommandObject*>& commandsToWrite)
{
for (const auto& cmdObj : commandsToWrite)
{
auto rcfCap = cmdObj->capability<RicfObjectCapability>();
if (!rcfCap) continue;
outputStream << cmdObj->classKeyword();
outputStream << "(";
rcfCap->writeFields(outputStream);
outputStream << ")";
}
}

View File

@ -281,3 +281,43 @@ TEST(RicfCommands, IgnoreCommentLinesShowErrorLine)
EXPECT_EQ((size_t)1, errors.m_messages.size());
EXPECT_EQ((size_t)6, objects.size());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RicfCommands, WriteCommand)
{
TestCommand1 testCmd;
testCmd.m_textArgument = "My Test";
testCmd.m_doubleArgument = 1.123;
testCmd.m_intArgument = -123;
testCmd.m_boolArgument = true;
QString commandString;
{
QTextStream inputStream(&commandString);
std::vector<RicfCommandObject*> cmdObjects;
cmdObjects.push_back(&testCmd);
RicfCommandFileReader::writeCommands(inputStream, cmdObjects);
EXPECT_FALSE(commandString.isEmpty());
}
{
QTextStream inputStream(&commandString);
RicfMessages errors;
auto objects = RicfCommandFileReader::readCommands(inputStream, caf::PdmDefaultObjectFactory::instance(), &errors);
EXPECT_EQ((size_t)1, objects.size());
TestCommand1* myObj = dynamic_cast<TestCommand1*>(objects.front());
EXPECT_TRUE(myObj != nullptr);
EXPECT_STREQ(testCmd.m_textArgument().toStdString().data(), myObj->m_textArgument().toStdString().data());
EXPECT_EQ(testCmd.m_doubleArgument, myObj->m_doubleArgument);
EXPECT_EQ(testCmd.m_intArgument, myObj->m_intArgument);
EXPECT_EQ(testCmd.m_boolArgument, myObj->m_boolArgument);
}
}