diff options
author | Yuhang Zhao <2546789017@qq.com> | 2022-10-20 09:27:18 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2022-10-21 11:51:31 +0800 |
commit | 738e05a55a4047268553eea6b9f4809d42181eef (patch) | |
tree | 8d89895b8253910912ffc0c4f0ee4f3ced29eb03 /tests/auto/corelib | |
parent | 466a03e724aa39f7c57010cc2263adb06976ea50 (diff) |
QWinRegistryKey: fix assert when querying default value
I wrongly assumed we can't query a value with an empty name ""
during the previous refactor commit, however, in Windows registry,
an empty name for a value means the default value of a key, we can
read and write it through the "Default" name.
Remove the wrong assert to fix the crash when we are trying to query
a default value of a key.
Add a new test case to test this kind of scenarios.
Amends commit 40523b68c14bf618bdc2d5438deebf34627be3af
Fixes: QTBUG-107794
Change-Id: Idacbcb86df4435a8c1ca1c19121599390ae8f3d3
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp b/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp index d3a20be048..81f75a7bea 100644 --- a/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp +++ b/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp @@ -20,6 +20,7 @@ static const QPair<QStringView, quint32> TEST_DWORD = qMakePair(u"dword", 123); static const QPair<QStringView, quint64> TEST_QWORD = qMakePair(u"qword", 456); static const QPair<QStringView, QByteArray> TEST_BINARY = qMakePair(u"binary", "binary\0"_ba); static const QPair<QStringView, QVariant> TEST_NOT_EXIST = qMakePair(u"not_exist", QVariant()); +static const QPair<QStringView, QVariant> TEST_DEFAULT = qMakePair(u"Default", u"default"_s); [[nodiscard]] static inline bool write(const HKEY key, const QStringView name, const QVariant &value) { @@ -124,6 +125,8 @@ void tst_qwinregistrykey::initTestCase() return; if (!write(key, TEST_BINARY.first, TEST_BINARY.second)) return; + if (!write(key, TEST_DEFAULT.first, TEST_DEFAULT.second)) + return; m_available = true; } @@ -141,9 +144,10 @@ void tst_qwinregistrykey::cleanupTestCase() RegDeleteValueW(key, C_STR(TEST_DWORD.first)); RegDeleteValueW(key, C_STR(TEST_QWORD.first)); RegDeleteValueW(key, C_STR(TEST_BINARY.first)); + RegDeleteValueW(key, C_STR(TEST_DEFAULT.first)); #undef C_STR - RegCloseKey(key); RegDeleteKeyW(HKEY_CURRENT_USER, TEST_KEY); + RegCloseKey(key); } void tst_qwinregistrykey::qwinregistrykey() @@ -207,6 +211,18 @@ void tst_qwinregistrykey::qwinregistrykey() } { + const auto value = registry.value<QString>(TEST_DEFAULT.first); + QVERIFY(value.has_value()); + QCOMPARE(value.value_or(QString()), TEST_DEFAULT.second); + } + + { + const auto value = registry.value<QString>(L""); + QVERIFY(value.has_value()); + QCOMPARE(value.value_or(QString()), TEST_DEFAULT.second); + } + + { const QString value = registry.stringValue(TEST_STRING.first); QVERIFY(!value.isEmpty()); QCOMPARE(value, TEST_STRING.second); |