Commit c457fbad authored by Ronan Abhamon's avatar Ronan Abhamon

feat(App): provide a way to run tests (in progress)

parent ea5e3849
...@@ -23,8 +23,14 @@ ...@@ -23,8 +23,14 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1)
project(linphoneqt VERSION 4.0) project(linphoneqt VERSION 4.0)
set(APP_LIBRARY app-library)
set(EXECUTABLE_NAME linphone) set(EXECUTABLE_NAME linphone)
set(TESTER_EXECUTABLE_NAME "${EXECUTABLE_NAME}-tester")
set(TARGET_NAME linphone-qt) set(TARGET_NAME linphone-qt)
set(TESTER_TARGET_NAME "${TARGET_NAME}-tester")
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(ASSETS_DIR assets) set(ASSETS_DIR assets)
...@@ -98,6 +104,7 @@ endif () ...@@ -98,6 +104,7 @@ endif ()
set(SOURCES set(SOURCES
src/app/App.cpp src/app/App.cpp
src/app/AppController.cpp
src/app/cli/Cli.cpp src/app/cli/Cli.cpp
src/app/logger/Logger.cpp src/app/logger/Logger.cpp
src/app/paths/Paths.cpp src/app/paths/Paths.cpp
...@@ -144,7 +151,6 @@ set(SOURCES ...@@ -144,7 +151,6 @@ set(SOURCES
src/components/telephone-numbers/TelephoneNumbersModel.cpp src/components/telephone-numbers/TelephoneNumbersModel.cpp
src/components/timeline/TimelineModel.cpp src/components/timeline/TimelineModel.cpp
src/components/url-handlers/UrlHandlers.cpp src/components/url-handlers/UrlHandlers.cpp
src/main.cpp
src/utils/LinphoneUtils.cpp src/utils/LinphoneUtils.cpp
src/utils/Utils.cpp src/utils/Utils.cpp
src/utils/QExifImageHeader.cpp src/utils/QExifImageHeader.cpp
...@@ -152,6 +158,7 @@ set(SOURCES ...@@ -152,6 +158,7 @@ set(SOURCES
set(HEADERS set(HEADERS
src/app/App.hpp src/app/App.hpp
src/app/AppController.hpp
src/app/cli/Cli.hpp src/app/cli/Cli.hpp
src/app/logger/Logger.hpp src/app/logger/Logger.hpp
src/app/paths/Paths.hpp src/app/paths/Paths.hpp
...@@ -205,6 +212,13 @@ set(HEADERS ...@@ -205,6 +212,13 @@ set(HEADERS
src/utils/QExifImageHeader.h src/utils/QExifImageHeader.h
) )
set(TESTS
src/tests/SelfTest.cpp
)
set(MAIN_FILE src/app/main.cpp)
set(TESTER_MAIN_FILE src/tests/main.cpp)
if(APPLE) if(APPLE)
list(APPEND SOURCES src/components/core/MessagesCountNotifierMacOS.m) list(APPEND SOURCES src/components/core/MessagesCountNotifierMacOS.m)
endif() endif()
...@@ -288,6 +302,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN ...@@ -288,6 +302,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN
find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED) find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED)
find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET) find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET)
find_package(Qt5 COMPONENTS Test REQUIRED)
if (CMAKE_INSTALL_RPATH) if (CMAKE_INSTALL_RPATH)
get_target_property(LUPDATE_PATH Qt5::lupdate LOCATION) get_target_property(LUPDATE_PATH Qt5::lupdate LOCATION)
...@@ -304,46 +319,44 @@ list(APPEND QRC_RESOURCES "${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGES_DIRECTORY}/${ ...@@ -304,46 +319,44 @@ list(APPEND QRC_RESOURCES "${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGES_DIRECTORY}/${
qt5_add_resources(RESOURCES ${QRC_RESOURCES}) qt5_add_resources(RESOURCES ${QRC_RESOURCES})
# Build. # Build.
# Note: `update_translations` is provided by `languages/CMakeLists.txt`. add_library(${APP_LIBRARY} OBJECT ${SOURCES} ${HEADERS} ${RESOURCES} ${QML_SOURCES})
set_property(TARGET ${APP_LIBRARY} PROPERTY POSITION_INDEPENDENT_CODE ON)
bc_git_version(${TARGET_NAME} ${PROJECT_VERSION})
add_dependencies(${APP_LIBRARY} ${TARGET_NAME}-git-version)
add_dependencies(${APP_LIBRARY} update_translations)
if (WIN32) if (WIN32)
add_executable(${TARGET_NAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} assets/linphone.rc) add_executable(${TARGET_NAME} WIN32 $<TARGET_OBJECTS:${APP_LIBRARY}> assets/linphone.rc ${MAIN_FILE})
add_executable(${TESTER_TARGET_NAME} WIN32 $<TARGET_OBJECTS:${APP_LIBRARY}> assets/linphone.rc ${TESTER_MAIN_FILE} ${TESTS})
else () else ()
add_executable(${TARGET_NAME} ${SOURCES} ${HEADERS} ${RESOURCES} ${QML_SOURCES}) add_executable(${TARGET_NAME} $<TARGET_OBJECTS:${APP_LIBRARY}> ${MAIN_FILE})
add_executable(${TESTER_TARGET_NAME} $<TARGET_OBJECTS:${APP_LIBRARY}> ${TESTER_MAIN_FILE} ${TESTS})
endif () endif ()
bc_git_version(${TARGET_NAME} ${PROJECT_VERSION})
add_dependencies(${TARGET_NAME} ${TARGET_NAME}-git-version)
add_dependencies(${TARGET_NAME} update_translations)
if (NOT WIN32) if (NOT WIN32)
add_dependencies(update_translations check_qml) add_dependencies(update_translations check_qml)
endif () endif ()
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}") set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}")
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${LINPHONECXX_INCLUDE_DIRS}" "${LINPHONE_INCLUDE_DIRS}" "${BELCARD_INCLUDE_DIRS}" "${BCTOOLBOX_INCLUDE_DIRS}") set_target_properties(${TESTER_TARGET_NAME} PROPERTIES OUTPUT_NAME "${TESTER_EXECUTABLE_NAME}")
# To start better integration into IDE. set(INCLUDED_DIRECTORIES "${LINPHONECXX_INCLUDE_DIRS}" "${LINPHONE_INCLUDE_DIRS}" "${BELCARD_INCLUDE_DIRS}" "${BCTOOLBOX_INCLUDE_DIRS}")
source_group( set(LIBRARIES ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONE_LIBRARIES} ${LINPHONECXX_LIBRARIES})
"Qml" REGULAR_EXPRESSION ".+\.qml$"
)
source_group(
"Js" REGULAR_EXPRESSION ".+\.js)$"
)
source_group(
"Svg" REGULAR_EXPRESSION ".+\.svg$"
)
foreach (package ${QT5_PACKAGES}) foreach (package ${QT5_PACKAGES})
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${Qt5${package}_INCLUDE_DIRS}") list(APPEND INCLUDED_DIRECTORIES "${Qt5${package}_INCLUDE_DIRS}")
# `qt5_create_translation` is provided from `LinguistTools` package. # `qt5_create_translation` is provided from `LinguistTools` package.
# But the `Qt5::LinguistTools` lib does not exist. Remove it. # But the `Qt5::LinguistTools` lib does not exist. Remove it.
if (NOT (${package} STREQUAL LinguistTools)) if (NOT (${package} STREQUAL LinguistTools))
target_link_libraries(${TARGET_NAME} ${Qt5${package}_LIBRARIES}) list(APPEND LIBRARIES ${Qt5${package}_LIBRARIES})
endif () endif ()
endforeach () endforeach ()
foreach (package ${QT5_PACKAGES_OPTIONAL}) foreach (package ${QT5_PACKAGES_OPTIONAL})
if ("${Qt5${package}_FOUND}") if ("${Qt5${package}_FOUND}")
message("Optional package ${package} found.") message("Optional package ${package} found.")
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${Qt5${package}_INCLUDE_DIRS}") list(APPEND INCLUDED_DIRECTORIES "${Qt5${package}_INCLUDE_DIRS}")
target_link_libraries(${TARGET_NAME} ${Qt5${package}_LIBRARIES}) list(APPEND LIBRARIES ${Qt5${package}_LIBRARIES})
string(TOUPPER "${package}" INCLUDE_NAME) string(TOUPPER "${package}" INCLUDE_NAME)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${INCLUDE_NAME}_ENABLED") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${INCLUDE_NAME}_ENABLED")
...@@ -352,17 +365,25 @@ foreach (package ${QT5_PACKAGES_OPTIONAL}) ...@@ -352,17 +365,25 @@ foreach (package ${QT5_PACKAGES_OPTIONAL})
endif () endif ()
endforeach () endforeach ()
target_link_libraries(${TARGET_NAME} ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONE_LIBRARIES} ${LINPHONECXX_LIBRARIES}) if (APPLE)
if(APPLE) list(APPEND LIBRARIES "-framework Cocoa")
target_link_libraries(${TARGET_NAME} "-framework Cocoa") endif ()
endif()
install(TARGETS ${TARGET_NAME} target_include_directories(${APP_LIBRARY} SYSTEM PRIVATE ${INCLUDED_DIRECTORIES})
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${INCLUDED_DIRECTORIES})
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} target_include_directories(${TESTER_TARGET_NAME} SYSTEM PRIVATE ${INCLUDED_DIRECTORIES})
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE target_link_libraries(${TARGET_NAME} ${LIBRARIES})
) target_link_libraries(${TESTER_TARGET_NAME} ${LIBRARIES} Qt5::Test)
foreach (target ${TARGET_NAME} ${TESTER_TARGET_NAME})
install(TARGETS ${target}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endforeach ()
install(FILES "assets/linphone.desktop" install(FILES "assets/linphone.desktop"
DESTINATION "${CMAKE_INSTALL_DATADIR}/applications" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications"
...@@ -392,3 +413,17 @@ install(FILES "${ASSETS_ASSISTANT_DIR}/create-linphone-sip-account.rc" ...@@ -392,3 +413,17 @@ install(FILES "${ASSETS_ASSISTANT_DIR}/create-linphone-sip-account.rc"
install(FILES "${ASSETS_ASSISTANT_DIR}/use-linphone-sip-account.rc" install(FILES "${ASSETS_ASSISTANT_DIR}/use-linphone-sip-account.rc"
DESTINATION "${ASSISTANT_INSTALL_DATADIR}" DESTINATION "${ASSISTANT_INSTALL_DATADIR}"
) )
# ------------------------------------------------------------------------------
# To start better integration into IDE.
# ------------------------------------------------------------------------------
source_group(
"Qml" REGULAR_EXPRESSION ".+\.qml$"
)
source_group(
"Js" REGULAR_EXPRESSION ".+\.js)$"
)
source_group(
"Svg" REGULAR_EXPRESSION ".+\.svg$"
)
/* /*
* main.cpp * AppController.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France * Copyright (C) 2017 Belledonne Communications, Grenoble, France
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* *
* Created on: February 2, 2017 * Created on: July 17, 2017
* Author: Ronan Abhamon * Author: Ronan Abhamon
*/ */
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "gitversion.h" #include "gitversion.h"
#include "app/App.hpp" #include "AppController.hpp"
// Must be unique. Used by `SingleApplication` and `Paths`. // Must be unique. Used by `SingleApplication` and `Paths`.
#define APPLICATION_NAME "linphone" #define APPLICATION_NAME "linphone"
...@@ -39,7 +39,14 @@ using namespace std; ...@@ -39,7 +39,14 @@ using namespace std;
// ============================================================================= // =============================================================================
int main (int argc, char *argv[]) { #ifndef QT_NO_DEBUG
bool AppController::mCreated = false;
#endif // ifndef QT_NO_DEBUG
AppController::AppController (int &argc, char *argv[]) {
Q_ASSERT(!mCreated);
mCreated = true;
QT_REQUIRE_VERSION(argc, argv, APPLICATION_MINIMAL_QT_VERSION); QT_REQUIRE_VERSION(argc, argv, APPLICATION_MINIMAL_QT_VERSION);
// Disable QML cache. Avoid malformed cache. // Disable QML cache. Avoid malformed cache.
...@@ -81,12 +88,11 @@ int main (int argc, char *argv[]) { ...@@ -81,12 +88,11 @@ int main (int argc, char *argv[]) {
QCoreApplication::setApplicationName(APPLICATION_NAME); QCoreApplication::setApplicationName(APPLICATION_NAME);
QCoreApplication::setApplicationVersion(APPLICATION_VERSION); QCoreApplication::setApplicationVersion(APPLICATION_VERSION);
App app(argc, argv); mApp = new App(argc, argv);
if (mApp->isSecondary()) {
if (app.isSecondary()) { QString command = mApp->getCommandArgument();
QString command = app.getCommandArgument(); mApp->sendMessage(command.isEmpty() ? "show" : command.toLocal8Bit(), -1);
app.sendMessage(command.isEmpty() ? "show" : command.toLocal8Bit(), -1); return;
return 0;
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -104,18 +110,9 @@ int main (int argc, char *argv[]) { ...@@ -104,18 +110,9 @@ int main (int argc, char *argv[]) {
} }
} }
app.setFont(QFont(DEFAULT_FONT)); mApp->setFont(QFont(DEFAULT_FONT));
}
// ---------------------------------------------------------------------------
// Init and run!
// ---------------------------------------------------------------------------
qInfo() << QStringLiteral("Running app...");
int ret; AppController::~AppController () {
do { delete mApp;
app.initContentApp();
ret = app.exec();
} while (ret == APP_CODE_RESTART);
return ret;
} }
/*
* AppController.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: July 17, 2017
* Author: Ronan Abhamon
*/
#include "App.hpp"
// =============================================================================
class AppController {
public:
AppController (int &argc, char *argv[]);
~AppController ();
App *getApp () const {
return mApp;
}
private:
App *mApp = nullptr;
#ifndef QT_NO_DEBUG
static bool mCreated;
#endif // ifndef QT_NO_DEBUG
};
/*
* main.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: February 2, 2017
* Author: Ronan Abhamon
*/
#include "AppController.hpp"
// =============================================================================
int main (int argc, char *argv[]) {
AppController controller(argc, argv);
App *app = controller.getApp();
if (app->isSecondary())
return 0;
qInfo() << QStringLiteral("Running app...");
int ret;
do {
app->initContentApp();
ret = app->exec();
} while (ret == APP_CODE_RESTART);
return ret;
}
/*
* SelfTest.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: July 17, 2017
* Author: Ronan Abhamon
*/
#include <QTest>
// =============================================================================
class SelfTest : public QObject {
Q_OBJECT;
private slots:
void t1 () {
QVERIFY(true);
}
};
#include "SelfTest.moc"
/*
* main.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: July 17, 2017
* Author: Ronan Abhamon
*/
#include "../app/AppController.hpp"
// =============================================================================
int main (int argc, char *argv[]) {
AppController controller(argc, argv);
App *app = controller.getApp();
if (app->isSecondary())
return 0;
qInfo() << QStringLiteral("Running test...");
int ret;
do {
app->initContentApp();
ret = app->exec();
} while (ret == APP_CODE_RESTART);
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment