Files
qelectrotech-source-mirror/tests/qttest/tst_terminalnamecheck.cpp
T
ispyisail bd4d942d71 Add a terminal name check when saving an element
Discussion #1157. IEC 61666 §4.1 requires each terminal to be
identified unambiguously within its object, so two terminals of one
element must not share a name.

On save, the element editor now:
- refuses to save when two terminals share a name, lists the names
  ("N ×3") and selects those terminals;
- warns, and still saves, when a terminal has no name. Folio reports,
  conductor definitions and thumbnails are skipped.

Names are compared after trimming surrounding spaces, case sensitive.

Settings > General > Editor has a new checkbox, on by default, that
turns both checks off (elementeditor/check-terminal-names).

--check-elements applies the same rule: repeated names are a FAIL,
missing names a WARN. It ignores the setting, since it is an explicit
check. On the shipped collection this reports 82 FAILs, the elements
that repeat a terminal name today.

The rule lives in the header-only editor/terminalnamecheck.h, shared
by both, and is unit tested by tst_terminalnamecheck.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 07:24:55 +13:00

56 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <QtTest>
#include "editor/terminalnamecheck.h"
class tst_terminalnamecheck : public QObject
{
Q_OBJECT
private slots:
void uniqueNamesPass()
{
QVERIFY(TerminalNameCheck::repeatedNames({"A1", "A2", "13", "14"}).isEmpty());
}
// Shelly Pro 2PM in the shipped collection: three terminals named N.
void repeatedNamesAreCounted()
{
const auto repeated = TerminalNameCheck::repeatedNames(
{"L", "N", "O1", "N", "O2", "N", "L"});
QCOMPARE(repeated.size(), 2);
QCOMPARE(repeated.at(0), qMakePair(QString("L"), 2));
QCOMPARE(repeated.at(1), qMakePair(QString("N"), 3));
QCOMPARE(TerminalNameCheck::describe(repeated),
QString::fromUtf8("L ×2, N ×3"));
}
void surroundingSpacesAreIgnored()
{
QCOMPARE(TerminalNameCheck::repeatedNames({"PE", " PE "}).size(), 1);
}
void caseMatters()
{
QVERIFY(TerminalNameCheck::repeatedNames({"n", "N"}).isEmpty());
}
// Unnamed terminals are reported as unnamed, never as a repeat of "".
void unnamedAreNotRepeats()
{
const QStringList names{"", " ", "1", ""};
QVERIFY(TerminalNameCheck::repeatedNames(names).isEmpty());
QCOMPARE(TerminalNameCheck::unnamedCount(names), 3);
}
// describe() goes into a tr() message with %1: a name holding %2 stays literal.
void describeKeepsPercentLiteral()
{
QCOMPARE(TerminalNameCheck::describe({qMakePair(QString("%2"), 2)}),
QString::fromUtf8("%2 ×2"));
}
};
QTEST_GUILESS_MAIN(tst_terminalnamecheck)
#include "tst_terminalnamecheck.moc"