From 1e432f0a88b25098819fc9684b54606ba3a05123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Fri, 4 May 2012 15:19:17 +0200 Subject: Introduce a new built-in type: signed char. C++ distinguish between "char", "signed char" and "unsigned char", they are three independent types. Fix QVariant behavior on ARM. On ARM "char" may mean "unsigned char", but we depends on the sign during a numerical conversions. Change-Id: I610ce3fb88ed5964b67f3ae442d264fe16b2d261 Reviewed-by: Thiago Macieira --- .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 6 ++++- .../auto/corelib/kernel/qvariant/tst_qvariant.cpp | 27 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index e9de52b821..e09517678e 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -273,6 +273,7 @@ void tst_QMetaType::qMetaTypeId() QCOMPARE(::qMetaTypeId(), QMetaType::type("char")); QCOMPARE(::qMetaTypeId(), QMetaType::type("unsigned char")); QCOMPARE(::qMetaTypeId(), QMetaType::type("signed char")); + QVERIFY(::qMetaTypeId() != ::qMetaTypeId()); QCOMPARE(::qMetaTypeId(), QMetaType::type("qint8")); } @@ -446,6 +447,9 @@ template<> struct TestValueFactory { template<> struct TestValueFactory { static ushort *create() { return new ushort(0x1234); } }; +template<> struct TestValueFactory { + static signed char *create() { return new signed char(-12); } +}; template<> struct TestValueFactory { static uchar *create() { return new uchar('u'); } }; @@ -1012,7 +1016,7 @@ void tst_QMetaType::typedefs() { QCOMPARE(QMetaType::type("long long"), int(QMetaType::LongLong)); QCOMPARE(QMetaType::type("unsigned long long"), int(QMetaType::ULongLong)); - QCOMPARE(QMetaType::type("qint8"), int(QMetaType::Char)); + QCOMPARE(QMetaType::type("qint8"), int(QMetaType::SChar)); QCOMPARE(QMetaType::type("quint8"), int(QMetaType::UChar)); QCOMPARE(QMetaType::type("qint16"), int(QMetaType::Short)); QCOMPARE(QMetaType::type("quint16"), int(QMetaType::UShort)); diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 569e448d88..47392a35a5 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -605,9 +605,18 @@ void tst_QVariant::canConvert_data() var = QVariant((uint)1); QTest::newRow("UInt") << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + var = QVariant((int)1); + QTest::newRow("Int") + << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; var = QVariant((qulonglong)1); QTest::newRow("ULongLong") << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + var = QVariant::fromValue('a'); + QTest::newRow("Char") + << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + var = QVariant::fromValue(-1); + QTest::newRow("SChar") + << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; #undef N #undef Y @@ -696,6 +705,9 @@ void tst_QVariant::toInt_data() QTest::newRow( "invalid" ) << QVariant() << 0 << false; QTest::newRow( "int" ) << QVariant( 123 ) << 123 << true; + QTest::newRow( "char" ) << QVariant::fromValue('a') << int('a') << true; + signed char signedChar = -13; + QTest::newRow( "signed char" ) << QVariant::fromValue(signedChar) << -13 << true; QTest::newRow( "double" ) << QVariant( 3.1415927 ) << 3 << true; QTest::newRow( "float" ) << QVariant( 3.1415927f ) << 3 << true; QTest::newRow( "uint" ) << QVariant( 123u ) << 123 << true; @@ -744,6 +756,9 @@ void tst_QVariant::toUInt_data() QTest::addColumn("valueOK"); QTest::newRow( "int" ) << QVariant( 123 ) << (uint)123 << true; + QTest::newRow( "char" ) << QVariant::fromValue('a') << uint('a') << true; + signed char signedChar = 12; + QTest::newRow( "signed char" ) << QVariant::fromValue(signedChar) << uint(12) << true; QTest::newRow( "double" ) << QVariant( 3.1415927 ) << (uint)3 << true; QTest::newRow( "float" ) << QVariant( 3.1415927f ) << (uint)3 << true; QTest::newRow( "uint" ) << QVariant( 123u ) << (uint)123 << true; @@ -1710,8 +1725,16 @@ void tst_QVariant::writeToReadFromOldDataStream() void tst_QVariant::checkDataStream() { - QTest::ignoreMessage(QtWarningMsg, "Trying to construct an instance of an invalid type, type id: 49"); - const QByteArray settingsHex("00000031ffffffffff"); + const int typeId = QMetaType::LastCoreType + 1; + QVERIFY(!QMetaType::isRegistered(typeId)); + + QByteArray errorMessage("Trying to construct an instance of an invalid type, type id: "); + errorMessage.append(QString::number(typeId, 10)); + + QTest::ignoreMessage(QtWarningMsg, errorMessage.constData()); + QByteArray settingsHex("000000"); + settingsHex.append(QString::number(typeId, 16)); + settingsHex.append("ffffffffff"); const QByteArray settings = QByteArray::fromHex(settingsHex); QDataStream in(settings); QVariant v; -- cgit v1.2.3