Skip to content
Snippets Groups Projects
Commit 1b3160e6 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Unit test for ComboProperty's XML.

parent b4661409
No related branches found
No related tags found
No related merge requests found
......@@ -67,7 +67,6 @@ class BA_CORE_API_ SessionWriter
public:
static void writeTo(QXmlStreamWriter *writer, SessionItem *parent);
static void writeItemAndChildItems(QXmlStreamWriter *writer, const SessionItem *item);
private:
static void writeVariant(QXmlStreamWriter *writer, QVariant variant, int role);
};
......@@ -77,10 +76,10 @@ public:
static void readItems(QXmlStreamReader *reader, SessionItem *item,
const QString &topTag = QString(),
WarningMessageService *messageService=0);
private:
static QString readProperty(QXmlStreamReader *reader, SessionItem *item,
WarningMessageService *messageService=0);
private:
static void report_error(WarningMessageService *messageService, SessionItem *item,
const QString &error_type, const QString &message);
};
......
#include <QtTest>
#include "ComboProperty.h"
#include "PropertyItem.h"
#include "SessionXML.h"
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QPair>
#include <QDebug>
#include <memory>
class TestComboProperty : public QObject {
Q_OBJECT
......@@ -9,6 +16,7 @@ private slots:
void test_VariantEquality();
void test_setValue();
void test_stringOfValues();
void test_comboXML();
};
inline void TestComboProperty::test_ComboEquality()
......@@ -79,5 +87,40 @@ inline void TestComboProperty::test_stringOfValues()
combo.setStringOfValues(stringOfValues);
QCOMPARE(combo.stringOfValues(), stringOfValues);
QCOMPARE(combo.getValue(), QString("b1"));
}
inline void TestComboProperty::test_comboXML()
{
// Wwiting combo to XML
ComboProperty combo = ComboProperty() << "a1" << "a2" << "a3";
QString buffer;
QXmlStreamWriter writer(&buffer);
SessionWriter::writeVariant(&writer, combo.getVariant(), 0);
QCOMPARE(buffer,
QString("<Parameter ParType=\"ComboProperty\" ParRole=\"0\" ParValue=\"a1\"/>"));
// reading from XML
std::unique_ptr<PropertyItem> item(new PropertyItem);
combo.setValue("a2");
item->setValue(combo.getVariant());
QXmlStreamReader reader(buffer);
while (!reader.atEnd()) {
reader.readNext();
if (reader.isStartElement()) {
if (reader.name() == SessionXML::ParameterTag) {
SessionReader::readProperty(&reader, item.get());
}
}
}
ComboProperty combo_property
= item->value().value<ComboProperty>();
QCOMPARE(combo_property.getValue(), QString("a1"));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment