[Libreoffice-commits] cppunit.git: Branch 'feature/cmake' - 2 commits - CMakeLists.txt cmake/SelectQtVersion.cmake examples/qt include/CMakeLists.txt src/CMakeLists.txt src/qttestrunner
Bernhard Sessler
bernhard at burnsen.de
Mon Jan 6 08:36:54 PST 2014
CMakeLists.txt | 12 +++++-
cmake/SelectQtVersion.cmake | 43 +++++++++++++++++++++++++
examples/qt/ExampleTestCases.cpp | 48 +++++++++++++--------------
examples/qt/ExampleTestCases.h | 32 ++++++++----------
examples/qt/Main.cpp | 18 ++++------
examples/qt/qt_example.pro | 67 +++++++++++----------------------------
include/CMakeLists.txt | 12 ++++++
src/CMakeLists.txt | 4 ++
src/qttestrunner/CMakeLists.txt | 43 +++++++++++++++++++++++++
9 files changed, 175 insertions(+), 104 deletions(-)
New commits:
commit f9374cf4589f8128be6962238bbcaff4e16720cb
Author: Bernhard Sessler <bernhard at burnsen.de>
Date: Sun Dec 22 15:16:50 2013 +0100
src/qttestrunner: Add CMake build system
This will allow building the qt test runner by using the CMake build
system. The new CMake option 'CPPUNIT_BUILD_QT_TESTRUNNER' (OFF by
default) can be used to build the test runner (switch these options
ON and OFF by running the CMake built-in 'edit_cache' build target,
e.g. using Linux / GNU make this would be 'make edit_cache', NMake
based build systems would run 'nmake edit_cache').
Change-Id: Ifead1e2cd9162c74b8a212daf93f4bbad9f6c1f3
Signed-off-by: Bernhard Sessler <bernhard at burnsen.de>
Reviewed-on: https://gerrit.libreoffice.org/7184
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 97baafe..0427289 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,9 @@ cmake_minimum_required(VERSION 2.8.7)
# Add project specific CMake module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# Perform platform and compiler feature checks
include(PlatformChecks)
@@ -12,13 +15,18 @@ include(PlatformChecks)
include(Versioning)
# Build options
-option(BUILD_SHARED_LIBS "Build cppunit as shared or static library" ON)
-option(CPPUNIT_BUILD_APIDOC "Adds a build target for generating the API documentation" OFF)
+option(BUILD_SHARED_LIBS "Build cppunit as shared or static library" ON)
+option(CPPUNIT_BUILD_APIDOC "Adds a build target for generating the API documentation" OFF)
+option(CPPUNIT_BUILD_QT_TESTRUNNER "Build the Qt test runner library" OFF)
if(BUILD_SHARED_LIBS AND WIN32)
add_definitions(-DCPPUNIT_BUILD_DLL)
endif()
+if(CPPUNIT_BUILD_QT_TESTRUNNER)
+ include(SelectQtVersion)
+endif()
+
# Include paths
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
diff --git a/cmake/SelectQtVersion.cmake b/cmake/SelectQtVersion.cmake
new file mode 100644
index 0000000..4cfb4d5
--- /dev/null
+++ b/cmake/SelectQtVersion.cmake
@@ -0,0 +1,43 @@
+##
+# Projectname - Redmine:Administration
+# Author - Bernhard Sessler <bernhard.sessler at corscience.de>
+# Description - Depending on the variable WITH_QT5 search either for Qt5 or Qt4 libs
+#
+# (c) 2013, Corscience GmbH & Co. KG
+##
+
+if(NOT WITH_QT)
+ set(WITH_QT 5)
+endif()
+
+# Find Qt5
+if(WITH_QT EQUAL 5)
+ set(QT5_REQUIRED_MODULES Widgets)
+
+ find_package(Qt5 REQUIRED COMPONENTS ${QT5_REQUIRED_MODULES})
+
+ foreach(_submodule ${QT5_REQUIRED_MODULES})
+ include_directories(${Qt5${_submodule}_INCLUDE_DIRS})
+ list(APPEND QT_LIBRARIES ${Qt5${_submodule}_LIBRARIES})
+ endforeach()
+
+ set(QT_LIBRARIES_FOUND ${Qt5Widgets_FOUND})
+
+# Find Qt4
+elseif(WITH_QT EQUAL 4)
+ set(QT4_REQUIRED_MODULES QtCore QtGui)
+
+ find_package(Qt4 REQUIRED COMPONENTS ${QT4_REQUIRED_MODULES})
+ include(${QT_USE_FILE})
+
+ foreach(_submodule ${QT4_REQUIRED_MODULES})
+ string(TOUPPER _submodule _var)
+ list(APPEND QT_LIBRARIES ${QT_${_var}_LIBRARY})
+ endforeach()
+
+ set(QT_LIBRARIES_FOUND ${QT_QTGUI_FOUND})
+
+# Unsupported version
+else()
+ message(SEND_ERROR "Unsupported Qt version specified. Set WITH_QT to either 4 or 5")
+endif()
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 142eeda..4e30800 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -2,4 +2,14 @@
configure_file(config-auto.h.in "${CMAKE_CURRENT_BINARY_DIR}/cppunit/config-auto.h")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cppunit/config-auto.h" DESTINATION include/cppunit)
-install(DIRECTORY cppunit DESTINATION include FILES_MATCHING PATTERN "*.h")
+install(DIRECTORY cppunit
+ DESTINATION include
+ FILES_MATCHING PATTERN "*.h"
+ PATTERN "ui/qt" EXCLUDE
+ PATTERN "ui/mfc" EXCLUDE)
+
+if(CPPUNIT_BUILD_QT_TESTRUNNER)
+ install(DIRECTORY cppunit/ui/qt
+ DESTINATION include/cppunit/ui
+ FILES_MATCHING PATTERN "*.h")
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4a72b2e..cc89dcb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1 +1,5 @@
add_subdirectory(cppunit)
+
+if(CPPUNIT_BUILD_QT_TESTRUNNER)
+ add_subdirectory(qttestrunner)
+endif()
diff --git a/src/qttestrunner/CMakeLists.txt b/src/qttestrunner/CMakeLists.txt
new file mode 100644
index 0000000..a3a0a16
--- /dev/null
+++ b/src/qttestrunner/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Include the current binary dir, so files produced by moc can be found
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+# Common source files
+set(qttestrunner_SOURCES
+ QtTestFailure.cpp
+ QtTestListener.cpp
+ QtTestRunner.cpp
+ TestBrowser.cpp
+ TestFailureTableModel.cpp
+ TestRunnerThread.cpp
+ TestRunnerWindow.cpp
+ TestRunnerWindowPrivate.cpp
+)
+
+set(qttestrunner_FORMS
+ TestRunnerWindow.ui
+ TestBrowser.ui
+)
+
+if(WITH_QT EQUAL 4)
+ qt4_wrap_ui(qttestrunner_UI_MOC ${qttestrunner_FORMS})
+elseif(WITH_QT EQUAL 5)
+ qt5_wrap_ui(qttestrunner_UI_MOC ${qttestrunner_FORMS})
+endif()
+
+# Create the test runner executable
+add_library(cppunit-qttestrunner ${qttestrunner_SOURCES} ${qttestrunner_UI_MOC})
+target_link_libraries(cppunit-qttestrunner cppunit ${QT_LIBRARIES})
+set_target_properties(cppunit-qttestrunner PROPERTIES
+ AUTOMOC ON
+ VERSION ${CPPUNIT_SOVERSION_MAJOR}.${CPPUNIT_SOVERSION_MINOR}.${CPPUNIT_SOVERSION_PATCH}
+ SOVERSION ${CPPUNIT_SOVERSION_MAJOR})
+
+if(WIN32)
+ set_target_properties(cppunit-qttestrunner DEBUG_POSTFIX "d")
+endif()
+
+# Create install target
+install(TARGETS cppunit-qttestrunner
+ LIBRARY DESTINATION lib COMPONENT testrunners
+ ARCHIVE DESTINATION lib COMPONENT testrunners
+ RUNTIME DESTINATION bin COMPONENT testrunners)
commit 6004a179ff2dae204df2f20e4dc5b0d92b36a1cf
Author: Bernhard Sessler <bernhard at burnsen.de>
Date: Sun Dec 22 15:13:54 2013 +0100
examples: Port qt test runner example to Qt4 / Qt5
Change-Id: Ide48092bc7205581d03ec31d31d6d071d4ccc3d5
Signed-off-by: Bernhard Sessler <bernhard at burnsen.de>
Reviewed-on: https://gerrit.libreoffice.org/7183
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/examples/qt/ExampleTestCases.cpp b/examples/qt/ExampleTestCases.cpp
index edd67b0..891f12c 100644
--- a/examples/qt/ExampleTestCases.cpp
+++ b/examples/qt/ExampleTestCases.cpp
@@ -1,41 +1,41 @@
#include "ExampleTestCases.h"
-CPPUNIT_TEST_SUITE_REGISTRATION( ExampleTestCases );
+CPPUNIT_TEST_SUITE_REGISTRATION(ExampleTestCases);
-void ExampleTestCases::example ()
+void ExampleTestCases::example()
{
- CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, 1.1, 0.05);
- CPPUNIT_ASSERT (1 == 0);
- CPPUNIT_ASSERT (1 == 1);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, 1.1, 0.05);
+ CPPUNIT_ASSERT(1 == 0);
+ CPPUNIT_ASSERT(1 == 1);
}
-void ExampleTestCases::anotherExample ()
+void ExampleTestCases::anotherExample()
{
- CPPUNIT_ASSERT (1 == 2);
+ CPPUNIT_ASSERT(1 == 2);
}
-void ExampleTestCases::setUp ()
+void ExampleTestCases::setUp()
{
- m_value1 = 2.0;
- m_value2 = 3.0;
+ m_value1 = 2.0;
+ m_value2 = 3.0;
}
-void ExampleTestCases::testAdd ()
+void ExampleTestCases::testAdd()
{
- double result = m_value1 + m_value2;
- CPPUNIT_ASSERT (result == 6.0);
+ double result = m_value1 + m_value2;
+ CPPUNIT_ASSERT(result == 6.0);
}
-void ExampleTestCases::testEquals ()
+void ExampleTestCases::testEquals()
{
- std::auto_ptr<long> l1 (new long (12));
- std::auto_ptr<long> l2 (new long (12));
-
- CPPUNIT_ASSERT_EQUAL (12, 12);
- CPPUNIT_ASSERT_EQUAL (12L, 12L);
- CPPUNIT_ASSERT_EQUAL (*l1, *l2);
-
- CPPUNIT_ASSERT (12L == 12L);
- CPPUNIT_ASSERT_EQUAL (12, 13);
- CPPUNIT_ASSERT_DOUBLES_EQUAL (12.0, 11.99, 0.5);
+ std::auto_ptr<long> l1(new long(12));
+ std::auto_ptr<long> l2(new long(12));
+
+ CPPUNIT_ASSERT_EQUAL(12, 12);
+ CPPUNIT_ASSERT_EQUAL(12L, 12L);
+ CPPUNIT_ASSERT_EQUAL(*l1, *l2);
+
+ CPPUNIT_ASSERT(12L == 12L);
+ CPPUNIT_ASSERT_EQUAL(12, 13);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(12.0, 11.99, 0.5);
}
diff --git a/examples/qt/ExampleTestCases.h b/examples/qt/ExampleTestCases.h
index 4c40b8e..1aba838 100644
--- a/examples/qt/ExampleTestCases.h
+++ b/examples/qt/ExampleTestCases.h
@@ -4,35 +4,31 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
-/*
+/*
* A test case that is designed to produce
* example errors and failures.
- *
*/
-
class ExampleTestCases : public CPPUNIT_NS::TestFixture
{
- CPPUNIT_TEST_SUITE( ExampleTestCases );
- CPPUNIT_TEST( example );
- CPPUNIT_TEST( anotherExample );
- CPPUNIT_TEST( testAdd );
- CPPUNIT_TEST( testEquals );
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(ExampleTestCases);
+ CPPUNIT_TEST(example);
+ CPPUNIT_TEST(anotherExample);
+ CPPUNIT_TEST(testAdd);
+ CPPUNIT_TEST(testEquals);
+ CPPUNIT_TEST_SUITE_END();
protected:
+ double m_value1;
+ double m_value2;
- double m_value1;
- double m_value2;
public:
-
- void setUp ();
+ void setUp();
protected:
-
- void example ();
- void anotherExample ();
- void testAdd ();
- void testEquals ();
+ void example();
+ void anotherExample();
+ void testAdd();
+ void testEquals();
};
#endif
diff --git a/examples/qt/Main.cpp b/examples/qt/Main.cpp
index e650040..450acc4 100644
--- a/examples/qt/Main.cpp
+++ b/examples/qt/Main.cpp
@@ -1,19 +1,15 @@
-#include <qapplication.h>
+#include <QApplication>
+
#include <cppunit/ui/qt/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-
int main( int argc, char** argv )
{
- QApplication app( argc, argv );
+ QApplication app(argc, argv);
- //CPPUNIT_NS::QtUi::TestRunner runner;
-
- CPPUNIT_NS::QtTestRunner runner;
-
- runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
- runner.run( true );
+ CPPUNIT_NS::QtTestRunner runner;
+ runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
+ runner.run(true);
- return 0;
+ return app.exec();
}
-
diff --git a/examples/qt/qt_example.pro b/examples/qt/qt_example.pro
index c93f76e..7f5994f 100644
--- a/examples/qt/qt_example.pro
+++ b/examples/qt/qt_example.pro
@@ -1,68 +1,49 @@
#----------------------------------------------------------------------
# File: qt_example.pro
# Purpose: qmake config file for the QtTestRunner example.
-# The program is built with the QtTestRunner debug staticlib.
+# The program is built with the QtTestRunner shared library in
+# both debug and release configs.
# Set the CONFIG variable accordingly to build it differently.
#----------------------------------------------------------------------
-TEMPLATE = app
-LANGUAGE = C++
-TARGET = qt_example
-
-# Get rid of possibly predefined options
-
-CONFIG -= debug
-CONFIG -= release
+QT += core gui
-CONFIG += qt warn_on debug use_static
-
-#CONFIG += qt warn_on release use_static
-#CONFIG += qt warn_on debug use_dll
-#CONFIG += qt warn_on release use_dll
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+TARGET = qt_example
+TEMPLATE = app
-CPPUNIT_LIB_DIR = ../../lib # Location of libraries
+CONFIG += use_dll
+#CONFIG += use_static
+CONFIG += warn_on
#----------------------------------------------------------------------
# MS Windows
#----------------------------------------------------------------------
win32 {
- # Suppress program database creation (should better be done
- # in the qmake spec file)
- QMAKE_CXXFLAGS_DEBUG += /Z7
- QMAKE_CXXFLAGS_DEBUG -= -Gm
- QMAKE_CXXFLAGS_DEBUG -= -Zi
-}
-
-win32 {
use_dll {
DEFINES += QTTESTRUNNER_DLL
debug {
- OBJECTS_DIR = DebugDLL
- LIBS += $${CPPUNIT_LIB_DIR}\cppunitd_dll.lib
- LIBS += $${CPPUNIT_LIB_DIR}\qttestrunnerd_dll.lib
+ LIBS += cppunitd_dll.lib
+ LIBS += cppunit-qttestrunnerd_dll.lib
}
release {
- OBJECTS_DIR = ReleaseDLL
- LIBS += $${CPPUNIT_LIB_DIR}\cppunit_dll.lib
- LIBS += $${CPPUNIT_LIB_DIR}\qttestrunner_dll.lib
+ LIBS += cppunit_dll.lib
+ LIBS += cppunit-qttestrunner_dll.lib
}
}
use_static {
debug {
- OBJECTS_DIR = Debug
- LIBS += $${CPPUNIT_LIB_DIR}\cppunitd.lib
- LIBS += $${CPPUNIT_LIB_DIR}\qttestrunnerd.lib
+ LIBS += cppunitd.lib
+ LIBS += cppunit-qttestrunnerd.lib
}
release {
- OBJECTS_DIR = Release
- LIBS += $${CPPUNIT_LIB_DIR}\cppunit.lib
- LIBS += $${CPPUNIT_LIB_DIR}\qttestrunner.lib
+ LIBS += cppunit.lib
+ LIBS += cppunit-qttestrunner.lib
}
}
- DESTDIR = $${OBJECTS_DIR}
}
#----------------------------------------------------------------------
@@ -70,18 +51,8 @@ win32 {
#----------------------------------------------------------------------
unix {
- debug {
- OBJECTS_DIR = .obj_debug
- use_static: LIBS += -L$${CPPUNIT_LIB_DIR} -lqttestrunnerd
- use_dll: LIBS += -L$${CPPUNIT_LIB_DIR} -lqttestrunnerd_shared
- LIBS += -L$${CPPUNIT_LIB_DIR} -lcppunit
- }
- release {
- OBJECTS_DIR = .obj_release
- use_static: LIBS += -L$${CPPUNIT_LIB_DIR} -lqttestrunner
- use_dll: LIBS += -L$${CPPUNIT_LIB_DIR} -lqttestrunner_shared
- LIBS += -L$${CPPUNIT_LIB_DIR} -lcppunit
- }
+ LIBS += -lcppunit-qttestrunner
+ LIBS += -lcppunit
}
#----------------------------------------------------------------------
More information about the Libreoffice-commits
mailing list