From 7df8b1ada4b23acedda5724b492c26a8e322648b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 4 Jun 2014 13:52:37 +0200 Subject: Properly escape bytearray data outside the ascii range when using a codec Some codecs can't handle the range outside ascii properly and would then fail to read the data back in correctly. Task-number: QTBUG-15543 Change-Id: I4c02921e787a939eeec0c7a11603b5896d756aef Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 501ad6f415..2c9868cd10 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -166,6 +166,7 @@ private slots: void testByteArray_data(); void testByteArray(); + void iniCodec(); private: const bool m_canWriteNativeSystemSettings; @@ -695,6 +696,28 @@ void tst_QSettings::testByteArray() } } +void tst_QSettings::iniCodec() +{ + { + QSettings settings("QtProject", "tst_qsettings"); + settings.setIniCodec("cp1251"); + QByteArray ba; + ba.resize(256); + for (int i = 0; i < ba.size(); i++) + ba[i] = i; + settings.setValue("array",ba); + } + { + QSettings settings("QtProject", "tst_qsettings"); + settings.setIniCodec("cp1251"); + QByteArray ba = settings.value("array").toByteArray(); + QCOMPARE(ba.size(), 256); + for (int i = 0; i < ba.size(); i++) + QCOMPARE((uchar)ba.at(i), (uchar)i); + } + +} + void tst_QSettings::testErrorHandling_data() { QTest::addColumn("filePerms"); // -1 means file should not exist -- cgit v1.2.3