Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ addons:

script: ./travis.sh

notifications:
email:
- cukes-devs@googlegroups.com
#notifications:
# email:
# - cukes-devs@googlegroups.com

branches:
only:
- master
#branches:
# only:
# - master
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ It relies on a few libraries:
Optional for the CppSpec driver.
* [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](http://qt-project.org/). Optional for the CalcQt example.
* [Qt 4 or 5](http://qt-project.org/). Optional for the CalcQt example.

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

Expand Down
52 changes: 40 additions & 12 deletions examples/CalcQt/CMakeLists.txt
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is LIBCALCQT_BUILD really needed? If it's for the if(LIBCALCQT_BUILD) later on, can't you use the QT_LIBRARIES variable?

Copy link
Copy Markdown
Contributor Author

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.

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()
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

#include <cstdlib>

#include <boost/test/unit_test.hpp>
#include <cucumber-cpp/defs.hpp>

#include <QApplication>
#include <QTest>

#include <CalculatorWidget.h>
#include "CalculatorWidget.h"

static int argc = 0;
static QApplication app(argc, 0);
Expand All @@ -23,13 +20,17 @@ int millisecondsToWait() {
}

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.toAscii().data(); return out; }
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());
}

Expand Down
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());
}
6 changes: 3 additions & 3 deletions examples/CalcQt/src/CalculatorWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "CalculatorWidget.h"

#include <stdio.h>
#include <QGridLayout>
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>
#include <QSignalMapper>

CalculatorWidget::CalculatorWidget(QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags) {
QGridLayout *layout = new QGridLayout;
QGridLayout *layout = new QGridLayout(this);
layout->setSizeConstraint(QLayout::SetFixedSize);
setLayout(layout);

Expand Down Expand Up @@ -69,7 +68,7 @@ int CalculatorWidget::calculate(const QString& expression) {
}
pos += regexp.matchedLength();
if (pos < expression.length()) {
operation = expression.at(pos).toAscii();
operation = expression.at(pos).toLatin1();
}
}
return result;
Expand Down Expand Up @@ -103,6 +102,7 @@ void CalculatorWidget::keyPressEvent(QKeyEvent *event) {
}

void CalculatorWidget::keyReleaseEvent(QKeyEvent *event) {
Q_UNUSED(event)
if (0 != keyclickedButton) {
keyclickedButton->setDown(false);
keyclickedButton = 0;
Expand Down
3 changes: 2 additions & 1 deletion examples/CalcQt/src/CalculatorWidget.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class QLabel;
class QPushButton;
#include <QString>
class QSignalMapper;

#include <QString>
#include <QWidget>

class CalculatorWidget : public QWidget {
Expand Down