Object to creating duplicate entries in a test-data table
Tero Heikkinen caught tst_QQuaternion() using a duplicated test data tag and was surprised that testlib let it get away with that. That seems like a reasonable thing to discourage. While I'm at it, duplicate columns should be discouraged. [ChangeLog][QtTest] Duplicate data tags are now warned about. Every call to QTest::newRow() or QTest::addRow() should result in a distinct data tag. If they do not, a warning is produced. Likewise, duplicate column names are forbidden; each call to QTest::addColumn() should use a distinct name. Fixes: QTBUG-107185 Pick-to: 6.5 Change-Id: Idfdb7cdfdd71e1fe3db5cadb243eeecc83032922 Reviewed-by: Jason McDonald <macadder1@gmail.com>bb10
parent
7c84550f3b
commit
2d1fd400fc
|
|
@ -731,6 +731,10 @@
|
|||
the type of the column whose value it supplies. If any assertion fails,
|
||||
the test is aborted.
|
||||
|
||||
The names of rows and columns, in a given test function's data table, should
|
||||
be unique: if two rows share a name, or two columns share a name, a warning
|
||||
will (since Qt 6.5) be produced.
|
||||
|
||||
\section1 Rewriting the Test Function
|
||||
|
||||
Our test function can now be rewritten:
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public:
|
|||
|
||||
void addColumn(int elemType, const char *elemName) { elementList.push_back(Element(elemName, elemType)); }
|
||||
void addRow(QTestData *data) { dataList.push_back(data); }
|
||||
bool hasRow(const char *name) const;
|
||||
|
||||
static QTestTable *currentTestTable;
|
||||
static QTestTable *gTable;
|
||||
|
|
@ -49,6 +50,8 @@ void QTestTable::addColumn(int type, const char *name)
|
|||
{
|
||||
QTEST_ASSERT(type);
|
||||
QTEST_ASSERT(name);
|
||||
if (indexOf(name) != -1)
|
||||
qWarning() << "Duplicate data column" << name << "- please rename.";
|
||||
|
||||
d->addColumn(type, name);
|
||||
}
|
||||
|
|
@ -70,6 +73,9 @@ bool QTestTable::isEmpty() const
|
|||
|
||||
QTestData *QTestTable::newData(const char *tag)
|
||||
{
|
||||
if (d->hasRow(tag))
|
||||
qWarning() << "Duplicate data tag" << tag << "- please rename.";
|
||||
|
||||
QTestData *dt = new QTestData(tag, this);
|
||||
d->addRow(dt);
|
||||
return dt;
|
||||
|
|
@ -110,10 +116,19 @@ public:
|
|||
bool operator()(const QTestTablePrivate::Element &e) const
|
||||
{ return !strcmp(e.name, m_needle); }
|
||||
|
||||
bool operator()(const QTestData *e) const
|
||||
{ return !strcmp(e->dataTag(), m_needle); }
|
||||
|
||||
private:
|
||||
const char *m_needle;
|
||||
};
|
||||
|
||||
bool QTestTablePrivate::hasRow(const char *rowName) const
|
||||
{
|
||||
QTEST_ASSERT(rowName);
|
||||
return std::find_if(dataList.begin(), dataList.end(), NamePredicate(rowName)) != dataList.end();
|
||||
}
|
||||
|
||||
int QTestTable::indexOf(const char *elementName) const
|
||||
{
|
||||
QTEST_ASSERT(elementName);
|
||||
|
|
|
|||
Loading…
Reference in New Issue