*.o
+moc_*
*.la
*.lo
*~
+gmock/*
--- /dev/null
+#!/bin/sh
+
+# A script to fetch GMock from source repository, compile it and run the tests.
+
+PRE_WD=`pwd`
+
+# Go to correct directory
+cd `dirname $0`
+
+# Get gmock from svn
+echo "Fetching GMock source from http://googlemock.googlecode.com"
+svn checkout http://googlemock.googlecode.com/svn/trunk/ gmock
+
+cd gmock
+echo "Running autoreconf..."
+AUTOMAKE=automake-1.9 ACLOCAL=aclocal-1.9 autoreconf -f -v -i
+
+mkdir build
+cd build
+
+echo "Running configure..."
+../configure
+
+echo "Running make..."
+make -j3
+echo "Running make check..."
+make check
+
+echo "All done"
+# Go back to original directory
+cd $PRE_WD
--- /dev/null
+GMOCKBUILDDIR = ../gmock/build
+QMAKE_CXXFLAGS += $$system($$GMOCKBUILDDIR/scripts/gmock-config --cppflags --cxxflags)
+QMAKE_LIBS += ../$$GMOCKBUILDDIR/lib/.libs/libgmock.a ../$$GMOCKBUILDDIR/gtest/lib/.libs/libgtest.a
--- /dev/null
+INCLUDEPATH += ../util
--- /dev/null
+Makefile
+ut_gmocktest
--- /dev/null
+#ifndef MOCK_TURTLE_H
+#define MOCK_TURTLE_H
+
+#include "turtle.h"
+#include <gmock/gmock.h>
+
+class MockTurtle : public Turtle {
+public:
+ MOCK_METHOD0(PenUp, void());
+ MOCK_METHOD0(PenDown, void());
+ MOCK_METHOD1(Forward, void(int distance));
+ MOCK_METHOD1(Turn, void(int degrees));
+ MOCK_METHOD2(GoTo, void(int x, int y));
+ MOCK_CONST_METHOD0(GetX, int());
+ MOCK_CONST_METHOD0(GetY, int());
+};
+
+#endif // MOCK_TURTLE_H
--- /dev/null
+#include "painter.h"
+#include "turtle.h"
+
+Painter::Painter(Turtle *turtle) :
+ turtle(turtle)
+{
+}
+
+Painter::~Painter() {
+}
+
+bool Painter::DrawCircle(int x, int y, int radius) {
+ turtle->PenDown();
+ emit DrawCircleCalled(x, y, radius);
+ return true;
+}
--- /dev/null
+#ifndef PAINTER_H
+#define PAINTER_H
+
+#include <QObject>
+
+class Turtle;
+
+class Painter : public QObject
+{
+ Q_OBJECT
+
+ Turtle *turtle;
+
+public:
+ Painter(Turtle *turtle);
+ virtual ~Painter();
+
+ bool DrawCircle(int x, int y, int radius);
+
+signals:
+ void DrawCircleCalled(int x, int y, int radius);
+};
+
+#endif // PAINTER_H
--- /dev/null
+#ifndef TURTLE_H
+#define TURTLE_H
+
+class Turtle {
+public:
+ virtual ~Turtle() {}
+ virtual void PenUp() = 0;
+ virtual void PenDown() = 0;
+ virtual void Forward(int distance) = 0;
+ virtual void Turn(int degrees) = 0;
+ virtual void GoTo(int x, int y) = 0;
+ virtual int GetX() const = 0;
+ virtual int GetY() const = 0;
+};
+
+#endif // TURTLE_H
--- /dev/null
+#include "mock_turtle.h"
+#include "painter.h"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <QSignalSpy>
+#include "stlhelpers4qt.h"
+
+using ::testing::AtLeast;
+
+TEST(PainterTest, TestTurtlePenDownCalledAtLeastOnceWhenDrawCircleCalled)
+{
+ MockTurtle turtle;
+ EXPECT_CALL(turtle, PenDown()).Times(AtLeast(1));
+
+ Painter painter(&turtle);
+
+ EXPECT_TRUE(painter.DrawCircle(0, 0, 10));
+}
+
+TEST(PainterTest, TestSignalEmittedWhenDrawCircleCalled)
+{
+ MockTurtle turtle;
+
+ Painter painter(&turtle);
+
+ QSignalSpy spy(&painter, SIGNAL(DrawCircleCalled(int,int,int)));
+
+ painter.DrawCircle(0, 0, 10);
+ ASSERT_EQ(1, spy.count());
+ QList<QVariant> expected = QList<QVariant>() << 0 << 0 << 10;
+ ASSERT_EQ(expected, spy.at(0));
+}
+
+int main(int argc, char *argv[])
+{
+ ::testing::InitGoogleMock(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+include(../ut_common.pri)
+
+TARGET = ut_gmocktest
+QT += testlib
+QT -= gui
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+OBJECTS_DIR = .obj
+MOC_DIR = .moc
+SOURCES += ut_gmocktest.cpp \
+ painter.cpp
+HEADERS += \
+ turtle.h \
+ mock_turtle.h \
+ painter.h
+
+include(../gmock.pri)
--- /dev/null
+Makefile
+ut_template
--- /dev/null
+#include "ut_template.h"
+#include <QtTest/QtTest>
+
+void Ut_template::initTestCase()
+{
+
+}
+
+void Ut_template::cleanupTestCase()
+{
+
+}
+
+void Ut_template::init()
+{
+
+}
+
+void Ut_template::cleanup()
+{
+
+}
+
+QTEST_MAIN(Ut_template)
--- /dev/null
+#ifndef UT_TEMPLATE_H
+#define UT_TEMPLATE_H
+
+#include <QObject>
+
+class Ut_template : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ // Will be called before the first testfunction is executed.
+ void initTestCase();
+ // Will be called after the last testfunction was executed.
+ void cleanupTestCase();
+ // Will be called before each testfunction is executed.
+ void init();
+ // Will be called after every testfunction.
+ void cleanup();
+
+};
+
+#endif // UT_TEMPLATE_H
--- /dev/null
+include(../ut_common.pri)
+
+TARGET = ut_template
+QT += testlib
+QT -= gui
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+OBJECTS_DIR = .obj
+MOC_DIR = .moc
+SOURCES += ut_template.cpp
+HEADERS += ut_template.h
--- /dev/null
+#ifndef STLHELPERS4QT_H
+#define STLHELPERS4QT_H
+
+#include <ostream>
+#include <QList>
+#include <QVariant>
+
+/**
+ * Outputs the contents of a QList<QVariant> container to a std::ostream object.
+ * @param stream the stream to output to
+ * @param val the container that is put to the stream
+ * @return the same stream that was passed as the parameter @a stream
+ */
+std::ostream& operator<<(std::ostream& stream, const QList<QVariant> &val)
+{
+ bool first = true;
+
+ foreach (const QVariant &v, val) {
+ if (!first) {
+ stream << ", ";
+ }
+ stream << v.toString().toStdString();
+ first = false;
+ }
+ return stream;
+}
+
+#endif // STLHELPERS4QT_H