summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-11-04 20:18:14 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2015-11-04 20:18:14 +0100
commit4159ee840549df11287294f0928e90f35f3e06ff (patch)
tree4a3947e37d54bdb78b4042e9ced20dbf181b5a2c /tests/auto/corelib/io
parent59dbf1786f22ec4ac88d8f9d38cac5cfb82acaea (diff)
parentc8c39ecc37c156ac2677de09a26548dfc274b564 (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: config.tests/unix/ptrsize.test configure src/corelib/global/qnamespace.h src/network/socket/qabstractsocket.cpp tests/auto/other/networkselftest/networkselftest.pro Change-Id: Ic78abb4a34f9068567cea876861d4220f5a07672
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
index 565ca18899..334f5aba05 100644
--- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
+++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
@@ -59,6 +59,7 @@ private slots:
void peekBug();
void readAllKeepPosition();
+ void writeInTextMode();
};
void tst_QIODevice::initTestCase()
@@ -628,5 +629,45 @@ void tst_QIODevice::readAllKeepPosition()
QCOMPARE(resultArray, buffer.buffer());
}
+class RandomAccessBuffer : public QIODevice
+{
+public:
+ RandomAccessBuffer(const char *data) : QIODevice(), buf(data) { }
+
+protected:
+ qint64 readData(char *data, qint64 maxSize) Q_DECL_OVERRIDE
+ {
+ maxSize = qMin(maxSize, qint64(buf.size() - pos()));
+ memcpy(data, buf.constData() + pos(), maxSize);
+ return maxSize;
+ }
+ qint64 writeData(const char *data, qint64 maxSize) Q_DECL_OVERRIDE
+ {
+ maxSize = qMin(maxSize, qint64(buf.size() - pos()));
+ memcpy(buf.data() + pos(), data, maxSize);
+ return maxSize;
+ }
+
+private:
+ QByteArray buf;
+};
+
+// Test write() on skipping correct number of bytes in read buffer
+void tst_QIODevice::writeInTextMode()
+{
+ // Unlike other platforms, Windows implementation expands '\n' into
+ // "\r\n" sequence in write(). Ensure that write() properly works with
+ // a read buffer on random-access devices.
+#ifndef Q_OS_WIN
+ QSKIP("This is a Windows-only test");
+#else
+ RandomAccessBuffer buffer("one\r\ntwo\r\nthree\r\n");
+ buffer.open(QBuffer::ReadWrite | QBuffer::Text);
+ QCOMPARE(buffer.readLine(), QByteArray("one\n"));
+ QCOMPARE(buffer.write("two\n"), 4);
+ QCOMPARE(buffer.readLine(), QByteArray("three\n"));
+#endif
+}
+
QTEST_MAIN(tst_QIODevice)
#include "tst_qiodevice.moc"