aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt76
-rw-r--r--src/CMakeLists.txt61
-rw-r--r--tests/CMakeLists.txt50
-rw-r--r--tests/unit/adbd-client-test.cpp (renamed from tests/adbd-client-test.cpp)4
-rw-r--r--tests/unit/rotation-lock-test.cpp (renamed from tests/rotation-lock-test.cpp)2
-rw-r--r--tests/unit/usb-snap-test.cpp (renamed from tests/usb-snap-test.cpp)4
-rw-r--r--tests/utils/adbd-server.h (renamed from tests/adbd-server.h)0
-rw-r--r--tests/utils/dbus-types.h (renamed from tests/dbus-types.h)0
-rw-r--r--tests/utils/glib-fixture.h (renamed from tests/glib-fixture.h)0
-rw-r--r--tests/utils/qmain.cpp60
-rw-r--r--tests/utils/test-dbus-fixture.h (renamed from tests/test-dbus-fixture.h)0
11 files changed, 149 insertions, 108 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8b8ef65..5110c9e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,30 +1,31 @@
project(indicator-display LANGUAGES C CXX)
cmake_minimum_required(VERSION 2.8.9)
-list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
-set (PROJECT_VERSION "14.10.0")
-set (PACKAGE ${CMAKE_PROJECT_NAME})
-set (GETTEXT_PACKAGE indicator-display)
-add_definitions (-DGETTEXT_PACKAGE="${GETTEXT_PACKAGE}"
- -DGNOMELOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}")
+set(PACKAGE ${CMAKE_PROJECT_NAME})
+set(GETTEXT_PACKAGE indicator-display)
+add_definitions(
+ -DGETTEXT_PACKAGE="${GETTEXT_PACKAGE}"
+ -DGNOMELOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}"
+)
-set (SERVICE_LIB ${PACKAGE})
-set (SERVICE_EXEC "${PACKAGE}-service")
+set(SERVICE_LIB ${PACKAGE})
+set(SERVICE_EXEC "${PACKAGE}-service")
-option (enable_tests "Build the package's automatic tests." ON)
-option (enable_lcov "Generate lcov code coverage reports." ON)
+option(enable_tests "Build the package's automatic tests." ON)
+option(enable_lcov "Generate lcov code coverage reports." ON)
##
## GNU standard paths
##
-include (GNUInstallDirs)
-if (EXISTS "/etc/debian_version") # Workaround for libexecdir on debian
- set (CMAKE_INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBDIR}")
- set (CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
-endif ()
-set (CMAKE_INSTALL_PKGLIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
-set (CMAKE_INSTALL_FULL_PKGLIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
+include(GNUInstallDirs)
+if(EXISTS "/etc/debian_version") # Workaround for libexecdir on debian
+ set(CMAKE_INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBDIR}")
+ set(CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
+endif()
+set(CMAKE_INSTALL_PKGLIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
+set(CMAKE_INSTALL_FULL_PKGLIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}")
##
## Check for prerequisites
@@ -32,12 +33,15 @@ set (CMAKE_INSTALL_FULL_PKGLIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
-find_package (PkgConfig REQUIRED)
+find_package(PkgConfig REQUIRED)
-pkg_check_modules (SERVICE_DEPS REQUIRED
- gio-unix-2.0>=2.36
- glib-2.0>=2.36)
-include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS})
+pkg_check_modules(SERVICE_DEPS REQUIRED
+ gio-unix-2.0>=2.36
+ glib-2.0>=2.36
+)
+include_directories (SYSTEM
+ ${SERVICE_DEPS_INCLUDE_DIRS}
+)
##
##
@@ -47,24 +51,26 @@ set (CMAKE_INCLUDE_CURRENT_DIR OFF)
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
# set the compiler warnings
-if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- set (CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Weverything -Wno-c++98-compat -Wno-padded")
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ set(CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Weverything -Wno-c++98-compat -Wno-padded")
else()
- set (CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Wall -Wextra -Wpedantic")
+ set(CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Wall -Wextra -Wpedantic")
endif()
-set (CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Wno-missing-field-initializers") # GActionEntry
+set(CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Wno-missing-field-initializers") # GActionEntry
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -g")
# testing & coverage
-if (${enable_tests})
- enable_testing ()
- if (${enable_lcov})
+if(${enable_tests})
+ enable_testing()
+ if(${enable_lcov})
include(GCov)
- endif ()
-endif ()
+ endif()
+endif()
-add_subdirectory (src)
-add_subdirectory (data)
-add_subdirectory (po)
+add_subdirectory(src)
+add_subdirectory(data)
+add_subdirectory(po)
if (${enable_tests})
- add_subdirectory (tests)
+ add_subdirectory(tests)
endif ()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ff385d9..6cfda91 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,32 +1,33 @@
-set (SERVICE_LIB "indicatordisplayservice")
-set (SERVICE_EXEC "indicator-display-service")
-add_definitions (-DG_LOG_DOMAIN="${CMAKE_PROJECT_NAME}")
-
-# handwritten source code...
-set (SERVICE_LIB_HANDWRITTEN_SOURCES
- adbd-client.cpp
- exporter.cpp
- indicator.cpp
- rotation-lock.cpp
- usb-snap.cpp)
-
-add_library (${SERVICE_LIB} STATIC
- ${SERVICE_LIB_HANDWRITTEN_SOURCES})
-
-# add the bin dir to the include path so that
-# the compiler can find the generated header files
-include_directories (${CMAKE_CURRENT_BINARY_DIR})
-
-link_directories (${SERVICE_DEPS_LIBRARY_DIRS})
-
-set (SERVICE_EXEC_HANDWRITTEN_SOURCES main.cpp)
-add_executable (${SERVICE_EXEC} ${SERVICE_EXEC_HANDWRITTEN_SOURCES})
-target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} Threads::Threads ${GCOV_LIBS})
-install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR})
-
-# add warnings/coverage info on handwritten files
-# but not the generated ones...
-set_property (SOURCE ${SERVICE_LIB_HANDWRITTEN_SOURCES} ${SERVICE_EXEC_HANDWRITTEN_SOURCES}
- APPEND_STRING PROPERTY COMPILE_FLAGS " -std=c++11 -g ${CXX_WARNING_ARGS} ${GCOV_FLAGS}")
+add_definitions(-DG_LOG_DOMAIN="${CMAKE_PROJECT_NAME}")
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARNING_ARGS} ${GCOV_FLAGS}")
+
+add_library(
+ ${SERVICE_LIB}
+ STATIC
+ adbd-client.cpp
+ exporter.cpp
+ indicator.cpp
+ rotation-lock.cpp
+ usb-snap.cpp
+)
+
+add_executable(
+ ${SERVICE_EXEC}
+ main.cpp
+)
+
+target_link_libraries(${SERVICE_EXEC}
+ ${SERVICE_LIB}
+ ${SERVICE_DEPS_LIBRARIES}
+ Threads::Threads
+ ${GCOV_LIBS}
+)
+
+install(
+ TARGETS
+ ${SERVICE_EXEC}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}
+)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 1fbe407..205792e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,57 +1,31 @@
-
set(CMAKE_AUTOMOC ON)
-
find_package(GMock REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Test REQUIRED)
find_package(Qt5DBus COMPONENTS Qt5DBusMacros REQUIRED)
pkg_check_modules(TEST_DEPS
- libqtdbustest-1 REQUIRED
- libqtdbusmock-1 REQUIRED
+ libqtdbustest-1 REQUIRED
+ libqtdbusmock-1 REQUIRED
)
-include_directories(
- ${CMAKE_SOURCE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}
-)
include_directories(SYSTEM
- ${DBUSTEST_INCLUDE_DIRS}
- ${TEST_DEPS_INCLUDE_DIRS}
- ${GTEST_INCLUDE_DIRS}
- ${GMOCK_INCLUDE_DIRS}
+ ${DBUSTEST_INCLUDE_DIRS}
+ ${TEST_DEPS_INCLUDE_DIRS}
+ ${GTEST_INCLUDE_DIRS}
+ ${GMOCK_INCLUDE_DIRS}
)
set(CTEST_ENVIRONMENT "${CTEST_ENVIRONMENT};G_MESSAGES_DEBUG=all")
-if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- # turn off the warnings that break Google Test
- set (CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Wno-global-constructors -Wno-weak-vtables")
+# turn off the warnings that break Google Test
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ set(CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Wno-global-constructors -Wno-weak-vtables")
endif()
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11 -g ${CXX_WARNING_ARGS}")
-
-function(add_test_by_name name)
- set (TEST_NAME ${name})
- add_executable (${TEST_NAME} ${TEST_NAME}.cpp)
- add_test (${TEST_NAME} ${TEST_NAME})
- set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT "${CTEST_ENVIRONMENT}")
- add_dependencies (${TEST_NAME} indicatordisplayservice)
- target_link_libraries (${TEST_NAME} indicatordisplayservice ${SERVICE_DEPS_LIBRARIES} ${TEST_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES})
-endfunction()
-add_test_by_name(rotation-lock-test)
-add_test_by_name(adbd-client-test)
-
-function(add_qt_test_by_name name)
- set (TEST_NAME ${name})
- add_executable (${TEST_NAME} ${TEST_NAME}.cpp qmain.cpp)
- add_test (${TEST_NAME} ${TEST_NAME})
- set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT "${CTEST_ENVIRONMENT}")
- add_dependencies (${TEST_NAME} indicatordisplayservice)
- target_link_libraries (${TEST_NAME} indicatordisplayservice ${SERVICE_DEPS_LIBRARIES} Qt5::Core Qt5::Test Qt5::DBus ${TEST_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES})
-endfunction()
-add_qt_test_by_name(usb-snap-test)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARNING_ARGS}")
add_test(cppcheck cppcheck --enable=all -USCHEMA_DIR --error-exitcode=2 --inline-suppr -I${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests)
+add_subdirectory(unit)
+add_subdirectory(utils)
diff --git a/tests/adbd-client-test.cpp b/tests/unit/adbd-client-test.cpp
index ae0378b..1e28cc9 100644
--- a/tests/adbd-client-test.cpp
+++ b/tests/unit/adbd-client-test.cpp
@@ -17,8 +17,8 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#include <tests/test-dbus-fixture.h>
-#include <tests/adbd-server.h>
+#include <tests/utils/test-dbus-fixture.h>
+#include <tests/utils/adbd-server.h>
#include <src/adbd-client.h>
diff --git a/tests/rotation-lock-test.cpp b/tests/unit/rotation-lock-test.cpp
index b8661cc..b9630b5 100644
--- a/tests/rotation-lock-test.cpp
+++ b/tests/unit/rotation-lock-test.cpp
@@ -17,7 +17,7 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#include "test-dbus-fixture.h"
+#include <tests/utils/test-dbus-fixture.h>
#include <src/rotation-lock.h>
diff --git a/tests/usb-snap-test.cpp b/tests/unit/usb-snap-test.cpp
index 309980a..70c9d97 100644
--- a/tests/usb-snap-test.cpp
+++ b/tests/unit/usb-snap-test.cpp
@@ -18,8 +18,8 @@
*/
#define QT_NO_KEYWORDS
-#include <tests/dbus-types.h>
-#include <tests/glib-fixture.h>
+#include <tests/utils/dbus-types.h>
+#include <tests/utils/glib-fixture.h>
#include <src/usb-snap.h>
diff --git a/tests/adbd-server.h b/tests/utils/adbd-server.h
index 740faaa..740faaa 100644
--- a/tests/adbd-server.h
+++ b/tests/utils/adbd-server.h
diff --git a/tests/dbus-types.h b/tests/utils/dbus-types.h
index c2dfb81..c2dfb81 100644
--- a/tests/dbus-types.h
+++ b/tests/utils/dbus-types.h
diff --git a/tests/glib-fixture.h b/tests/utils/glib-fixture.h
index ccdeccd..ccdeccd 100644
--- a/tests/glib-fixture.h
+++ b/tests/utils/glib-fixture.h
diff --git a/tests/utils/qmain.cpp b/tests/utils/qmain.cpp
new file mode 100644
index 0000000..72a49b1
--- /dev/null
+++ b/tests/utils/qmain.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Pete Woods <pete.woods@canonical.com>
+ */
+
+//#include <config.h>
+
+#include <QCoreApplication>
+#include <QTimer>
+#include <gtest/gtest.h>
+
+#include <libqtdbusmock/DBusMock.h>
+
+using namespace QtDBusMock;
+
+class Runner: public QObject
+{
+ Q_OBJECT
+public Q_SLOTS:
+ void run()
+ {
+ QCoreApplication::exit(RUN_ALL_TESTS());
+ }
+};
+
+int main(int argc, char **argv)
+{
+ qputenv("LANG", "C.UTF-8");
+ unsetenv("LC_ALL");
+
+ // boilerplate i18n
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ textdomain(GETTEXT_PACKAGE);
+
+ QCoreApplication application(argc, argv);
+ DBusMock::registerMetaTypes();
+ ::testing::InitGoogleTest(&argc, argv);
+
+ Runner runner;
+ QTimer::singleShot(0, &runner, SLOT(run()));
+
+ return application.exec();
+}
+
+#include "qmain.moc"
diff --git a/tests/test-dbus-fixture.h b/tests/utils/test-dbus-fixture.h
index 3947e58..3947e58 100644
--- a/tests/test-dbus-fixture.h
+++ b/tests/utils/test-dbus-fixture.h