Permalink
Browse files

added unit test infrastructure with google c++ mocking framework

  • Loading branch information...
1 parent fa98a56 commit a457565c9dc4016fdd36ea5f0ce07d408579ca88 @vapolyakov vapolyakov committed Jul 28, 2012
View
@@ -35,3 +35,15 @@ plugins.depends = \
qrkernel \
qrmc \
+UNIT_TEST = TRUE
+!isEmpty(UNIT_TEST) {
+ SUBDIRS += qrtest
+
+ qrtest.depends = \
+ qrxc \
+ qrrepo \
+ qrutils \
+ qrkernel \
+ qrmc \
+ qrgui \
+}
View
@@ -0,0 +1,48 @@
+contains(QT_VERSION, ^4\\.[0-5]\\..*){
+ message("Cannot build qreal using Qt version $${QT_VERSION}")
+ error("Use at least Qt 4.6")
+}
+
+TEMPLATE = subdirs
+SUBDIRS = \
+# doc \
+ qrmc \
+ qrxc \
+ qrgui \
+ qrrepo \
+ plugins \
+ qrkernel \
+ qrutils \
+ qrtest \
+
+qrutils.depends = qrkernel
+qrrepo.depends = qrkernel qrutils
+qrxc.depends = qrutils
+qrmc.depends = qrrepo
+qrmc.file = qrmc/qrmc-lib.pro
+
+qrgui.file = qrgui/qrguiTest.pro
+qrxc.file = qrxc/qrxcTest.pro
+
+qrgui.depends = \
+# doc \
+ qrxc \
+ qrrepo \
+ qrutils \
+ qrkernel \
+ qrmc \
+
+plugins.depends = \
+ qrxc \
+ qrrepo \
+ qrutils \
+ qrkernel \
+ qrmc \
+
+qrtest.depends = \
+ qrxc \
+ qrrepo \
+ qrutils \
+ qrkernel \
+ qrmc \
+ qrgui \
View
@@ -0,0 +1 @@
+include (qrealTest.pri)
View
@@ -1,13 +1,19 @@
#include "mainwindow/mainWindow.h"
#include "thirdparty/windowsmodernstyle.h"
+#ifdef UNITTEST
+ #include "gtest/gtest.h"
+#endif
+
#include <QtCore/QtPlugin>
#include <QtGui/QApplication>
using namespace qReal;
int main(int argc, char *argv[])
{
+#ifndef UNITTEST
+
QApplication app(argc, argv);
QTranslator appTranslator;
@@ -25,4 +31,8 @@ int main(int argc, char *argv[])
return app.exec();
else // The window decided to not show itself, exiting now.
return 0;
+#else
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+#endif
}
View
@@ -34,6 +34,22 @@ LIBS += -L../bin -lqrrepo -lqrkernel -lqrutils #-lqrmc
unix:DEFINES = _TTY_POSIX_
win32:DEFINES = _TTY_WIN_
+UNIT_TEST = TRUE
+!isEmpty(UNIT_TEST) {
+ OBJECTS_DIR = .unittestobj
+ UI_DIR = .unittestui
+ MOC_DIR = .unittestmoc
+ RCC_DIR = .unittestmoc
+
+ INCLUDEPATH += ../thirdparty/gmock-1.6.0/include
+ INCLUDEPATH += ../thirdparty/gmock-1.6.0/gtest/include
+ LIBS += -L../thirdparty/ -lgmock_main -lpthread
+
+ TARGET = qrgui_unittests
+ DESTDIR = ../bin/unittests
+ DEFINES += UNITTEST
+}
+
# Graphical elements
include (umllib/umllib.pri)
@@ -67,3 +83,6 @@ include (toolPluginInterface/toolPluginInterface.pri)
# Text Editor
include (textEditor/textEditor.pri)
+
+# Unit tests for qrgui code
+include (unitTests/unitTests.pri)
View
@@ -0,0 +1,80 @@
+DESTDIR = ../bin
+
+QT += svg xml
+CONFIG += rpath_libdirs help
+macx {
+ CONFIG -= app_bundle
+}
+
+RESOURCES = qrgui.qrc
+SOURCES = main.cpp
+
+TRANSLATIONS = qrgui_ru.ts
+
+# QMAKE_CXXFLAGS_DEBUG += -pg
+# QMAKE_LFLAGS_DEBUG += -pg
+
+# workaround для http://bugreports.qt.nokia.com/browse/QTBUG-8110
+# как только поправят, можно будет юзать QMAKE_LFLAGS_RPATH
+!macx {
+ QMAKE_LFLAGS="-Wl,-O1,-rpath,$(PWD)/../bin/"
+}
+
+if (equals(QMAKE_CXX, "g++") : !macx) {
+ QMAKE_LFLAGS += -Wl,-E
+}
+
+LIBS += -L../bin -lqrrepo -lqrkernel -lqrutils #-lqrmc
+
+unix:DEFINES = _TTY_POSIX_
+win32:DEFINES = _TTY_WIN_
+
+OBJECTS_DIR = .unittestobj
+UI_DIR = .unittestui
+MOC_DIR = .unittestmoc
+RCC_DIR = .unittestmoc
+
+INCLUDEPATH += ../thirdparty/gmock-1.6.0/include
+INCLUDEPATH += ../thirdparty/gmock-1.6.0/gtest/include
+LIBS += -L../thirdparty/ -lgmock_main -lpthread
+
+TARGET = qrgui_unittests
+DESTDIR = ../bin/unittests
+DEFINES += UNITTEST
+
+
+# Graphical elements
+include (umllib/umllib.pri)
+
+# Dialogs
+include (dialogs/dialogs.pri)
+
+# Main window
+include (mainwindow/mainwindow.pri)
+
+# View
+include (view/view.pri)
+
+# "Встроенные" генераторы
+include (generators/generators.pri)
+
+# Код, скачанный из интернета.
+include (thirdparty/thirdparty.pri)
+
+# Управление плагинами. Plugin managment
+include (pluginManager/pluginManager.pri)
+
+# Graphical and logical models
+include (models/models.pri)
+
+# Interfaces for plugins, used by qrxc and qrmc.
+include (editorPluginInterface/editorPluginInterface.pri)
+
+# Interfaces for tool plugins, used in handcoded tools.
+include (toolPluginInterface/toolPluginInterface.pri)
+
+# Text Editor
+include (textEditor/textEditor.pri)
+
+# Unit tests for qrgui code
+include (unitTests/unitTests.pri)
No changes.
@@ -0,0 +1,12 @@
+#include "mockedTestClass.h"
+
+#include "gtest/gtest.h"
+
+using ::testing::AtLeast;
+
+TEST(MockTest, testMethodTest) {
+ MockedTestClass testObject;
+ EXPECT_CALL(testObject, testMethod()).Times(AtLeast(1));
+
+ testObject.testMethod();
+}
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "testClass.h"
+#include "gmock/gmock.h"
+
+class MockedTestClass : public TestClass {
+public:
+ MOCK_METHOD0(testMethod, void());
+};
@@ -0,0 +1,21 @@
+#include "sampleFixtureTest.h"
+
+void BlockParserTest::SetUp() {
+ blockParser = new qReal::BlockParser(NULL);
+}
+
+void BlockParserTest::TearDown() {
+ delete blockParser;
+}
+
+TEST_F(BlockParserTest, expression) {
+ QString const stream = "(2+3)*5";
+ int pos = 0;
+ EXPECT_EQ(25, blockParser->parseExpression(stream, pos).property("Number").toInt());
+}
+
+TEST_F(BlockParserTest, condition) {
+ QString const stream = "2 + 3 < 5 * 5";
+ int pos = 0;
+ ASSERT_TRUE(blockParser->parseConditionHelper(stream, pos));
+}
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "../plugins/blockDiagram/visualDebugSupport/interpreter/blockParser.h"
+#include "gtest/gtest.h"
+
+class BlockParserTest : public testing::Test {
+
+protected:
+ virtual void SetUp();
+
+ virtual void TearDown();
+
+ qReal::BlockParser *blockParser;
+};
@@ -0,0 +1,20 @@
+#include "../qrutils/expressionsParser/number.h"
+#include "../plugins/blockDiagram/visualDebugSupport/interpreter/blockParser.h"
+
+#include "gtest/gtest.h"
+
+using namespace utils;
+
+TEST(NumberTest, sum) {
+ Number n1(2, Number::intType);
+ Number n2(3, Number::intType);
+ n1 += n2;
+ EXPECT_EQ(5, n1.property("Number").toInt());
+}
+
+TEST(ParserTest, expressionCalculation) {
+ qReal::BlockParser *parser = new qReal::BlockParser(NULL);
+ QString const stream = "1+1";
+ int pos = 0;
+ EXPECT_EQ(2, parser->parseExpression(stream, pos).property("Number").toInt());
+}
@@ -0,0 +1,7 @@
+#pragma once
+
+class TestClass {
+public:
+ virtual ~TestClass() {}
+ virtual void testMethod() {}
+};
View
@@ -0,0 +1,29 @@
+DESTDIR = ../bin/unittests
+TARGET = qrlibs_unittests
+
+!macx {
+ QMAKE_LFLAGS += -Wl,-rpath,$(PWD)/../bin
+ QMAKE_LFLAGS += -Wl,-rpath,$(PWD)/../bin/plugins
+}
+
+OBJECTS_DIR = .obj
+UI_DIR = .ui
+MOC_DIR = .moc
+RCC_DIR = .moc
+
+INCLUDEPATH += ../thirdparty/gmock-1.6.0/include
+INCLUDEPATH += ../thirdparty/gmock-1.6.0/gtest/include
+
+LIBS += -L../bin/ -lqrkernel -lqrutils -lqrmc -lqrrepo
+LIBS += -L../bin/plugins/ -lvisualDebugSupport
+LIBS += -L../thirdparty/ -lgmock_main -lpthread
+
+HEADERS += \
+ exampleTests/sampleFixtureTest.h \
+ exampleTests/testClass.h \
+ exampleTests/mockedTestClass.h \
+
+SOURCES += \
+ exampleTests/sampleTest.cpp \
+ exampleTests/sampleFixtureTest.cpp \
+ exampleTests/mockTest.cpp \
View
@@ -1,5 +1,10 @@
#include "xmlCompiler.h"
+#ifdef UNITTEST
+ #include "gtest/gtest.h"
+#endif
+
+
#include <QCoreApplication>
#include <QStringList>
#include <QDebug>
@@ -24,6 +29,7 @@ void myMessageOutput(QtMsgType type, const char *msg)
int main(int argc, char *argv[])
{
+#ifndef UNITTEST
qInstallMsgHandler(myMessageOutput);
QCoreApplication app(argc, argv);
QStringList args = app.arguments();
@@ -43,4 +49,9 @@ int main(int argc, char *argv[])
return 1;
return 0;
+
+#else
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+#endif
}
View
@@ -17,6 +17,20 @@ DESTDIR += ../bin
QMAKE_LFLAGS="-Wl,-O1,-rpath,$(PWD)/../bin"
}
+UNIT_TEST = TRUE
+!isEmpty(UNIT_TEST) {
+ OBJECTS_DIR = .unittestobj
+ MOC_DIR = .unittestmoc
+
+ INCLUDEPATH += ../thirdparty/gmock-1.6.0/include
+ INCLUDEPATH += ../thirdparty/gmock-1.6.0/gtest/include
+ LIBS += -L../thirdparty/ -lgmock_main -lpthread
+
+ TARGET = qrxc_unittests
+ DESTDIR = ../bin/unittests
+ DEFINES += UNITTEST
+}
+
HEADERS += association.h \
diagram.h \
edgeType.h \
@@ -61,3 +75,6 @@ SOURCES += association.cpp \
type.cpp \
xmlCompiler.cpp \
scalableItem.cpp
+
+# Unit tests for qrgxc code
+include (unitTests/unitTests.pri)
Oops, something went wrong.

0 comments on commit a457565

Please sign in to comment.