Fix spurious XPASS in tst_QGraphicsAnchorLayout.

Seen on Windows:

XPASS  : tst_QGraphicsAnchorLayout::stability() QCOMPARE(sameAsPreviousArrangement, true) returned TRUE unexpectedly.
tst_qgraphicsanchorlayout.cpp(1399) : failure location

Move check into loop with descriptive message on fail, do not error
out if it actually passes. This now typically prints:

XFAIL  : tst_QGraphicsAnchorLayout::stability() The layout has several solutions, but which solution it picks is not stable ( QRectF(30,0 0x10) != QRectF(30,0 10x10) , iteration 3 , item 4 )

Change-Id: Iae8553dbbcedeb70d5d672e3cefbd1f06a63d27d
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
bb10
Friedemann Kleint 2014-03-12 10:20:02 +01:00 committed by The Qt Project
parent fde6450b59
commit 08f0dbd13c
1 changed files with 19 additions and 12 deletions

View File

@ -1365,14 +1365,22 @@ void tst_QGraphicsAnchorLayout::hardComplexS60()
delete p;
}
static inline QByteArray msgStability(const QRectF &actual, const QRectF &expected, int pass, int item)
{
QString result;
QDebug(&result)
<< "The layout has several solutions, but which solution it picks is not stable ("
<< actual << "!=" << expected << ", iteration" << pass << ", item" << item << ')';
return result.toLocal8Bit();
}
void tst_QGraphicsAnchorLayout::stability()
{
QVector<QRectF> geometries;
geometries.resize(7);
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
bool sameAsPreviousArrangement = true;
QGraphicsWidget p(0, Qt::Window);
// it usually fails after 3-4 iterations
for (int pass = 0; pass < 20 && sameAsPreviousArrangement; ++pass) {
for (int pass = 0; pass < 20; ++pass) {
// In case we need to "scramble" the heap allocator to provoke this bug.
//static const int primes[] = {2, 3, 5, 13, 89, 233, 1597, 28657, 514229}; // fibo primes
//const int primeCount = sizeof(primes)/sizeof(int);
@ -1380,23 +1388,22 @@ void tst_QGraphicsAnchorLayout::stability()
//void *mem = malloc(alloc);
//free(mem);
QGraphicsAnchorLayout *l = createAmbiguousS60Layout();
p->setLayout(l);
p.setLayout(l);
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
l->setGeometry(QRectF(QPointF(0,0), layoutMinimumSize));
QApplication::processEvents();
for (int i = l->count() - 1; i >=0 && sameAsPreviousArrangement; --i) {
QRectF geom = l->itemAt(i)->geometry();
for (int i = l->count() - 1; i >=0; --i) {
const QRectF actualGeom = l->itemAt(i)->geometry();
if (pass != 0) {
sameAsPreviousArrangement = (geometries[i] == geom);
if (actualGeom != geometries[i])
QEXPECT_FAIL("", msgStability(actualGeom, geometries[i], pass, i).constData(), Abort);
QCOMPARE(actualGeom, geometries[i]);
}
geometries[i] = geom;
geometries[i] = actualGeom;
}
p->setLayout(0); // uninstalls and deletes the layout
p.setLayout(0); // uninstalls and deletes the layout
QApplication::processEvents();
}
delete p;
QEXPECT_FAIL("", "The layout have several solutions, but which solution it picks is not stable", Continue);
QCOMPARE(sameAsPreviousArrangement, true);
}
void tst_QGraphicsAnchorLayout::delete_anchor()