--- /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
#ifndef PAINTER_H
#define PAINTER_H
+#include <QObject>
+
class Turtle;
-class Painter
+class Painter : public QObject
{
+ Q_OBJECT
+
Turtle *turtle;
public:
virtual ~Painter();
bool DrawCircle(int x, int y, int radius);
+
+signals:
+ void DrawCircleCalled(int x, int y, int radius);
};
#endif // PAINTER_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-using ::testing::AtLeast;
+#include <QSignalSpy>
+#include "../stlhelpers4qt.h"
+using ::testing::AtLeast;
TEST(PainterTest, TestTurtlePenDownCalledAtLeastOnceWhenDrawCircleCalled)
{
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);