diff options
Diffstat (limited to 'tests/auto/corelib/serialization/qtextstream')
11 files changed, 178 insertions, 157 deletions
diff --git a/tests/auto/corelib/serialization/qtextstream/BLACKLIST b/tests/auto/corelib/serialization/qtextstream/BLACKLIST index aef7d7aa26..cb76e0454d 100644 --- a/tests/auto/corelib/serialization/qtextstream/BLACKLIST +++ b/tests/auto/corelib/serialization/qtextstream/BLACKLIST @@ -1,5 +1,3 @@ -[stillOpenWhenAtEnd] -windows-7sp1 # QTBUG-87410 [readStdin] android diff --git a/tests/auto/corelib/serialization/qtextstream/CMakeLists.txt b/tests/auto/corelib/serialization/qtextstream/CMakeLists.txt index 15798c963f..ac3dc91555 100644 --- a/tests/auto/corelib/serialization/qtextstream/CMakeLists.txt +++ b/tests/auto/corelib/serialization/qtextstream/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qtextstream.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextstream LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() add_subdirectory(test) add_subdirectory(stdinProcess) diff --git a/tests/auto/corelib/serialization/qtextstream/qtextstream_integrity.qrc b/tests/auto/corelib/serialization/qtextstream/qtextstream_integrity.qrc new file mode 100644 index 0000000000..620fddcd45 --- /dev/null +++ b/tests/auto/corelib/serialization/qtextstream/qtextstream_integrity.qrc @@ -0,0 +1,7 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/"> + <file>rfc3261.txt</file> + <file>task113817.txt</file> + <file>tst_qtextstream.cpp</file> +</qresource> +</RCC> diff --git a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/CMakeLists.txt b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/CMakeLists.txt index 785785d43a..bcfb0aaf4e 100644 --- a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/CMakeLists.txt +++ b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from readAllStdinProcess.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## readAllStdinProcess Binary: diff --git a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/main.cpp b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/main.cpp index 08d2bf8183..01f47d758f 100644 --- a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/main.cpp +++ b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/main.cpp @@ -1,33 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QTextStream> +#include <QtCore/QString> #include <stdio.h> int main(int, char**) diff --git a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/CMakeLists.txt b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/CMakeLists.txt index 897444c9af..39af3a3048 100644 --- a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/CMakeLists.txt +++ b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from readLineStdinProcess.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## readLineStdinProcess Binary: diff --git a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp index 2d4aa452ca..8f81f5a720 100644 --- a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp +++ b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QCoreApplication> diff --git a/tests/auto/corelib/serialization/qtextstream/stdinProcess/CMakeLists.txt b/tests/auto/corelib/serialization/qtextstream/stdinProcess/CMakeLists.txt index 73eccd1ed8..7e964bbfb2 100644 --- a/tests/auto/corelib/serialization/qtextstream/stdinProcess/CMakeLists.txt +++ b/tests/auto/corelib/serialization/qtextstream/stdinProcess/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from stdinProcess.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## stdinProcess Binary: diff --git a/tests/auto/corelib/serialization/qtextstream/stdinProcess/main.cpp b/tests/auto/corelib/serialization/qtextstream/stdinProcess/main.cpp index a3c1fc525b..b8a274ed0f 100644 --- a/tests/auto/corelib/serialization/qtextstream/stdinProcess/main.cpp +++ b/tests/auto/corelib/serialization/qtextstream/stdinProcess/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QTextStream> diff --git a/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt b/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt index 61d594900f..588a49fcf0 100644 --- a/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt +++ b/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from test.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextstream Test: @@ -8,6 +9,7 @@ list(APPEND test_data "../rfc3261.txt") list(APPEND test_data "../task113817.txt") list(APPEND test_data "../qtextstream.qrc") +list(APPEND test_data "../qtextstream_integrity.qrc") list(APPEND test_data "../tst_qtextstream.cpp") list(APPEND test_data "../resources") list(APPEND test_data "../BLACKLIST") @@ -15,25 +17,22 @@ list(APPEND test_data "../BLACKLIST") qt_internal_add_test(tst_qtextstream OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES - ../../../../../shared/emulationdetector.h ../tst_qtextstream.cpp - INCLUDE_DIRECTORIES - ../../../../../shared - PUBLIC_LIBRARIES + LIBRARIES Qt::Network + Qt::TestPrivate TESTDATA ${test_data} + QT_TEST_SERVER_LIST "cyrus" ) +if(QT_FEATURE_sanitize_address) + set_property(TEST tst_qtextstream APPEND PROPERTY ENVIRONMENT "QTEST_FUNCTION_TIMEOUT=900000") +endif() + # Resources: -set_source_files_properties("../resources/big_endian/" - PROPERTIES QT_RESOURCE_ALIAS "resources/big_endian/" -) -set_source_files_properties("../resources/little_endian/" - PROPERTIES QT_RESOURCE_ALIAS "resources/little_endian/" -) set(qtextstream_resource_files - "resources/big_endian/" - "resources/little_endian/" + "../resources/big_endian/" + "../resources/little_endian/" ) qt_internal_add_resource(tst_qtextstream "qtextstream" @@ -45,11 +44,6 @@ qt_internal_add_resource(tst_qtextstream "qtextstream" ${qtextstream_resource_files} ) - -## Scopes: -##################################################################### - -qt_internal_extend_target(tst_qtextstream CONDITION builtin_testdata - DEFINES - BUILTIN_TESTDATA -) +if(QT_FEATURE_process) + add_dependencies(tst_qtextstream stdinProcess readAllStdinProcess readLineStdinProcess) +endif() diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 3ab095827f..411084a36c 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -37,6 +12,7 @@ #include <QDebug> #include <QElapsedTimer> #include <QFile> +#include <QTemporaryFile> #include <QStringConverter> #include <QTcpSocket> #include <QTemporaryDir> @@ -45,7 +21,7 @@ # include <QProcess> #endif #include "../../../network-settings.h" -#include "emulationdetector.h" +#include <QtTest/private/qemulationdetector_p.h> QT_BEGIN_NAMESPACE template<> struct QMetaTypeId<QIODevice::OpenModeFlag> @@ -94,6 +70,8 @@ private slots: // char operators void QChar_operators_FromDevice_data(); void QChar_operators_FromDevice(); + void char16_t_operators_FromDevice_data(); + void char16_t_operators_FromDevice(); void char_operators_FromDevice_data(); void char_operators_FromDevice(); @@ -225,6 +203,9 @@ private slots: void textModeOnEmptyRead(); + void autodetectUnicode_data(); + void autodetectUnicode(); + private: void generateLineData(bool for_QString); void generateAllData(bool for_QString); @@ -569,7 +550,7 @@ void tst_QTextStream::readLineMaxlen() QFile::remove("testfile"); QFile file("testfile"); if (useDevice) { - file.open(QIODevice::ReadWrite); + QVERIFY(file.open(QIODevice::ReadWrite)); file.write(input.toUtf8()); file.seek(0); stream.setDevice(&file); @@ -954,7 +935,8 @@ void tst_QTextStream::lineCount_data() QTest::newRow("buffersize+1 line") << QByteArray(16384, '\n') << 16384; QTest::newRow("buffersize+2 line") << QByteArray(16385, '\n') << 16385; - QFile file(m_rfc3261FilePath); file.open(QFile::ReadOnly); + QFile file(m_rfc3261FilePath); + QVERIFY(file.open(QFile::ReadOnly)); QTest::newRow("rfc3261") << file.readAll() << 15067; } @@ -965,7 +947,7 @@ void tst_QTextStream::lineCount() QFETCH(int, lineCount); QFile out("out.txt"); - out.open(QFile::WriteOnly); + QVERIFY(out.open(QFile::WriteOnly)); QTextStream lineReader(data); int lines = 0; @@ -1211,11 +1193,16 @@ void tst_QTextStream::stillOpenWhenAtEnd() while (!stream.readLine().isNull()) {} QVERIFY(file.isOpen()); +#ifdef QT_TEST_SERVER + if (!QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 143)) + QSKIP("No network test server available"); +#else if (!QtNetworkSettings::verifyTestNetworkSettings()) QSKIP("No network test server available"); +#endif QTcpSocket socket; - socket.connectToHost(QtNetworkSettings::serverName(), 143); + socket.connectToHost(QtNetworkSettings::imapServerName(), 143); QVERIFY(socket.waitForReadyRead(5000)); QTextStream stream2(&socket); @@ -1417,23 +1404,23 @@ void tst_QTextStream::pos2() // ------------------------------------------------------------------------------ void tst_QTextStream::pos3LargeFile() { - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QSKIP("Running QTextStream::pos() in tight loop is too slow on emulator"); { QFile file(testFileName); - file.open(QIODevice::WriteOnly | QIODevice::Text); + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out( &file ); // NOTE: The unusual spacing is to ensure non-1-character whitespace. QString lineString = " 0 1 2\t3 4\t \t5 6 7 8 9 \n"; // Approximate 50kb text file - const int NbLines = (50*1024) / lineString.length() + 1; + const int NbLines = (50*1024) / lineString.size() + 1; for (int line = 0; line < NbLines; ++line) out << lineString; // File is automatically flushed and closed on destruction. } QFile file(testFileName); - file.open(QIODevice::ReadOnly | QIODevice::Text); + QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream in( &file ); const int testValues[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int value; @@ -1530,7 +1517,7 @@ void tst_QTextStream::read() { QFile::remove("testfile"); QFile file("testfile"); - file.open(QFile::WriteOnly); + QVERIFY(file.open(QFile::WriteOnly)); file.write("4.15 abc ole"); file.close(); @@ -1552,7 +1539,7 @@ void tst_QTextStream::read() // File larger than QTEXTSTREAM_BUFFERSIZE QFile::remove("testfile"); QFile file("testfile"); - file.open(QFile::WriteOnly); + QVERIFY(file.open(QFile::WriteOnly)); for (int i = 0; i < 16384 / 8; ++i) file.write("01234567"); file.write("0"); @@ -1608,8 +1595,8 @@ void tst_QTextStream::forceSign() // ------------------------------------------------------------------------------ void tst_QTextStream::read0d0d0a() { - QFile file("task113817.txt"); - file.open(QIODevice::ReadOnly | QIODevice::Text); + QFile file(QFINDTESTDATA("task113817.txt")); + QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream stream(&file); while (!stream.atEnd()) @@ -1773,7 +1760,7 @@ void tst_QTextStream::utf8IncompleteAtBufferBoundary() "\342\200\223" "\342\200\223"); - data.open(QFile::WriteOnly | QFile::Truncate); + QVERIFY(data.open(QFile::WriteOnly | QFile::Truncate)); { QTextStream out(&data); out.setEncoding(QStringConverter::Utf8); @@ -1785,7 +1772,7 @@ void tst_QTextStream::utf8IncompleteAtBufferBoundary() } data.close(); - data.open(QFile::ReadOnly); + QVERIFY(data.open(QFile::ReadOnly)); QTextStream in(&data); QFETCH(bool, useLocale); @@ -1914,6 +1901,40 @@ void tst_QTextStream::QChar_operators_FromDevice() } // ------------------------------------------------------------------------------ +void tst_QTextStream::char16_t_operators_FromDevice_data() +{ + generateOperatorCharData(false); +} + +// ------------------------------------------------------------------------------ +void tst_QTextStream::char16_t_operators_FromDevice() +{ + QFETCH(QByteArray, input); + QFETCH(const QChar, qchar_output); + QFETCH(const QByteArray, write_output); + const char16_t char16_t_output = qchar_output.unicode(); + + QBuffer buf(&input); + buf.open(QBuffer::ReadOnly); + QTextStream stream(&buf); + stream.setEncoding(QStringConverter::Latin1); + char16_t tmp; + stream >> tmp; + QCOMPARE(tmp, qchar_output); + + QBuffer writeBuf; + writeBuf.open(QBuffer::WriteOnly); + + QTextStream writeStream(&writeBuf); + writeStream.setEncoding(QStringConverter::Latin1); + writeStream << char16_t_output; + writeStream.flush(); + + QCOMPARE(writeBuf.buffer().size(), write_output.size()); + QCOMPARE(writeBuf.buffer().constData(), write_output.constData()); +} + +// ------------------------------------------------------------------------------ void tst_QTextStream::char_operators_FromDevice_data() { generateOperatorCharData(false); @@ -2633,13 +2654,27 @@ void tst_QTextStream::manipulators_data() QTest::addColumn<QString>("textData"); QTest::addColumn<QByteArray>("result"); - QTest::newRow("no flags") << 10 << 0 << 0 << 0 << 5.0 << 5 << QString("five") << QByteArray("55five"); - QTest::newRow("rightadjust") << 10 << int(QTextStream::AlignRight) << 0 << 10 << 5.0 << 5 << QString("five") << QByteArray(" 5 5 five"); - QTest::newRow("leftadjust") << 10 << int(QTextStream::AlignLeft) << 0 << 10 << 5.0 << 5 << QString("five") << QByteArray("5 5 five "); - QTest::newRow("showpos") << 10 << int(QTextStream::AlignRight) << int(QTextStream::ForceSign) << 10 << 5.0 << 5 << QString("five") << QByteArray(" +5 +5 five"); - QTest::newRow("showpos2") << 10 << int(QTextStream::AlignRight) << int(QTextStream::ForceSign) << 5 << 3.14 << -5 << QString("five") << QByteArray("+3.14 -5 five"); - QTest::newRow("hex") << 16 << int(QTextStream::AlignRight) << int(QTextStream::ShowBase) << 5 << 3.14 << -5 << QString("five") << QByteArray(" 3.14 -0x5 five"); - QTest::newRow("hex") << 16 << int(QTextStream::AlignRight) << int(QTextStream::ShowBase | QTextStream::UppercaseBase) << 5 << 3.14 << -5 << QString("five") << QByteArray(" 3.14 -0X5 five"); + QTest::newRow("no flags") + << 10 << 0 << 0 << 0 << 5.0 << 5 << QString("five") << QByteArray("55five"); + QTest::newRow("rightadjust") + << 10 << int(QTextStream::AlignRight) << 0 << 10 << 5.0 << 5 << QString("five") + << QByteArray(" 5 5 five"); + QTest::newRow("leftadjust") + << 10 << int(QTextStream::AlignLeft) << 0 << 10 << 5.0 << 5 << QString("five") + << QByteArray("5 5 five "); + QTest::newRow("showpos-wide") + << 10 << int(QTextStream::AlignRight) << int(QTextStream::ForceSign) << 10 << 5.0 << 5 << + QString("five") << QByteArray(" +5 +5 five"); + QTest::newRow("showpos-pi") + << 10 << int(QTextStream::AlignRight) << int(QTextStream::ForceSign) << 5 << 3.14 << -5 << + QString("five") << QByteArray("+3.14 -5 five"); + QTest::newRow("hex-lower") + << 16 << int(QTextStream::AlignRight) << int(QTextStream::ShowBase) << 5 << 3.14 << -5 << + QString("five") << QByteArray(" 3.14 -0x5 five"); + QTest::newRow("hex-upper") + << 16 << int(QTextStream::AlignRight) + << int(QTextStream::ShowBase | QTextStream::UppercaseBase) + << 5 << 3.14 << -5 << QString("five") << QByteArray(" 3.14 -0X5 five"); } // ------------------------------------------------------------------------------ @@ -3027,6 +3062,57 @@ void tst_QTextStream::textModeOnEmptyRead() QVERIFY(file.isTextModeEnabled()); } +void tst_QTextStream::autodetectUnicode_data() +{ + QTest::addColumn<QStringConverter::Encoding>("encoding"); + QTest::newRow("Utf8") << QStringConverter::Utf8; + QTest::newRow("Utf16BE") << QStringConverter::Utf16BE; + QTest::newRow("Utf16LE") << QStringConverter::Utf16LE; + QTest::newRow("Utf32BE") << QStringConverter::Utf32BE; + QTest::newRow("Utf32LE") << QStringConverter::Utf32LE; +} + +void tst_QTextStream::autodetectUnicode() +{ + QFETCH(QStringConverter::Encoding, encoding); + + QTemporaryFile file; + QVERIFY(file.open()); + + QString original("HelloWorldđź‘‹"); + + { + QTextStream out(&file); + out.setGenerateByteOrderMark(true); + out.setEncoding(encoding); + out << original; + } + file.seek(0); + { + QTextStream in(&file); + QString actual; + in >> actual; + QCOMPARE(actual, original); + QCOMPARE(in.encoding(), encoding); + } + file.seek(0); + // Again, but change order of calls to QTextStream... + { + QTextStream out(&file); + out.setEncoding(encoding); + out.setGenerateByteOrderMark(true); + out << original; + } + file.seek(0); + { + QTextStream in(&file); + QString actual; + in >> actual; + QCOMPARE(actual, original); + QCOMPARE(in.encoding(), encoding); + } +} + // ------------------------------------------------------------------------------ |