Fix duplicate datatags and other issues in tst_QSizePolicy

tst_QSizePolicy is creating data tags programmatically, and the
implementation creates duplicates. This commit fixes the problem.

It used to print tens of thousands of warnings about duplicate datatags:

QWARN  : tst_QSizePolicy::getSetCheck() Duplicate data tag "Fixed-Fixed-0-0-DefaultType-false-false" - please rename

It turns out that the warnings were not only caused by collisions of
datatags (the textual representations of the test data rows), but also
by real test issues.

Problems fixed or found:

The datatag string now includes a couple of new factors used in
generating the data and were not represented before. Namely
"ed" (expandingDirections), and "spId" which represents the counter `i`
from the innermost loop which changes what each iteration of the test
checks for.

That same innermost counter was previously iterating up to one value
less than it should (4 instead of 5 (inclusive)), which resulted to test
data rows containing the same values.

The very first iteration of the innermost loop is now skipped so that
"oldsp" gets a real value, which avoids 5 data rows identical to the
ones defined on the next iteration.

Mark with a FIXME comment that the part of the test filling the
expandingDirections data does nothing, because none of the "policies"
tested has ExpandFlag set. The QSizePolicy-ies that have that, are
Expanding and MinimumExpanding, which are not tested at all. In other
words, all generated data have no expanding directions, thus the
datatags contain the "ed:__" string.

Finally, the datatags format string is now more descriptive, of the
form:

tst_QSizePolicy::getSetCheck(H:Fixed-V:Fixed-0-0-DefaultType-hfw:0-wfh:0-ed:__-spId:0)

Task-number: QTBUG-107185
Change-Id: I48d5839967f743643c68aeb0f3950503cd5a6e0e
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
Dimitrios Apostolou 2024-09-21 02:59:01 +02:00
parent 0704eff561
commit b6bfde6cf2

View File

@ -172,14 +172,29 @@ void tst_QSizePolicy::transposed()
QCOMPARE(sp, tr);
}
static void makeRow(QSizePolicy sp, QSizePolicy::Policy hp, QSizePolicy::Policy vp,
int hst, int vst, QSizePolicy::ControlType ct, bool hfw, bool wfh,
Qt::Orientations orients)
static const char *edToString(Qt::Orientations orients)
{
QTest::addRow("%s-%s-%d-%d-%s-%s-%s",
PrettyPrint(hp).s(), PrettyPrint(vp).s(), hst, vst,
if (orients.testFlags(Qt::Horizontal | Qt::Vertical))
return "HV";
if (orients.testFlag(Qt::Horizontal))
return "H_";
if (orients.testFlag(Qt::Vertical))
return "_V";
return "__";
}
static void makeRow(QSizePolicy sp,
QSizePolicy::Policy hp, QSizePolicy::Policy vp,
int hst, int vst, QSizePolicy::ControlType ct, bool hfw, bool wfh,
Qt::Orientations orients, int spId)
{
QTest::addRow("H:%s-V:%s-%d-%d-%s-hfw:%d-wfh:%d-ed:%s-spId:%d",
PrettyPrint(hp).s(), PrettyPrint(vp).s(),
hst, vst,
PrettyPrint(ct).s(),
hfw ? "true" : "false", wfh ? "true" : "false")
hfw ? 1 : 0,
wfh ? 1 : 0,
edToString(orients), spId)
<< sp << hp << vp << hst << vst << ct << hfw << wfh << orients;
}
@ -209,14 +224,15 @@ void tst_QSizePolicy::data() const
};
#define ITEMCOUNT(arr) int(sizeof(arr)/sizeof(arr[0]))
QSizePolicy sp, oldsp;
QSizePolicy sp;
std::optional<QSizePolicy> oldsp;
#ifdef GENERATE_BASELINE
QFile out(QString::fromAscii("qsizepolicy-Qt%1%2.txt").arg((QT_VERSION >> 16) & 0xff).arg((QT_VERSION) >> 8 & 0xff));
if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QDataStream stream(&out);
#endif
/* Loop for permutating over the values most likely to trigger a bug:
- mininumum, maximum values
- minimum, maximum values
- Some values with LSB set, others with MSB unset. (check if shifts are ok)
*/
@ -232,8 +248,7 @@ void tst_QSizePolicy::data() const
for (int j = 0; j < 3; ++j) {
bool hfw = j & 1;
bool wfh = j & 2; // cannot set hfw and wfh at the same time
oldsp = sp;
for (int i = 0; i < 5; ++i) {
for (int i = 0; i <= 5; ++i) {
switch (i) {
case 0: sp.setHorizontalPolicy(hp); break;
case 1: sp.setVerticalPolicy(vp); break;
@ -243,26 +258,28 @@ void tst_QSizePolicy::data() const
case 5: sp.setHeightForWidth(hfw); sp.setWidthForHeight(wfh); break;
default: break;
}
// FIXME these will never be set,
// they need QSizePolicy::Expanding or MinimumExpanding.
Qt::Orientations orients;
if (sp.horizontalPolicy() & QSizePolicy::ExpandFlag)
orients |= Qt::Horizontal;
if (sp.verticalPolicy() & QSizePolicy::ExpandFlag)
orients |= Qt::Vertical;
makeRow(sp,
i >= 0 ? hp : oldsp.horizontalPolicy(),
i >= 1 ? vp : oldsp.verticalPolicy(),
i >= 2 ? hst : oldsp.horizontalStretch(),
i >= 3 ? vst : oldsp.verticalStretch(),
i >= 4 ? ct : oldsp.controlType(),
i >= 5 ? hfw : oldsp.hasHeightForWidth(),
i >= 5 ? wfh : oldsp.hasWidthForHeight(),
orients);
if (oldsp)
makeRow(sp,
i >= 0 ? hp : oldsp->horizontalPolicy(),
i >= 1 ? vp : oldsp->verticalPolicy(),
i >= 2 ? hst : oldsp->horizontalStretch(),
i >= 3 ? vst : oldsp->verticalStretch(),
i >= 4 ? ct : oldsp->controlType(),
i >= 5 ? hfw : oldsp->hasHeightForWidth(),
i >= 5 ? wfh : oldsp->hasWidthForHeight(),
orients, i);
#ifdef GENERATE_BASELINE
stream << sp;
#endif
}
oldsp = sp;
}
}
}