mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-17 11:24:14 +02:00
fcc797342e
A folio report's label shows where its partner is (updateReportText()).
Changing any other information of the report -- a comment, a function --
ran elementInfoChanged(), which set the text from the label stored in
the report's information instead: the partner's position when the file
was last saved. Move the partner from column 4 to column 9, give the
report a comment, and it showed (and saved) 1-C4 again.
With lazy folios the partner is often built after the change, so the
report was recomputed and the two modes saved different files; that is
how this was found (FINDINGS F116, tools/lazy-folios/edit-diff.py).
New tst_reporttextafterinfo: move the partner, comment the report, save,
check the report says 1-C9, with folios built when needed and with every
folio built. Both rows fail without this change ("1-C4").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
4.1 KiB
C++
107 lines
4.1 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include <QtTest>
|
|
|
|
#include <QDir>
|
|
#include <QDomDocument>
|
|
#include <QFile>
|
|
#include <QProcess>
|
|
#include <QProcessEnvironment>
|
|
#include <QTemporaryDir>
|
|
|
|
// A folio report shows where its partner is. Changing any other
|
|
// information of the report wrote back the label stored in its
|
|
// information, the partner's position when the file was last saved, so
|
|
// the report pointed at the wrong place until the partner moved again
|
|
// (FINDINGS F116). Runs a script through the real binary's --run on
|
|
// examples/iso_sfc_example.qet: the "jump to" of folio 1 moves from
|
|
// column 4 to column 9, then the "jump from" on folio 2 gets a comment.
|
|
class tst_reporttextafterinfo : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
QTemporaryDir m_dir;
|
|
|
|
// The text a symbol @p uuid of @p saved shows for its label
|
|
static QString labelText(const QString &saved, const QString &uuid)
|
|
{
|
|
QFile file(saved);
|
|
if (!file.open(QIODevice::ReadOnly)) return QStringLiteral("(not saved)");
|
|
QDomDocument doc;
|
|
if (!doc.setContent(&file)) return QStringLiteral("(not read)");
|
|
const QDomNodeList elements = doc.elementsByTagName(QStringLiteral("element"));
|
|
for (int i = 0 ; i < elements.size() ; ++i) {
|
|
const QDomElement e = elements.at(i).toElement();
|
|
if (e.attribute(QStringLiteral("uuid")) != uuid) continue;
|
|
const QDomNodeList texts = e.elementsByTagName(QStringLiteral("dynamic_elmt_text"));
|
|
for (int j = 0 ; j < texts.size() ; ++j) {
|
|
const QDomElement t = texts.at(j).toElement();
|
|
if (t.firstChildElement(QStringLiteral("info_name")).text() == QLatin1String("label"))
|
|
return t.firstChildElement(QStringLiteral("text")).text();
|
|
}
|
|
}
|
|
return QStringLiteral("(no such text)");
|
|
}
|
|
|
|
private slots:
|
|
void initTestCase()
|
|
{
|
|
QVERIFY(m_dir.isValid());
|
|
QVERIFY(QFile::exists(QStringLiteral(QET_TEST_BINARY_PATH)));
|
|
}
|
|
|
|
void reportFollowsItsPartner_data()
|
|
{
|
|
QTest::addColumn<bool>("every_folio_built");
|
|
QTest::newRow("folios built when needed") << false;
|
|
QTest::newRow("every folio built") << true;
|
|
}
|
|
void reportFollowsItsPartner()
|
|
{
|
|
QFETCH(bool, every_folio_built);
|
|
const QString tag = every_folio_built ? QStringLiteral("eager") : QStringLiteral("lazy");
|
|
const QString saved = m_dir.filePath(tag + QStringLiteral(".qet"));
|
|
const QString script = m_dir.filePath(tag + QStringLiteral(".js"));
|
|
QFile f(script);
|
|
QVERIFY(f.open(QIODevice::WriteOnly));
|
|
f.write("qet.moveElement(0, '{bcf3d2e9-7190-48ed-bbb5-57bcc9ba8cfa}', 300, 0);\n"
|
|
"qet.setElementInfo(1, '{016d0266-33ac-4255-8fe2-4d9629a12d86}', 'comment', 'edited');\n"
|
|
"qet.save('" + saved.toUtf8() + "');\n");
|
|
f.close();
|
|
|
|
// Columns numbered from 1, as QElectroTech's settings page
|
|
// shows by default
|
|
const QString home = m_dir.filePath(tag + QStringLiteral("-home"));
|
|
QVERIFY(QDir().mkpath(home + QStringLiteral("/config/QElectroTech")));
|
|
QFile conf(home + QStringLiteral("/config/QElectroTech/QElectroTech.conf"));
|
|
QVERIFY(conf.open(QIODevice::WriteOnly));
|
|
conf.write("[General]\nborder-columns_0=false\n");
|
|
conf.close();
|
|
|
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("offscreen"));
|
|
env.insert(QStringLiteral("QET_ENABLE_SCRIPTING"), QStringLiteral("1"));
|
|
env.insert(QStringLiteral("HOME"), home);
|
|
env.insert(QStringLiteral("XDG_CONFIG_HOME"), home + QStringLiteral("/config"));
|
|
env.insert(QStringLiteral("XDG_DATA_HOME"), home + QStringLiteral("/data"));
|
|
env.insert(QStringLiteral("TMPDIR"), m_dir.path());
|
|
if (every_folio_built)
|
|
env.insert(QStringLiteral("QET_EAGER_FOLIOS"), QStringLiteral("1"));
|
|
else
|
|
env.remove(QStringLiteral("QET_EAGER_FOLIOS"));
|
|
QProcess proc;
|
|
proc.setProcessEnvironment(env);
|
|
proc.start(QStringLiteral(QET_TEST_BINARY_PATH),
|
|
{QStringLiteral("--run"), script,
|
|
QStringLiteral(QET_EXAMPLES_DIR "/iso_sfc_example.qet")});
|
|
QVERIFY(proc.waitForFinished(120000));
|
|
|
|
// The partner, moved, and the report that shows where it is
|
|
QCOMPARE(labelText(saved, QStringLiteral("{016d0266-33ac-4255-8fe2-4d9629a12d86}")),
|
|
QStringLiteral("1-C9"));
|
|
}
|
|
};
|
|
|
|
QTEST_APPLESS_MAIN(tst_reporttextafterinfo)
|
|
|
|
#include "tst_reporttextafterinfo.moc"
|