#2361 AppFwk : Make sure field of FilePath supports space, add more tests

This commit is contained in:
Magne Sjaastad
2018-01-17 14:32:44 +01:00
parent c0d9ef67fa
commit 76b84cbb17
6 changed files with 139 additions and 4 deletions

View File

@@ -50,7 +50,19 @@ bool caf::FilePath::operator==(const FilePath& other) const
QTextStream& operator>>(QTextStream& str, caf::FilePath& filePath)
{
QString text;
str >> text;
while (str.status() == QTextStream::Ok)
{
// Read QChar to avoid white space trimming when reading QString
QChar singleChar;
str >> singleChar;
if (!singleChar.isNull())
{
text += singleChar;
}
}
filePath.setPath(text);
return str;

View File

@@ -12,6 +12,8 @@
#include "cafPdmReferenceHelper.h"
#include "cafPdmValueField.h"
#include <vector>
class DemoPdmObject: public caf::PdmObjectHandle
{
@@ -36,6 +38,7 @@ public:
this->addField(&m_memberStringField, "m_memberStringField");
// Default values
m_doubleMember = 2.1;
m_intMember = 7;
@@ -87,12 +90,18 @@ public:
this->addField(&m_texts, "Texts");
this->addField(&m_childArrayField, "DemoPdmObjectects");
this->addField(&m_ptrField, "m_ptrField");
this->addField(&m_singleFilePath, "m_singleFilePath");
this->addField(&m_multipleFilePath, "m_multipleFilePath");
}
caf::PdmDataValueField<QString > m_texts;
caf::PdmChildArrayField<DemoPdmObject*> m_childArrayField;
caf::PdmPtrField<InheritedDemoObj*> m_ptrField;
caf::PdmDataValueField<caf::FilePath> m_singleFilePath;
caf::PdmDataValueField<std::vector<caf::FilePath>> m_multipleFilePath;
};
@@ -589,3 +598,37 @@ TEST(BaseTest, PdmPointer)
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, PdmFilePath)
{
InheritedDemoObj* d = new InheritedDemoObj;
QVariant newVal = "path with space";
d->m_singleFilePath.setFromQVariant(newVal);
QVariant var = d->m_singleFilePath.toQVariant();
ASSERT_TRUE(newVal == var);
delete d;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, MultiplePdmFilePath)
{
InheritedDemoObj* d = new InheritedDemoObj;
QString newVal = "path with space";
d->m_multipleFilePath.v().push_back(newVal);
d->m_multipleFilePath.v().push_back(newVal);
QVariant var = d->m_multipleFilePath.toQVariant();
QStringList str = var.toStringList();
EXPECT_EQ(2, str.size());
delete d;
}