summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2012-05-04 15:19:17 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-08 11:47:29 +0200
commit1e432f0a88b25098819fc9684b54606ba3a05123 (patch)
treedc01912358b31857ce9edea706a57e0c7015d726 /tests
parent4169e20662d0bcf52d6a278f85f44f9dacad7a68 (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp6
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp27
2 files changed, 30 insertions, 3 deletions
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<char>(), QMetaType::type("char"));
QCOMPARE(::qMetaTypeId<uchar>(), QMetaType::type("unsigned char"));
QCOMPARE(::qMetaTypeId<signed char>(), QMetaType::type("signed char"));
+ QVERIFY(::qMetaTypeId<signed char>() != ::qMetaTypeId<char>());
QCOMPARE(::qMetaTypeId<qint8>(), QMetaType::type("qint8"));
}
@@ -446,6 +447,9 @@ template<> struct TestValueFactory<QMetaType::ULong> {
template<> struct TestValueFactory<QMetaType::UShort> {
static ushort *create() { return new ushort(0x1234); }
};
+template<> struct TestValueFactory<QMetaType::SChar> {
+ static signed char *create() { return new signed char(-12); }
+};
template<> struct TestValueFactory<QMetaType::UChar> {
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<signed char>(-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<bool>("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;