From 7e05bf257d589e97e54b36cb112f96ae17cbd6f2 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 10 Sep 2010 14:06:59 +0200 Subject: Fix the bug for QSettings on Windows, to store qint32/quint32, qint64/quint64 in Windows registry. Reviewed-by: Prasanth Ullattil Reviewed-by: Joerg Bornemann Task: QTBUT-13249 AutoTest: Included --- src/corelib/io/qsettings_win.cpp | 24 +++++++++++-- tests/auto/qsettings/tst_qsettings.cpp | 63 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index de96e06..b3fe734 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -535,6 +535,15 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa break; } + case REG_QWORD: { + Q_ASSERT(data.size() == sizeof(qint64)); + qint64 i; + memcpy((char*)&i, data.constData(), sizeof(qint64)); + if (value != 0) + *value = i; + break; + } + default: qWarning("QSettings: Unknown data %d type in Windows registry", static_cast(dataType)); if (value != 0) @@ -683,10 +692,19 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) break; } - case QVariant::Int: { + case QVariant::Int: + case QVariant::UInt: { type = REG_DWORD; - int i = value.toInt(); - regValueBuff = QByteArray((const char*)&i, sizeof(int)); + qint32 i = value.toInt(); + regValueBuff = QByteArray((const char*)&i, sizeof(qint32)); + break; + } + + case QVariant::LongLong: + case QVariant::ULongLong: { + type = REG_QWORD; + qint64 i = value.toLongLong(); + regValueBuff = QByteArray((const char*)&i, sizeof(qint64)); break; } diff --git a/tests/auto/qsettings/tst_qsettings.cpp b/tests/auto/qsettings/tst_qsettings.cpp index 058a750..0395eff 100644 --- a/tests/auto/qsettings/tst_qsettings.cpp +++ b/tests/auto/qsettings/tst_qsettings.cpp @@ -60,6 +60,10 @@ #include #endif +#if defined(Q_OS_WIN) +#include +#endif + #ifndef QSETTINGS_P_H_VERSION #define QSETTINGS_P_H_VERSION 1 #endif @@ -127,6 +131,9 @@ private slots: #if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN) void dontReorderIniKeysNeedlessly(); #endif +#if defined(Q_OS_WIN) + void qtbug_13249(); +#endif /* These tests were developed for the Qt 3 QSettings class. @@ -3801,6 +3808,62 @@ void tst_QSettings::setPathBug() } #endif +#if defined(Q_OS_WIN) + +static DWORD readKeyType(HKEY handle, const QString &rSubKey) +{ + DWORD dataType; + DWORD dataSize; + LONG res = RegQueryValueEx(handle, reinterpret_cast(rSubKey.utf16()), 0, &dataType, 0, &dataSize); + + if (res == ERROR_SUCCESS) + return dataType; + + return 0; +} + +void tst_QSettings::qtbug_13249() +{ + QSettings settings1(QSettings::UserScope, "software.org", "KillerAPP"); + + qint32 x = 1024; + settings1.setValue("qtbug_13249_a", (qint32)x); + QCOMPARE(settings1.value("qtbug_13249_a").toInt(), (qint32)1024); + settings1.setValue("qtbug_13249_b", (quint32)x); + QCOMPARE(settings1.value("qtbug_13249_b").toUInt(), (quint32)1024); + settings1.setValue("qtbug_13249_c", (qint64)x); + QCOMPARE(settings1.value("qtbug_13249_c").toLongLong(), (qint64)1024); + settings1.setValue("qtbug_13249_d", (quint64)x); + QCOMPARE(settings1.value("qtbug_13249_d").toULongLong(), (quint64)1024); + settings1.sync(); + + HKEY handle; + LONG res; + QString keyName = "Software\\software.org\\KillerAPP"; + res = RegOpenKeyEx(HKEY_CURRENT_USER, reinterpret_cast(keyName.utf16()), 0, KEY_READ, &handle); + if (res == ERROR_SUCCESS) + { + DWORD dataType; + dataType = readKeyType(handle, QString("qtbug_13249_a")); + if (dataType != 0) { + QCOMPARE((int)REG_DWORD, (int)dataType); + } + dataType = readKeyType(handle, QString("qtbug_13249_b")); + if (dataType != 0) { + QCOMPARE((int)REG_DWORD, (int)dataType); + } + dataType = readKeyType(handle, QString("qtbug_13249_c")); + if (dataType != 0) { + QCOMPARE((int)REG_QWORD, (int)dataType); + } + dataType = readKeyType(handle, QString("qtbug_13249_d")); + if (dataType != 0) { + QCOMPARE((int)REG_QWORD, (int)dataType); + } + RegCloseKey(handle); + } +} +#endif /* // Not tested at the moment. void tst_QSettings::oldSubkeyList() -- cgit v0.12