Prevent qDebug test bypassing the testlib message handler.
authorJason McDonald <jason.mcdonald@nokia.com>
Fri, 30 Dec 2011 00:58:14 +0000 (10:58 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 30 Dec 2011 03:14:53 +0000 (04:14 +0100)
commit14e139f39187a6e87d6eed332b11b8a3f8521906
tree96edfd9df01ce3421a376c077d02dbef2edd17cf
parentd8f1749a7472ce924304d45cdd94f8488b1e65fd
Prevent qDebug test bypassing the testlib message handler.

Several of the test functions in the QDebug autotest call
qInstallMsgHandler() to temporarily use a custom message handler.
Unfortunately, these test functions were then resetting the message
handler back to Qt's default handler at the end of the test.

QTestLib also calls qInstallMsgHandler() to set a message handler that
redirects debug/warning/fatal messages into the test log.  When the test
resets the message handler back to Qt's default handler, testlib's
message handler is bypassed for the rest of the test, preventing any
subsequent debug/warning/fatal messages from being visible in the test
log or subject to testlib's ignoreMessage() function.

This error also caused several of the test functions to fail if they
were run manually.  The "defaultMessagehandler" test would fail if it
was run before any other test function and the "assignment" test would
fail if it was run after any other test function.

This commit fixes these failures by using a helper class to ensure that
the previously active message handler is restored at the end of each
test function, even if the test function fails or throws an exception.

Change-Id: I51376724d164c8ad126e5b9be76890bf3e6a9fb0
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
tests/auto/corelib/io/qdebug/tst_qdebug.cpp