mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 14:14:15 +02:00
e25ae3cbfb
Review of #1109 (scorpio810): - tst_resaveunchanged now resaves every .qet in examples/ twice instead of two of them (24 rows, ~40 s). Dropping the load-time trim now also fails affuteuse_250h.qet, which the two-file version missed. - New case singleSpaceValueKept: a title-block property set to one space survives two saves (#973), and an accented property comes back unchanged. Fails if qetproject.cpp stops parsing with PreserveSpacingOnlyNodes. - New tst_diagramcontext: the QDom reader (projects) and the pugixml reader (element definitions in the collection) return the same value for plain, stray-spaced, accented and non-Latin text. Fails if the pugixml path decodes as Latin-1 or either reader stops trimming. The pugixml reader still reads a single-space value as "": pugixml drops whitespace-only text unless parse_ws_pcdata is set, as it did before this PR. That reader only sees element definitions, never a project, so #973's title-block values do not go through it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include <QtTest>
|
|
|
|
#include "diagramcontext.h"
|
|
#include "qetapp.h"
|
|
|
|
QString QETApp::m_interface_language;
|
|
|
|
/**
|
|
DiagramContext::fromXml() has two readers: QDom, for projects, and
|
|
pugixml, for element definitions in the collection. Both must give the
|
|
values the next save writes -- stray spaces around real content trimmed,
|
|
accented characters kept.
|
|
*/
|
|
class tst_diagramcontext : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
static QByteArray xml(const QString &value)
|
|
{
|
|
return QStringLiteral(
|
|
"<elementInformations>"
|
|
"<elementInformation name=\"v\" show=\"1\">%1</elementInformation>"
|
|
"</elementInformations>")
|
|
.arg(value)
|
|
.toUtf8();
|
|
}
|
|
|
|
static QString fromDom(const QByteArray &data)
|
|
{
|
|
QDomDocument doc;
|
|
if (!doc.setContent(data)) return QStringLiteral("<parse error>");
|
|
DiagramContext dc;
|
|
dc.fromXml(doc.documentElement(), QStringLiteral("elementInformation"));
|
|
return dc.value(QStringLiteral("v")).toString();
|
|
}
|
|
|
|
static QString fromPugi(const QByteArray &data)
|
|
{
|
|
pugi::xml_document doc;
|
|
if (!doc.load_buffer(data.constData(), size_t(data.size())))
|
|
return QStringLiteral("<parse error>");
|
|
DiagramContext dc;
|
|
dc.fromXml(doc.document_element(), QStringLiteral("elementInformation"));
|
|
return dc.value(QStringLiteral("v")).toString();
|
|
}
|
|
|
|
private slots:
|
|
void bothReadersAgree_data()
|
|
{
|
|
QTest::addColumn<QString>("value");
|
|
QTest::addColumn<QString>("expected");
|
|
|
|
QTest::newRow("plain") << "PRISE" << "PRISE";
|
|
QTest::newRow("stray spaces") << " PRISE " << "PRISE";
|
|
QTest::newRow("accents") << "Armoire façade été" << "Armoire façade été";
|
|
QTest::newRow("accents and stray spaces") << " Moteur à cage " << "Moteur à cage";
|
|
QTest::newRow("non-Latin") << "Двигатель 電機" << "Двигатель 電機";
|
|
}
|
|
|
|
void bothReadersAgree()
|
|
{
|
|
QFETCH(QString, value);
|
|
QFETCH(QString, expected);
|
|
QCOMPARE(fromDom(xml(value)), expected);
|
|
QCOMPARE(fromPugi(xml(value)), expected);
|
|
}
|
|
};
|
|
|
|
QTEST_APPLESS_MAIN(tst_diagramcontext)
|
|
|
|
#include "tst_diagramcontext.moc"
|