Test for QMetaType binary breakage.

Type traits can not be changed durring Qt5 life time.

Change-Id: If69f65ff2113c901580afee91b11ae1b11c13a4f
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
bb10
Jędrzej Nowacki 2012-06-21 17:19:33 +02:00 committed by Qt by Nokia
parent 8ca17ed943
commit 197f34bcff
3 changed files with 46 additions and 0 deletions

View File

@ -2,3 +2,4 @@ CONFIG += testcase parallel_test
TARGET = tst_qmetatype
QT = core testlib
SOURCES = tst_qmetatype.cpp
TESTDATA=./typeFlags.bin

View File

@ -90,6 +90,8 @@ private slots:
void flags();
void flagsStaticLess_data();
void flagsStaticLess();
void flagsBinaryCompatibility5_0_data();
void flagsBinaryCompatibility5_0();
void construct_data();
void construct();
void constructCopy_data();
@ -885,6 +887,49 @@ void tst_QMetaType::flagsStaticLess()
QCOMPARE(bool(flags & QMetaType::MovableType), isMovable);
}
void tst_QMetaType::flagsBinaryCompatibility5_0_data()
{
// Changing traits of a built-in type is illegal from BC point of view.
// Traits are saved in code of an application and in the Qt library which means
// that there may be a mismatch.
// The test is loading data generated by this code:
//
// QByteArray buffer;
// buffer.reserve(2 * QMetaType::User);
// for (quint32 i = 0; i < QMetaType::User; ++i) {
// if (QMetaType::isRegistered(i)) {
// buffer.append(i);
// buffer.append(quint32(QMetaType::typeFlags(i)));
// }
// }
// QFile file("/tmp/typeFlags.bin");
// file.open(QIODevice::WriteOnly);
// file.write(buffer);
// file.close();
QTest::addColumn<quint32>("id");
QTest::addColumn<quint32>("flags");
QFile file(QFINDTESTDATA("typeFlags.bin"));
file.open(QIODevice::ReadOnly);
QByteArray buffer = file.readAll();
for (int i = 0; i < buffer.size(); i+=2) {
const quint32 id = buffer.at(i);
const quint32 flags = buffer.at(i + 1);
QVERIFY2(QMetaType::isRegistered(id), "A type could not be removed in BC way");
QTest::newRow(QMetaType::typeName(id)) << id << flags;
}
}
void tst_QMetaType::flagsBinaryCompatibility5_0()
{
QFETCH(quint32, id);
QFETCH(quint32, flags);
QCOMPARE(quint32(QMetaType::typeFlags(id)), flags);
}
void tst_QMetaType::construct_data()
{
create_data();

Binary file not shown.