1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Rewrite qInstallMsgHandler test in C++

* Allows tests independent of debug settings for Qt
* Allows testing behavior unreachable from Ruby
This commit is contained in:
Joe Ferris 2013-11-10 16:52:01 -05:00
parent 48c7afe7e1
commit 87418b89db
11 changed files with 112 additions and 96 deletions

View file

@ -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"

View file

@ -0,0 +1,5 @@
SOURCES = testignoredebugoutput.cpp
OBJECTS += ../src/IgnoreDebugOutput.o
QT += testlib
CONFIG += testcase console
CONFIG -= app_bundle