-
Notifications
You must be signed in to change notification settings - Fork 139
QtTest driver v2 #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QtTest driver v2 #142
Changes from 6 commits
964af78
26e6feb
411cdbd
d833723
b1eaf2c
795ced6
15164eb
d1b3ffd
5b10e66
3218931
0202bed
ff88570
0858492
e2373da
288a6ad
742b88d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| cmake_minimum_required(VERSION 2.8.12) | ||
| cmake_minimum_required(VERSION 3.1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I think we already needed 3.1 anyway (for both |
||
|
|
||
| project(Cucumber-Cpp) | ||
|
|
||
|
|
@@ -13,7 +13,9 @@ set(CUKE_ENABLE_EXAMPLES OFF CACHE BOOL "Enable the examples") | |
| set(GMOCK_SRC_DIR "" CACHE STRING "Google Mock framework sources path (otherwise downloaded)") | ||
| set(GMOCK_VER "1.7.0" CACHE STRING "Google Mock framework version to be used") | ||
| option(VALGRIND_TESTS "Run tests within Valgrind" OFF) | ||
| set(CUKE_DISABLE_QT OFF CACHE BOOL "Disable using Qt framework") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For boolean parameters I recommend using |
||
|
|
||
| set(ignoreMe "${QT_QMAKE_EXECUTABLE}") #supress warning | ||
| set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) | ||
|
|
||
| # | ||
|
|
@@ -31,6 +33,40 @@ elseif(MSVC) | |
| #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /analyze") | ||
| endif() | ||
|
|
||
| # | ||
| # Qt | ||
| # | ||
|
|
||
| if(NOT CUKE_DISABLE_QT) | ||
| set(CMAKE_PREFIX_PATH $ENV{QTDIR}) | ||
| find_package(Qt5Core QUIET) | ||
| find_package(Qt5Widgets QUIET) | ||
| find_package(Qt5Test QUIET) | ||
| if(${Qt5Core_FOUND} AND ${Qt5Widgets_FOUND} AND ${Qt5Test_FOUND}) | ||
| set(QT5_FOUND true) | ||
| message(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}") | ||
| include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS}) | ||
| if (Qt5_POSITION_INDEPENDENT_CODE) | ||
| SET(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
| endif() | ||
| set(QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Test) | ||
|
|
||
| #check if c++11 is nedded | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use this instead: if(NOT QT_VERSION VERSION_LESS 5.7)That does a proper lexicographic comparison of the version number. |
||
| message(STATUS "C++11 is needed from Qt version 5.7.0, building with c++11 enabled") | ||
| set(CMAKE_CXX_STANDARD 11) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you just build the Qt specific bits with C++11 instead of everything?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting this for everything fixed TCPserver tests
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are they broken? Because they seem to be running fine on Travis. AFAIK we're doing a lot of work to be C++98 compatible. Just flipping the switch like this throws away our testing of that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see issue #141 - we can discuss further there the ServerTests. |
||
| endif() | ||
| else() | ||
| find_package(Qt4 COMPONENTS QtCore QtGui QtTest) | ||
| if(QT4_FOUND) | ||
| set(QT_LIBRARIES Qt4::QtCore Qt4::QtGui Qt4::QtTest) | ||
| include(${QT_USE_FILE}) | ||
| endif() | ||
| endif() | ||
| endif() | ||
|
|
||
| # | ||
| # Boost | ||
| # | ||
|
|
@@ -154,11 +190,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) | ||
|
|
||
| # | ||
|
|
@@ -223,3 +256,4 @@ endif() | |
| if(CUKE_ENABLE_EXAMPLES) | ||
| add_subdirectory(examples) | ||
| endif() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| set PATH=C:\Ruby200\bin;%BOOST_LIBRARYDIR%;%PATH% | ||
| if defined MINGW_ROOT set PATH=%MINGW_ROOT%\bin;C:\msys64\usr\bin\;%PATH% | ||
| if defined QT_DIR set PATH=%QT_DIR%\bin;%PATH% | ||
| if "%CMAKE_GENERATOR%"=="NMake Makefiles" call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %PLATFORM% | ||
| echo %PATH% | ||
|
|
||
| git submodule init | ||
| git submodule update | ||
| call gem install bundle | ||
| call bundle install | ||
| if defined MINGW_ARCH bash -lc "pacman --needed --noconfirm -S mingw-w64-%MINGW_ARCH%-boost | ||
|
|
||
| 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 | ||
|
|
||
| set CTEST_OUTPUT_ON_FAILURE=ON | ||
| cmake --build build --target test | ||
| cmake --build build --target features | ||
|
|
| 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); | ||
| } | ||
|
|
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't compare the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is not my code to be honest but I can change it |
||
| } | ||
| 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; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you convert to UTF-8 instead? That's the default on most modern Unices. Or better yet, if QString supports it, convert to whatever multi-byte encoding the current locale has.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because windows
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not even Windows has Latin-1 as default always. It's dependent on the locale, e.g. when set to Russian it has some Cyrillic code page. Anyway, I suggest you try toLocal8Bit() instead. It uses whatever the locale says to use as encoding.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed it to local8bit - let's see how it behaves on Windows |
||
|
|
||
| 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()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if this could be done with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! I've done that. |
||
| } | ||
|
|
||
| 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()); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: doesn't brew support installing multiple packages at once? E.g.
brew install ninja qt5?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are probably right - I have no expirience with OSX