File tree Expand file tree Collapse file tree 13 files changed +177
-1
lines changed
features/step_definitions
features/step_definitions
include/cucumber-cpp/internal/drivers Expand file tree Collapse file tree 13 files changed +177
-1
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,10 @@ if(NOT CUKE_DISABLE_QT)
124
124
if (${Qt5Core_FOUND} AND ${Qt5Widgets_FOUND} AND ${Qt5Test_FOUND} )
125
125
message (STATUS "Found Qt version: ${Qt5Core_VERSION_STRING} " )
126
126
set (QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Test )
127
+ if (NOT Qt5Core_VERSION_STRING VERSION_LESS 5.7 AND (NOT DEFINED CMAKE_CXX_STANDARD OR NOT CMAKE_CXX_STANDARD STREQUAL 98 ))
128
+ message (STATUS "C++11 is needed from Qt version 5.7.0, building with c++11 enabled" )
129
+ set (CMAKE_CXX_STANDARD 11 )
130
+ endif ()
127
131
else ()
128
132
find_package (Qt4 COMPONENTS QtCore QtGui QtTest )
129
133
if (QT4_FOUND )
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ It relies on a few libraries:
33
33
Optional for the GTest driver. By default downloaded and built by CMake.
34
34
* [ GMock] ( http://code.google.com/p/googlemock/ ) 1.6 or later.
35
35
Optional for the internal test suite. By default downloaded and built by CMake.
36
- * [ Qt 4 or 5] ( http://qt-project.org/ ) . Optional for the CalcQt example.
36
+ * [ Qt 4 or 5] ( http://qt-project.org/ ) . Optional for the CalcQt example and QtTest driver (only Qt 5) .
37
37
38
38
This header-only library is included in the source code:
39
39
Original file line number Diff line number Diff line change @@ -20,3 +20,8 @@ if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
20
20
add_executable (BoostCalculatorSteps features/step_definitions/BoostCalculatorSteps )
21
21
target_link_libraries (BoostCalculatorSteps Calc ${CUKE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )
22
22
endif ()
23
+
24
+ if (Qt5TEST_FOUND )
25
+ add_executable (QtTestCalculatorSteps features/step_definitions/QtTestCalculatorSteps )
26
+ target_link_libraries (QtTestCalculatorSteps Calc ${QT_LIBRARIES} ${CUKE_LIBRARIES} )
27
+ endif ()
Original file line number Diff line number Diff line change
1
+ #include < QTest>
2
+ // Pretend to be GTest
3
+ #define EXPECT_EQ QCOMPARE
4
+ #include " CalculatorSteps.cpp"
Original file line number Diff line number Diff line change @@ -9,12 +9,20 @@ if(QT_LIBRARIES)
9
9
add_executable (calcqt src/CalcQt.cpp )
10
10
target_link_libraries (calcqt libcalcqt ${QT_LIBRARIES} )
11
11
12
+ if (Qt5TEST_FOUND )
13
+ add_executable (QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps )
14
+ set_target_properties (QtTestCalculatorQtSteps PROPERTIES AUTOMOC ON )
15
+ target_link_libraries (QtTestCalculatorQtSteps PRIVATE libcalcqt ${QT_LIBRARIES} ${CUKE_LIBRARIES} )
16
+ endif ()
17
+
12
18
if (Boost_UNIT_TEST_FRAMEWORK_FOUND )
13
19
add_executable (BoostCalculatorQtSteps features/step_definitions/BoostCalculatorQtSteps )
14
20
target_link_libraries (BoostCalculatorQtSteps libcalcqt ${CUKE_LIBRARIES} ${QT_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )
15
21
endif ()
22
+
16
23
if (GTEST_FOUND )
17
24
add_executable (GTestCalculatorQtSteps features/step_definitions/GTestCalculatorQtSteps )
18
25
target_link_libraries (GTestCalculatorQtSteps libcalcqt ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES} ${QT_LIBRARIES} )
19
26
endif ()
27
+
20
28
endif ()
Original file line number Diff line number Diff line change
1
+ #include < QTest>
2
+ // Pretend to be GTest
3
+ #define EXPECT_EQ QCOMPARE
4
+ #include " CalculatorQtSteps.cpp"
Original file line number Diff line number Diff line change 2
2
#include " GTestDriver.hpp"
3
3
#elif defined(BOOST_TEST_CASE)
4
4
#include " BoostDriver.hpp"
5
+ #elif defined(QTEST_H)
6
+ #include " QtTestDriver.hpp"
5
7
#endif
Original file line number Diff line number Diff line change
1
+ #ifndef CUKE_QTTESTDRIVER_HPP_
2
+ #define CUKE_QTTESTDRIVER_HPP_
3
+
4
+ #include " ../step/StepManager.hpp"
5
+ #include < QObject>
6
+
7
+ namespace cucumber {
8
+ namespace internal {
9
+
10
+ class QtTestStep : public BasicStep {
11
+ friend class QtTestObject ;
12
+ public:
13
+ QtTestStep (): BasicStep() {}
14
+
15
+ protected:
16
+ const InvokeResult invokeStepBody ();
17
+ };
18
+
19
+ #define STEP_INHERITANCE (step_name ) ::cucumber::internal::QtTestStep
20
+
21
+ class QtTestObject : public QObject {
22
+ Q_OBJECT
23
+ public:
24
+ QtTestObject (QtTestStep* qtTestStep): step(qtTestStep) {}
25
+ virtual ~QtTestObject () {}
26
+
27
+ protected:
28
+ QtTestStep* step;
29
+
30
+ private slots:
31
+ void test () const {
32
+ step->body ();
33
+ }
34
+ };
35
+
36
+ }
37
+ }
38
+
39
+ #endif /* CUKE_QTTESTDRIVER_HPP_ */
Original file line number Diff line number Diff line change @@ -26,6 +26,13 @@ if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
26
26
list (APPEND CUKE_SOURCES drivers/BoostDriver.cpp )
27
27
endif ()
28
28
29
+ if (Qt5TEST_FOUND )
30
+ qt5_wrap_cpp (MOC_FILE ../include/cucumber-cpp/internal/drivers/QtTestDriver.hpp )
31
+ list (APPEND CUKE_SOURCES ${MOC_FILE} )
32
+ list (APPEND CUKE_SOURCES drivers/QtTestDriver.cpp )
33
+ list (APPEND CUKE_DEP_LIBRARIES ${QT_LIBRARIES} )
34
+ endif ()
35
+
29
36
if (CMAKE_EXTRA_GENERATOR OR MSVC_IDE )
30
37
message (STATUS "Adding header files to project" )
31
38
file (GLOB_RECURSE CUKE_HEADERS "${CUKE_INCLUDE_DIR} /cucumber-cpp/*.hpp" )
Original file line number Diff line number Diff line change
1
+ #include " cucumber-cpp/internal/drivers/QtTestDriver.hpp"
2
+
3
+ #include < QtTest/QtTest>
4
+ #include < QTextStream>
5
+ #include < QTemporaryFile>
6
+
7
+ namespace cucumber {
8
+ namespace internal {
9
+
10
+ const InvokeResult QtTestStep::invokeStepBody () {
11
+ QTemporaryFile file;
12
+ QString fileName;
13
+ if (!file.open ()) {
14
+ return InvokeResult::failure (" Unable to open temporary file needed for this test" );
15
+ }
16
+ file.close ();
17
+
18
+ QtTestObject testObject (this );
19
+ int returnValue = QTest::qExec (&testObject, QStringList () << " test" << " -o" << file.fileName ());
20
+ if (returnValue == 0 )
21
+ return InvokeResult::success ();
22
+ else
23
+ {
24
+ file.open ();
25
+ QTextStream ts (&file);
26
+ return InvokeResult::failure (ts.readAll ().toLocal8Bit ());
27
+ }
28
+ }
29
+
30
+ }
31
+ }
32
+
Original file line number Diff line number Diff line change @@ -48,4 +48,8 @@ if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
48
48
cuke_add_driver_test (integration/drivers/BoostDriverTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )
49
49
endif ()
50
50
51
+ if (Qt5TEST_FOUND )
52
+ cuke_add_driver_test (integration/drivers/QtTestDriverTest ${QT_LIBRARIES} )
53
+ endif ()
54
+
51
55
cuke_add_driver_test (integration/drivers/GenericDriverTest )
Original file line number Diff line number Diff line change
1
+ #include < QtTest>
2
+ #include < cucumber-cpp/autodetect.hpp>
3
+
4
+ #include " ../../utils/DriverTestRunner.hpp"
5
+
6
+ using namespace cucumber ;
7
+
8
+ THEN (SUCCEED_MATCHER) {
9
+ ScenarioScope<SomeContext> ctx;
10
+ QVERIFY (true );
11
+ }
12
+
13
+ THEN (FAIL_MATCHER) {
14
+ ScenarioScope<SomeContext> ctx;
15
+ QVERIFY (false );
16
+ }
17
+
18
+ THEN (PENDING_MATCHER_1) {
19
+ pending ();
20
+ }
21
+
22
+ THEN (PENDING_MATCHER_2) {
23
+ pending (PENDING_DESCRIPTION);
24
+ }
25
+
26
+ using namespace cucumber ::internal;
27
+
28
+ class QtTestStepDouble : public QtTestStep {
29
+ public:
30
+ QtTestStepDouble () : QtTestStep() {
31
+ testRun = false ;
32
+ }
33
+
34
+ const InvokeResult invokeStepBody () {
35
+ return QtTestStep::invokeStepBody ();
36
+ }
37
+
38
+ void body () {
39
+ testRun = true ;
40
+ }
41
+
42
+ bool testRun;
43
+ };
44
+
45
+ class QtTestDriverTest : public DriverTest {
46
+ public:
47
+ virtual void runAllTests () {
48
+ stepInvocationRunsStepBody ();
49
+ DriverTest::runAllTests ();
50
+ }
51
+
52
+ private:
53
+ void stepInvocationRunsStepBody () {
54
+ QtTestStepDouble framework;
55
+ expectFalse (" The test body has not been run" , framework.testRun );
56
+ framework.invokeStepBody ();
57
+ expectTrue (" The test body has been run" , framework.testRun );
58
+ }
59
+ };
60
+
61
+ int main () {
62
+ QtTestDriverTest test;
63
+ return test.run ();
64
+ }
65
+
Original file line number Diff line number Diff line change 53
53
54
54
for TEST in \
55
55
build/examples/Calc/GTestCalculatorSteps \
56
+ build/examples/Calc/QtTestCalculatorSteps \
56
57
build/examples/Calc/BoostCalculatorSteps \
57
58
build/examples/Calc/FuncArgsCalculatorSteps \
58
59
; do
66
67
67
68
for TEST in \
68
69
build/examples/CalcQt/GTestCalculatorQtSteps \
70
+ build/examples/CalcQt/QtTestCalculatorQtSteps \
69
71
build/examples/CalcQt/BoostCalculatorQtSteps \
70
72
; do
71
73
if [ -f " ${TEST} " -a -n " ${DISPLAY:- } " ]; then
You can’t perform that action at this time.
0 commit comments