summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qsettings
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qsettings')
-rw-r--r--tests/auto/corelib/io/qsettings/CMakeLists.txt1
-rw-r--r--tests/auto/corelib/io/qsettings/float.ini3
-rw-r--r--tests/auto/corelib/io/qsettings/qsettings.qrc1
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp23
4 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qsettings/CMakeLists.txt b/tests/auto/corelib/io/qsettings/CMakeLists.txt
index c12f94cf36..55a360166b 100644
--- a/tests/auto/corelib/io/qsettings/CMakeLists.txt
+++ b/tests/auto/corelib/io/qsettings/CMakeLists.txt
@@ -26,6 +26,7 @@ set(qsettings_resource_files
"resourcefile5.ini"
"resourcefile6.plist"
"withcomments.ini"
+ "float.ini"
)
qt_internal_add_resource(tst_qsettings "qsettings"
diff --git a/tests/auto/corelib/io/qsettings/float.ini b/tests/auto/corelib/io/qsettings/float.ini
new file mode 100644
index 0000000000..bf9312c14c
--- /dev/null
+++ b/tests/auto/corelib/io/qsettings/float.ini
@@ -0,0 +1,3 @@
+[test]
+float=0.5
+float_qvariant=@Variant(\0\0\0\x87?\0\0\0)
diff --git a/tests/auto/corelib/io/qsettings/qsettings.qrc b/tests/auto/corelib/io/qsettings/qsettings.qrc
index db1d8c663f..0501206c05 100644
--- a/tests/auto/corelib/io/qsettings/qsettings.qrc
+++ b/tests/auto/corelib/io/qsettings/qsettings.qrc
@@ -8,5 +8,6 @@
<file>resourcefile6.plist</file>
<file>bom.ini</file>
<file>withcomments.ini</file>
+ <file>float.ini</file>
</qresource>
</RCC>
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
index eef0a7ca2a..9fd7b255d7 100644
--- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
+++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
@@ -189,6 +189,7 @@ private slots:
void embeddedZeroByte_data();
void embeddedZeroByte();
void spaceAfterComment();
+ void floatAsQVariant();
void testXdg();
private:
@@ -765,6 +766,20 @@ void tst_QSettings::spaceAfterComment()
settings.endGroup();
}
+// test if a qvariant-encoded float can be read
+void tst_QSettings::floatAsQVariant()
+{
+ QVERIFY(QFile::exists(":/float.ini"));
+ QSettings s(":/float.ini", QSettings::IniFormat);
+
+ s.beginGroup("test");
+ QCOMPARE(s.value("float").toDouble(), 0.5);
+ QCOMPARE(s.value("float_qvariant").toDouble(), 0.5);
+
+ QCOMPARE(s.value("float").toFloat(), 0.5);
+ QCOMPARE(s.value("float_qvariant").toFloat(), 0.5);
+}
+
void tst_QSettings::testErrorHandling_data()
{
QTest::addColumn<int>("filePerms"); // -1 means file should not exist
@@ -1090,6 +1105,14 @@ void tst_QSettings::setValue()
settings.setValue("key 2", QString("false"));
QCOMPARE(settings.value("key 2", true).toBool(), false);
+ settings.setValue("key 2", double(1234.56));
+ QCOMPARE(settings.value("key 2").toDouble(), double(1234.56));
+ QCOMPARE(settings.value("key 2").toString().left(7), QString::number(double(1234.56)));
+
+ settings.setValue("key 2", float(1234.56));
+ QCOMPARE(settings.value("key 2").toFloat(), float(1234.56));
+ QCOMPARE(settings.value("key 2").toString().left(7), QString::number(float(1234.56)));
+
// The following block should not compile.
/*
settings.setValue("key 2", "true");