Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:
- os: osx
env: GMOCK_PATH=/usr/src/gmock
- os: osx
compiler: gcc #does anyone on osx use it?
compiler: gcc

addons:
apt:
Expand All @@ -30,6 +30,7 @@ addons:
- libboost-test-dev
- google-mock
- ninja-build
- qtbase5-dev

before_install:
- if [[ "${TRAVIS_OS_NAME}" = "osx" ]]; then brew update && brew install ninja; fi
Expand Down
42 changes: 39 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ elseif(MSVC)
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /analyze")
endif()

#
# Qt
#

find_package(Qt5Core QUIET)
find_package(Qt5Widgets QUIET)
find_package(Qt5Test QUIET)
find_package(Qt5Concurrent QUIET)

if(${Qt5Core_FOUND} AND ${Qt5Test_FOUND})
message(STATUS "Using Qt version: ${Qt5Core_VERSION_STRING}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
if (Qt5_POSITION_INDEPENDENT_CODE)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
set(QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Test)
endif()

#
# Boost
#
Expand Down Expand Up @@ -107,11 +126,8 @@ endif()
#

set(CUKE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

include_directories(${CUKE_INCLUDE_DIR})

set(CUKE_LIBRARIES cucumber-cpp ${CUKE_EXTRA_LIBRARIES})

add_subdirectory(src)

#
Expand Down Expand Up @@ -176,3 +192,23 @@ endif()
if(CUKE_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()

#check if c++11 is nedded
if(${Qt5Core_FOUND} AND ${Qt5Test_FOUND})
find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
if(QT_VERSION GREATER 5.6.99)
message(STATUS "C++11 is needed from Qt version 5.7.0, building with c++11 enabled")
set_property(TARGET cucumber-cpp PROPERTY CXX_STANDARD 11)
set_property(TARGET cucumber-cpp-nomain PROPERTY CXX_STANDARD 11)
if(NOT CUKE_DISABLE_UNIT_TESTS)
set_property(TARGET QtTestDriverTest PROPERTY CXX_STANDARD 11)
endif()
if(CUKE_ENABLE_EXAMPLES)
set_property(TARGET libcalcqt PROPERTY CXX_STANDARD 11)
set_property(TARGET calcqt PROPERTY CXX_STANDARD 11)
set_property(TARGET QtTestCalculatorQtSteps PROPERTY CXX_STANDARD 11)
endif()
endif()
endif()

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ It relies on a few libraries:
Optional for the GTest driver. By default downloaded and built by CMake.
* [GMock](http://code.google.com/p/googlemock/) 1.6 or later.
Optional for the internal test suite. By default downloaded and built by CMake.
* [Qt 4 or 5](http://qt-project.org/). Optional for the CalcQt example.
* [Qt](http://www.qt.io/)
Optional for the CalcQt example: version 4.x or 5.x, modules: *core*, *widgets* and *test*.
Optional for QtTest driver: version 5.x, modules: *core* and *test*.

This header-only library is included in the source code:

Expand Down
13 changes: 13 additions & 0 deletions appveyor.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
git submodule init
git submodule update
call gem install bundle
call bundle install
REM bundle env
if "%build%"=="mingw" bash -lc "pacman --needed --noconfirm -S mingw-w64-%MINGW_ARCH%-boost
if "%build%"=="msvc" call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %PLATFORM%

cmake -E make_directory build
cmake -E chdir build cmake -G "%CMAKE_GENERATOR%" -DCUKE_ENABLE_EXAMPLES=on -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_INCLUDEDIR="%BOOST_INCLUDEDIR%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DQT_QMAKE_EXECUTABLE="%QT_DIR%/bin/qmake.exe" ..
cmake --build build
cmake --build build --target test
cmake --build build --target features
14 changes: 4 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,22 @@ environment:
BOOST_LIBRARYDIR: C:\Libraries\boost_1_59_0\lib32-msvc-14.0
BOOST_INCLUDEDIR: C:\Libraries\boost_1_59_0\boost
CMAKE_GENERATOR: 'NMake Makefiles'
QT_DIR: C:\Qt\5.7\msvc2015
- build: msvc
platform: x64
BOOST_ROOT: C:\Libraries\boost_1_59_0
BOOST_INCLUDEDIR: C:\Libraries\boost_1_59_0\boost
BOOST_LIBRARYDIR: C:\Libraries\boost_1_59_0\lib64-msvc-14.0
CMAKE_GENERATOR: 'NMake Makefiles'
QT_DIR: C:\Qt\5.7\msvc2015_64

install:
- git submodule init
- git submodule update
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%BOOST_LIBRARYDIR%;%PATH%
- gem install bundle
- bundle install
- bundle env
- if "%build%"=="mingw" set PATH=%MINGW_ROOT%\bin;C:\msys64\usr\bin\;%PATH%
- if "%build%"=="mingw" bash -lc "pacman --needed --noconfirm -S mingw-w64-%MINGW_ARCH%-boost
- if "%build%"=="msvc" set PATH=%QT_DIR%\bin;%PATH%

build_script:
- cmd: if "%build%"=="msvc" call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %PLATFORM%
- cmd: cmake -E make_directory build
- cmd: cmake -E chdir build cmake -G "%CMAKE_GENERATOR%" -DCUKE_ENABLE_EXAMPLES=ON -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_INCLUDEDIR="%BOOST_INCLUDEDIR%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" ..
- cmd: cmake --build build
- cmd: call appveyor.bat

test_script:
- cmd: set CTEST_OUTPUT_ON_FAILURE=ON
Expand Down
6 changes: 6 additions & 0 deletions examples/Calc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
add_executable(BoostCalculatorSteps features/step_definitions/BoostCalculatorSteps)
target_link_libraries(BoostCalculatorSteps Calc ${CUKE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
endif()

if(${Qt5Core_FOUND} AND ${Qt5Test_FOUND})
include_directories(${Qt5Core_INCLUDE_DIRS})
add_executable(QtTestCalculatorSteps features/step_definitions/QtTestCalculatorSteps)
target_link_libraries(QtTestCalculatorSteps Calc Qt5::Core Qt5::Test ${CUKE_LIBRARIES})
endif()
38 changes: 38 additions & 0 deletions examples/Calc/features/step_definitions/QtTestCalculatorSteps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <QTest>
#include <cucumber-cpp/autodetect.hpp>

#include "Calculator.h"

using cucumber::ScenarioScope;

struct CalcCtx {
Calculator calc;
double result;
};

GIVEN("^I have entered (\\d+) into the calculator$") {
REGEX_PARAM(double, n);
ScenarioScope<CalcCtx> context;

context->calc.push(n);
}

WHEN("^I press add") {
ScenarioScope<CalcCtx> context;

context->result = context->calc.add();
}

WHEN("^I press divide") {
ScenarioScope<CalcCtx> context;

context->result = context->calc.divide();
}

THEN("^the result should be (.*) on the screen$") {
REGEX_PARAM(double, expected);
ScenarioScope<CalcCtx> context;

QCOMPARE(expected, context->result);
}

3 changes: 3 additions & 0 deletions examples/CalcQt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ if(${Qt5Core_FOUND} AND ${Qt5Widgets_FOUND} AND ${Qt5Test_FOUND})

add_executable(calcqt ${CALCQT_SOURCES})
target_link_libraries(calcqt libcalcqt ${QT_LIBRARIES})

add_executable(QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps)
target_link_libraries(QtTestCalculatorQtSteps libcalcqt ${QT_LIBRARIES} ${CUKE_LIBRARIES})
else()
find_package(Qt4 COMPONENTS QtCore QtGui QtTest)
if(QT4_FOUND)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <QTest>
#include <cucumber-cpp/autodetect.hpp>
#include <cstdlib>
#include <QApplication>
#include "CalculatorWidget.h"

static int argc = 0;
static QApplication app(argc, 0);
static int milliseconds = -1;

int millisecondsToWait() {
if (milliseconds < 0)
{
char* envVariable = getenv("CALCQT_STEP_DELAY");
milliseconds = (0 != envVariable) ? atoi(envVariable) : 0;
}
return milliseconds;
}

std::istream& operator>> (std::istream& in, QString& val) { std::string s; in >> s; val = s.c_str(); return in; }
std::ostream& operator<< (std::ostream& out, const QString& val) { out << val.toLatin1().data(); return out; }

GIVEN("^I just turned on the calculator$") {
cucumber::ScenarioScope<CalculatorWidget> calculator;
calculator->move(0, 0);
calculator->show();
#if QT_VERSION >= 0x050000
QTest::qWaitForWindowExposed(calculator.get());
#else
QTest::qWaitForWindowShown(calculator.get());
#endif
QTest::qWait(millisecondsToWait());
}

WHEN("^I press (\\d+)$") {
REGEX_PARAM(unsigned int, n);
cucumber::ScenarioScope<CalculatorWidget> calculator;
QTest::keyClick(calculator.get(), Qt::Key_0 + n, Qt::NoModifier, millisecondsToWait());
}

WHEN("^I press add") {
cucumber::ScenarioScope<CalculatorWidget> calculator;
QTest::keyClick(calculator.get(), Qt::Key_Plus, Qt::NoModifier, millisecondsToWait());
}

WHEN("^I press calculate") {
cucumber::ScenarioScope<CalculatorWidget> calculator;
QTest::keyClick(calculator.get(), Qt::Key_Return, Qt::NoModifier, millisecondsToWait());
}

WHEN("^I press clear") {
cucumber::ScenarioScope<CalculatorWidget> calculator;
QTest::keyClick(calculator.get(), Qt::Key_Escape, Qt::NoModifier, millisecondsToWait());
}

WHEN("^I press subtract") {
cucumber::ScenarioScope<CalculatorWidget> calculator;
QTest::keyClick(calculator.get(), Qt::Key_Minus, Qt::NoModifier, millisecondsToWait());
}

THEN("^the display should be empty$") {
cucumber::ScenarioScope<CalculatorWidget> calculator;
QCOMPARE(0, calculator->display().size());
QTest::qWait(millisecondsToWait());
}

THEN("^the display should show (.*)$") {
REGEX_PARAM(QString, expected);
cucumber::ScenarioScope<CalculatorWidget> calculator;
QCOMPARE(calculator->display(), expected);
QTest::qWait(millisecondsToWait());
}
3 changes: 3 additions & 0 deletions include/cucumber-cpp/internal/drivers/DriverSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
#include "GTestDriver.hpp"
#elif defined(BOOST_TEST_CASE)
#include "BoostDriver.hpp"
#elif defined(QTEST_H)
#include "QtTestDriver.hpp"
#endif

23 changes: 23 additions & 0 deletions include/cucumber-cpp/internal/drivers/QtTestDriver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef CUKE_QTTESTDRIVER_HPP_
#define CUKE_QTTESTDRIVER_HPP_

#include "../step/StepManager.hpp"

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

}
}

#endif /* CUKE_QTTESTDRIVER_HPP_ */
Loading