forked from cucumber/cucumber-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[QtTestDriver] Qt test driver for cucumber-cpp.
Implementation based on temporary file. When building QtTest driver C++11 is enabled globally to prevent issue cucumber#141.
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 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
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,40 @@ | ||
#ifndef CUKE_QTTESTDRIVER_HPP_ | ||
#define CUKE_QTTESTDRIVER_HPP_ | ||
|
||
#include "../step/StepManager.hpp" | ||
#include <QObject> | ||
|
||
namespace cucumber { | ||
namespace internal { | ||
|
||
class QtTestStep : public BasicStep { | ||
friend class QtTestObject; | ||
|
||
public: | ||
QtTestStep() : BasicStep() {} | ||
|
||
protected: | ||
const InvokeResult invokeStepBody(); | ||
}; | ||
|
||
#define STEP_INHERITANCE(step_name) ::cucumber::internal::QtTestStep | ||
|
||
class QtTestObject : public QObject { | ||
Q_OBJECT | ||
public: | ||
QtTestObject(QtTestStep* qtTestStep): step(qtTestStep) {} | ||
virtual ~QtTestObject() {} | ||
|
||
protected: | ||
QtTestStep* step; | ||
|
||
private slots: | ||
void test() const { | ||
step->body(); | ||
} | ||
}; | ||
|
||
} | ||
} | ||
|
||
#endif /* CUKE_QTTESTDRIVER_HPP_ */ |
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,33 @@ | ||
#include "cucumber-cpp/internal/drivers/QtTestDriver.hpp" | ||
|
||
#include <QtTest/QtTest> | ||
#include <QTextStream> | ||
#include <QTemporaryFile> | ||
|
||
namespace cucumber { | ||
namespace internal { | ||
|
||
const InvokeResult QtTestStep::invokeStepBody() { | ||
QTemporaryFile file; | ||
if (!file.open()) { | ||
return InvokeResult::failure("Unable to open temporary file needed for this test"); | ||
} | ||
file.close(); | ||
|
||
QtTestObject testObject(this); | ||
int returnValue = QTest::qExec(&testObject, | ||
QStringList() << "test" | ||
<< "-o" | ||
<< file.fileName()); | ||
if (returnValue == 0) { | ||
return InvokeResult::success(); | ||
} else { | ||
file.open(); | ||
QTextStream ts(&file); | ||
return InvokeResult::failure(ts.readAll().toLocal8Bit()); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|