summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-12-16 11:36:41 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-12-16 13:57:44 (GMT)
commit135a6e32522775b182e870130eb12502753c913c (patch)
treee960b4864d4431dbffa7025116dc0e3493027ff0 /tests/auto
parent9233143bb25e33c07f73b7d35b0d6cbd14ef1686 (diff)
downloadQt-135a6e32522775b182e870130eb12502753c913c.zip
Qt-135a6e32522775b182e870130eb12502753c913c.tar.gz
Qt-135a6e32522775b182e870130eb12502753c913c.tar.bz2
add write error handling to QTextStream
add new status flag WriteFailed. use it in flushWriteBuffer(). remove the boolean return values from write(), putString() and putNumber(), as they were ignored anyway - flushWriteBuffer() does it correctly now. Task-number: QTBUG-376 Reviewed-by: mariusSO
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtextstream/tst_qtextstream.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qtextstream/tst_qtextstream.cpp b/tests/auto/qtextstream/tst_qtextstream.cpp
index 4c78ef0..005f686 100644
--- a/tests/auto/qtextstream/tst_qtextstream.cpp
+++ b/tests/auto/qtextstream/tst_qtextstream.cpp
@@ -228,6 +228,7 @@ private slots:
void status_real_read();
void status_integer_read();
void status_word_read();
+ void status_write_error();
// use case tests
void useCase1();
@@ -4176,6 +4177,42 @@ void tst_QTextStream::status_word_read()
QCOMPARE(s.status(), QTextStream::ReadPastEnd);
}
+class FakeBuffer : public QBuffer
+{
+protected:
+ qint64 writeData(const char *c, qint64 i) { return m_lock ? 0 : QBuffer::writeData(c, i); }
+public:
+ FakeBuffer(bool locked = false) : m_lock(locked) {}
+ void setLocked(bool locked) { m_lock = locked; }
+private:
+ bool m_lock;
+};
+
+void tst_QTextStream::status_write_error()
+{
+ FakeBuffer fb(false);
+ QVERIFY(fb.open(QBuffer::ReadWrite));
+ QTextStream fs(&fb);
+ fs.setCodec(QTextCodec::codecForName("latin1"));
+ /* first write some initial content */
+ fs << "hello";
+ fs.flush();
+ QCOMPARE(fs.status(), QTextStream::Ok);
+ QCOMPARE(fb.data(), QByteArray("hello"));
+ /* then test that writing can cause an error */
+ fb.setLocked(true);
+ fs << "error";
+ fs.flush();
+ QCOMPARE(fs.status(), QTextStream::WriteFailed);
+ QCOMPARE(fb.data(), QByteArray("hello"));
+ /* finally test that writing after an error doesn't change the stream any more */
+ fb.setLocked(false);
+ fs << "can't do that";
+ fs.flush();
+ QCOMPARE(fs.status(), QTextStream::WriteFailed);
+ QCOMPARE(fb.data(), QByteArray("hello"));
+}
+
void tst_QTextStream::task180679_alignAccountingStyle()
{
{