forked from thoughtbot/capybara-webkit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite qInstallMsgHandler test in C++
* Allows tests independent of debug settings for Qt * Allows testing behavior unreachable from Ruby
- Loading branch information
Showing
11 changed files
with
112 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
*.swp | ||
bin/webkit_server* | ||
test/testwebkitserver | ||
*.swo | ||
*~ | ||
*.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "IgnoreDebugOutput.h" | ||
|
||
#include <QtGlobal> | ||
#include <QString> | ||
|
||
void debugIgnoringMessageHandler(QtMsgType type, const char *msg); | ||
|
||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) | ||
void debugIgnoringMessageHandlerQt5(QtMsgType type, const QMessageLogContext &context, const QString &message); | ||
#endif | ||
|
||
void debugIgnoringMessageHandler(QtMsgType type, const char *msg) { | ||
switch (type) { | ||
case QtDebugMsg: | ||
case QtWarningMsg: | ||
break; | ||
default: | ||
fprintf(stderr, "%s\n", msg); | ||
break; | ||
} | ||
} | ||
|
||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) | ||
void debugIgnoringMessageHandlerQt5(QtMsgType type, const QMessageLogContext &context, const QString &message) { | ||
Q_UNUSED(context); | ||
debugIgnoringMessageHandler(type, message.toLocal8Bit().data()); | ||
} | ||
#endif | ||
|
||
void ignoreDebugOutput(void) { | ||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) | ||
qInstallMessageHandler(debugIgnoringMessageHandlerQt5); | ||
#else | ||
qInstallMsgHandler(debugIgnoringMessageHandler); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
void ignoreDebugOutput(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <QtTest/QtTest> | ||
#include <stdio.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include "../src/IgnoreDebugOutput.h" | ||
|
||
#define MAX_LEN 40 | ||
|
||
class TestIgnoreDebugOutput: public QObject { | ||
Q_OBJECT | ||
|
||
private slots: | ||
void testIgnoreDebugOutput(); | ||
}; | ||
|
||
void TestIgnoreDebugOutput::testIgnoreDebugOutput() { | ||
char buffer[MAX_LEN+1] = {0}; | ||
int out_pipe[2]; | ||
int saved_stdout; | ||
|
||
saved_stdout = dup(STDOUT_FILENO); | ||
|
||
QVERIFY(pipe(out_pipe) == 0); | ||
|
||
dup2(out_pipe[1], STDOUT_FILENO); | ||
close(out_pipe[1]); | ||
|
||
long flags = fcntl(out_pipe[0], F_GETFL); | ||
flags |= O_NONBLOCK; | ||
fcntl(out_pipe[0], F_SETFL, flags); | ||
|
||
ignoreDebugOutput(); | ||
|
||
qDebug() << "Message"; | ||
fflush(stdout); | ||
|
||
read(out_pipe[0], buffer, MAX_LEN); | ||
|
||
dup2(saved_stdout, STDOUT_FILENO); | ||
|
||
QCOMPARE(QString(buffer), QString("")); | ||
} | ||
|
||
QTEST_MAIN(TestIgnoreDebugOutput) | ||
#include "testignoredebugoutput.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SOURCES = testignoredebugoutput.cpp | ||
OBJECTS += ../src/IgnoreDebugOutput.o | ||
QT += testlib | ||
CONFIG += testcase console | ||
CONFIG -= app_bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
TEMPLATE = subdirs | ||
CONFIG += ordered | ||
SUBDIRS += src/webkit_server.pro | ||
|
||
test { | ||
SUBDIRS += test/testwebkitserver.pro | ||
} |