ResInsight/ApplicationCode/UnitTests/RifcCommandCore-Test.cpp

96 lines
3.5 KiB
C++
Raw Normal View History

2017-06-29 04:48:26 -05:00
#include "gtest/gtest.h"
#include "RifcCommandFileReader.h"
#include "RicfCommandObject.h"
#include "cafPdmField.h"
class TestCommand1: public RicfCommandObject
{
CAF_PDM_HEADER_INIT;
public:
TestCommand1()
{
RICF_InitField(&m_textArgument, "TextArgument", QString(), "TextArgument", "", "", "");
RICF_InitField(&m_doubleArgument, "DoubleArgument", 0.0, "DoubleArgument", "", "", "");
RICF_InitField(&m_intArgument, "IntArgument", 0, "IntArgument", "", "", "");
}
virtual void execute() override { std::cout << "TestCommand1::execute(" << "\"" << m_textArgument().toStdString() << "\", "
<< m_doubleArgument() << ", "
<< m_intArgument << ");" << std::endl; }
caf::PdmField<QString> m_textArgument;
caf::PdmField<double> m_doubleArgument;
caf::PdmField<int> m_intArgument;
};
CAF_PDM_SOURCE_INIT(TestCommand1, "TestCommand1");
class TC2: public RicfCommandObject
{
CAF_PDM_HEADER_INIT;
public:
TC2()
{
RICF_InitField(&m_textArgument, "ta", QString(), "TextArgument", "", "", "");
RICF_InitField(&m_doubleArgument, "da", 0.0, "DoubleArgument", "", "", "");
RICF_InitField(&m_intArgument, "ia", 0,"IntArgument", "", "", "");
}
virtual void execute() override { std::cout << "TC2::execute(" << "\"" << m_textArgument().toStdString() << "\", "
<< m_doubleArgument() << ", "
<< m_intArgument << ");" << std::endl; }
caf::PdmField<QString> m_textArgument;
caf::PdmField<double> m_doubleArgument;
caf::PdmField<int> m_intArgument;
};
CAF_PDM_SOURCE_INIT(TC2, "TC2");
2017-06-29 04:48:26 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RicfCommands, Test1)
{
QString commandString("TestCommand1(IntArgument=3, TextArgument=\"Dette er en tekst, \\\"og\\\" jeg er: (happy)\", DoubleArgument=5.0e3) \n"
"TestCommand1 ( IntArgument = 4 , \n TextArgument = \"Dette er en tekst, \\\"og\\\" jeg er: (happy)\", \n DoubleArgument = 5.0e-3 ) \n"
" TestCommand1(TextArgument=\"Litt kortere tekst.\") \n"
"TC2 ( ta = \"Hepp\", ia = 3, da= 0.123)");
//std::cout << commandString.toStdString() << std::endl;
2017-06-29 04:48:26 -05:00
QTextStream inputStream(&commandString);
auto objects = RicfCommandFileReader::readCommands(inputStream, caf::PdmDefaultObjectFactory::instance());
EXPECT_EQ(4, objects.size());
2017-06-29 04:48:26 -05:00
auto tc2 = dynamic_cast<TestCommand1*>(objects[0]);
EXPECT_EQ(39, tc2->m_textArgument().size());
EXPECT_EQ(5.0e3, tc2->m_doubleArgument());
2017-06-29 04:48:26 -05:00
tc2 = dynamic_cast<TestCommand1*>(objects[1]);
EXPECT_EQ(39, tc2->m_textArgument().size());
2017-06-29 04:48:26 -05:00
EXPECT_EQ(5e-3, tc2->m_doubleArgument());
2017-06-29 04:48:26 -05:00
tc2 = dynamic_cast<TestCommand1*>(objects[2]);
EXPECT_EQ(19, tc2->m_textArgument().size());
EXPECT_EQ(0.0, tc2->m_doubleArgument());
auto tc3 = dynamic_cast<TC2*>(objects[3]);
EXPECT_EQ(4, tc3->m_textArgument().size());
EXPECT_EQ(0.123, tc3->m_doubleArgument());
EXPECT_EQ(3, tc3->m_intArgument());
2017-06-29 04:48:26 -05:00
for (auto obj: objects)
{
obj->execute();
}
for (auto obj: objects)
{
delete(obj);
}
}