-
Notifications
You must be signed in to change notification settings - Fork 141
Qt5 support for CalcQt example #98
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,21 +1,49 @@ | ||
| project(CalcQt) | ||
|
|
||
| find_package(Qt4 COMPONENTS QtCore QtGui QtTest) | ||
| set(CALCQT_HEADERS src/CalculatorWidget.h) | ||
| set(CALCQT_SOURCES src/CalcQt.cpp src/CalculatorWidget.cpp) | ||
| set(LIBCALCQT_BUILD OFF) | ||
| include_directories(${CUKE_INCLUDE_DIRS} src) | ||
|
|
||
| if(QT4_FOUND) | ||
| include(${QT_USE_FILE}) | ||
| set(CALCQT_HEADERS src/CalculatorWidget.h) | ||
| qt4_wrap_cpp(CALCQT_HEADERS_MOC ${CALCQT_HEADERS}) | ||
| include_directories(${CUKE_INCLUDE_DIRS} src) | ||
| add_library(CalcQt src/CalculatorWidget ${CALCQT_HEADERS_MOC}) | ||
| find_package(Qt5Core QUIET) | ||
| find_package(Qt5Widgets QUIET) | ||
| find_package(Qt5Test QUIET) | ||
|
|
||
| if(${Qt5Core_FOUND} AND ${Qt5Widgets_FOUND} AND ${Qt5Test_FOUND}) | ||
| set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
| set(CMAKE_AUTOMOC ON) | ||
| set(QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Test) | ||
|
|
||
| add_library(libcalcqt src/CalculatorWidget.cpp ${CALCQT_HEADERS}) | ||
| target_link_libraries(libcalcqt ${QT_LIBRARIES}) | ||
|
|
||
| add_executable(calcqt ${CALCQT_SOURCES}) | ||
| target_link_libraries(calcqt libcalcqt ${QT_LIBRARIES}) | ||
|
|
||
| set(LIBCALCQT_BUILD ON) | ||
| else() | ||
| find_package(Qt4 COMPONENTS QtCore QtGui QtTest) | ||
| if(QT4_FOUND) | ||
| include(${QT_USE_FILE}) | ||
| qt4_wrap_cpp(CALCQT_HEADERS_MOC ${CALCQT_HEADERS}) | ||
| add_library(libcalcqt src/CalculatorWidget ${CALCQT_HEADERS_MOC}) | ||
|
|
||
| add_executable(calcqt ${CALCQT_SOURCES} ${CALCQT_HEADERS_MOC}) | ||
| target_link_libraries(calcqt ${QT_LIBRARIES}) | ||
|
|
||
| set(LIBCALCQT_BUILD ON) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(LIBCALCQT_BUILD) | ||
| if(Boost_UNIT_TEST_FRAMEWORK_FOUND) | ||
| include_directories(${Boost_INCLUDE_DIRS}) | ||
| add_executable(BoostCalculatorQtSteps features/step_definitions/BoostCalculatorQtSteps) | ||
| target_link_libraries(BoostCalculatorQtSteps CalcQt ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${CUKE_LIBRARIES} ${QT_LIBRARIES}) | ||
| target_link_libraries(BoostCalculatorQtSteps libcalcqt ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${CUKE_LIBRARIES} ${QT_LIBRARIES}) | ||
| endif() | ||
| if(GTEST_FOUND) | ||
| include_directories(${GTEST_INCLUDE_DIRS}) | ||
| add_executable(GTestCalculatorQtSteps features/step_definitions/GTestCalculatorQtSteps) | ||
| target_link_libraries(GTestCalculatorQtSteps libcalcqt ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES} ${QT_LIBRARIES}) | ||
| endif() | ||
|
|
||
| set(CALCQT_SOURCES src/CalcQt.cpp src/CalculatorWidget.cpp) | ||
| add_executable(calcqt ${CALCQT_SOURCES} ${CALCQT_HEADERS_MOC}) | ||
| target_link_libraries(calcqt ${QT_LIBRARIES}) | ||
| endif() | ||
This file contains hidden or 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
74 changes: 74 additions & 0 deletions
74
examples/CalcQt/features/step_definitions/GTestCalculatorQtSteps.cpp
This file contains hidden or 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,74 @@ | ||
| #include <cstdlib> | ||
| #include <gtest/gtest.h> | ||
| #include <cucumber-cpp/defs.hpp> | ||
| #include <QApplication> | ||
| #include <QTest> | ||
|
|
||
| #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; | ||
| EXPECT_EQ(calculator->display().size(), 0); | ||
| QTest::qWait(millisecondsToWait()); | ||
| } | ||
|
|
||
| THEN("^the display should show (.*)$") { | ||
| REGEX_PARAM(QString, expected); | ||
| cucumber::ScenarioScope<CalculatorWidget> calculator; | ||
| EXPECT_EQ(expected, calculator->display()); | ||
| QTest::qWait(millisecondsToWait()); | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is
LIBCALCQT_BUILDreally needed? If it's for theif(LIBCALCQT_BUILD)later on, can't you use theQT_LIBRARIESvariable?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.
Good idea ;) Let's check that.