From 02dd363feb87f9205bdc65c2ad6a33d4b94b9630 Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Mon, 1 Feb 2021 21:07:17 +0100 Subject: [PATCH] Add test utils library The test utils library collects all dependencies that are needed for tests and gets automatically linked with every test. Signed-off-by: Felix Weilbach --- src/cmd/CMakeLists.txt | 24 +++++---- test/CMakeLists.txt | 95 ++++++++++++++++++----------------- test/nextcloud_add_test.cmake | 21 +++++--- 3 files changed, 78 insertions(+), 62 deletions(-) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index f7b6a10a5..cea206600 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -2,12 +2,19 @@ project(cmd) set(CMAKE_AUTOMOC TRUE) set(cmd_NAME ${APPLICATION_EXECUTABLE}cmd) -set(cmd_SRC - cmd.cpp - simplesslerrorhandler.cpp - netrcparser.cpp - ) +add_library(cmdCore STATIC simplesslerrorhandler.cpp netrcparser.cpp) + +target_link_libraries(cmdCore + PUBLIC + "${csync_NAME}" + "${synclib_NAME}" + Qt5::Core + Qt5::Network + ) + +# Need tokenizer for netrc parser +target_include_directories(cmdCore PRIVATE ${CMAKE_SOURCE_DIR}/src/3rdparty/qtokenizer) if(UNIX AND NOT APPLE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") @@ -20,14 +27,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") endif() if(NOT BUILD_LIBRARIES_ONLY) - add_executable(${cmd_NAME} ${cmd_SRC}) + add_executable(${cmd_NAME} cmd.cpp) set_target_properties(${cmd_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY} ) - target_link_libraries(${cmd_NAME} "${csync_NAME}" "${synclib_NAME}" Qt5::Core Qt5::Network) - - # Need tokenizer for netrc parser - target_include_directories(${cmd_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/3rdparty/qtokenizer) + target_link_libraries(${cmd_NAME} cmdCore) endif() # OSX: Copy nextcloudcmd to app bundle, src/gui will run macdeployqt diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f3bbc516a..2297eb0da 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,68 +5,73 @@ include(nextcloud_add_test.cmake) set(CMAKE_AUTOMOC TRUE) -add_library(syncenginetestutils STATIC syncenginetestutils.cpp) -target_link_libraries(syncenginetestutils PUBLIC ${APPLICATION_EXECUTABLE}sync Qt5::Test) -target_include_directories(syncenginetestutils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +add_library(testutils + STATIC + syncenginetestutils.cpp + pushnotificationstestutils.cpp +) -nextcloud_add_test(NextcloudPropagator "") +target_link_libraries(testutils PUBLIC ${APPLICATION_EXECUTABLE}sync Qt5::Test) +target_include_directories(testutils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +nextcloud_add_test(NextcloudPropagator) IF(BUILD_UPDATER) - nextcloud_add_test(Updater "") + nextcloud_add_test(Updater) endif() -nextcloud_add_test(NetrcParser ../src/cmd/netrcparser.cpp) -nextcloud_add_test(OwnSql "") -nextcloud_add_test(SyncJournalDB "") -nextcloud_add_test(SyncFileItem "") -nextcloud_add_test(ConcatUrl "") -nextcloud_add_test(Cookies "") -nextcloud_add_test(XmlParse "") -nextcloud_add_test(ChecksumValidator "") +nextcloud_add_test(NetrcParser) +nextcloud_add_test(OwnSql) +nextcloud_add_test(SyncJournalDB) +nextcloud_add_test(SyncFileItem) +nextcloud_add_test(ConcatUrl) +nextcloud_add_test(Cookies) +nextcloud_add_test(XmlParse) +nextcloud_add_test(ChecksumValidator) -nextcloud_add_test(ClientSideEncryption "") -nextcloud_add_test(ExcludedFiles "") +nextcloud_add_test(ClientSideEncryption) +nextcloud_add_test(ExcludedFiles) -nextcloud_add_test(Utility "") -nextcloud_add_test(SyncEngine "") -nextcloud_add_test(SyncVirtualFiles "") -nextcloud_add_test(SyncMove "") -nextcloud_add_test(SyncDelete "") -nextcloud_add_test(SyncConflict "") -nextcloud_add_test(SyncFileStatusTracker "") -nextcloud_add_test(Download "") -nextcloud_add_test(ChunkingNg "") -nextcloud_add_test(AsyncOp "") -nextcloud_add_test(UploadReset "") -nextcloud_add_test(AllFilesDeleted "") -nextcloud_add_test(Blacklist "") -nextcloud_add_test(LocalDiscovery "") -nextcloud_add_test(RemoteDiscovery "") -nextcloud_add_test(Permissions "") -nextcloud_add_test(SelectiveSync "") -nextcloud_add_test(DatabaseError "") -nextcloud_add_test(LockedFiles "../src/gui/lockwatcher.cpp") -nextcloud_add_test(FolderWatcher "") -nextcloud_add_test(Capabilities "") -nextcloud_add_test(PushNotifications "pushnotificationstestutils.cpp") +nextcloud_add_test(Utility) +nextcloud_add_test(SyncEngine) +nextcloud_add_test(SyncVirtualFiles) +nextcloud_add_test(SyncMove) +nextcloud_add_test(SyncDelete) +nextcloud_add_test(SyncConflict) +nextcloud_add_test(SyncFileStatusTracker) +nextcloud_add_test(Download) +nextcloud_add_test(ChunkingNg) +nextcloud_add_test(AsyncOp) +nextcloud_add_test(UploadReset) +nextcloud_add_test(AllFilesDeleted) +nextcloud_add_test(Blacklist) +nextcloud_add_test(LocalDiscovery) +nextcloud_add_test(RemoteDiscovery) +nextcloud_add_test(Permissions) +nextcloud_add_test(SelectiveSync) +nextcloud_add_test(DatabaseError) +nextcloud_add_test(LockedFiles) +nextcloud_add_test(FolderWatcher) +nextcloud_add_test(Capabilities) +nextcloud_add_test(PushNotifications) if( UNIX AND NOT APPLE ) - nextcloud_add_test(InotifyWatcher "${FolderWatcher_SRC}") + nextcloud_add_test(InotifyWatcher) endif(UNIX AND NOT APPLE) if (WIN32) - nextcloud_add_test(LongWinPath "") - nextcloud_add_test(SyncCfApi "") + nextcloud_add_test(LongWinPath) + nextcloud_add_test(SyncCfApi) elseif(LINUX) # elseif(LINUX OR APPLE) - nextcloud_add_test(SyncXAttr "") + nextcloud_add_test(SyncXAttr) endif() -nextcloud_add_benchmark(LargeSync "") +nextcloud_add_benchmark(LargeSync) -nextcloud_add_test(FolderMan "") -nextcloud_add_test(RemoteWipe "") +nextcloud_add_test(FolderMan) +nextcloud_add_test(RemoteWipe) -nextcloud_add_test(OAuth "../src/gui/creds/oauth.cpp") +nextcloud_add_test(OAuth) configure_file(test_journal.db "${PROJECT_BINARY_DIR}/bin/test_journal.db" COPYONLY) diff --git a/test/nextcloud_add_test.cmake b/test/nextcloud_add_test.cmake index 07e9d1e83..2d775fcae 100644 --- a/test/nextcloud_add_test.cmake +++ b/test/nextcloud_add_test.cmake @@ -1,17 +1,18 @@ find_package(Qt5 COMPONENTS Core Test Xml Network Qml Quick REQUIRED) -macro(nextcloud_add_test test_class additional_cpp) +macro(nextcloud_add_test test_class) set(CMAKE_AUTOMOC TRUE) set(OWNCLOUD_TEST_CLASS ${test_class}) string(TOLOWER "${OWNCLOUD_TEST_CLASS}" OWNCLOUD_TEST_CLASS_LOWERCASE) - add_executable(${OWNCLOUD_TEST_CLASS}Test test${OWNCLOUD_TEST_CLASS_LOWERCASE}.cpp ${additional_cpp}) + add_executable(${OWNCLOUD_TEST_CLASS}Test test${OWNCLOUD_TEST_CLASS_LOWERCASE}.cpp) set_target_properties(${OWNCLOUD_TEST_CLASS}Test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY}) target_link_libraries(${OWNCLOUD_TEST_CLASS}Test ${APPLICATION_EXECUTABLE}sync - syncenginetestutils + testutils nextcloudCore + cmdCore Qt5::Test Qt5::Quick ) @@ -35,17 +36,23 @@ macro(nextcloud_add_test test_class additional_cpp) ) endmacro() -macro(nextcloud_add_benchmark test_class additional_cpp) +macro(nextcloud_add_benchmark test_class) set(CMAKE_AUTOMOC TRUE) set(OWNCLOUD_TEST_CLASS ${test_class}) string(TOLOWER "${OWNCLOUD_TEST_CLASS}" OWNCLOUD_TEST_CLASS_LOWERCASE) - add_executable(${OWNCLOUD_TEST_CLASS}Bench benchmarks/bench${OWNCLOUD_TEST_CLASS_LOWERCASE}.cpp ${additional_cpp}) + add_executable(${OWNCLOUD_TEST_CLASS}Bench benchmarks/bench${OWNCLOUD_TEST_CLASS_LOWERCASE}.cpp) set_target_properties(${OWNCLOUD_TEST_CLASS}Bench PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY}) target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench - ${APPLICATION_EXECUTABLE}sync syncenginetestutils - Qt5::Core Qt5::Test Qt5::Xml Qt5::Network + ${APPLICATION_EXECUTABLE}sync + testutils + nextcloudCore + cmdCore + Qt5::Core + Qt5::Test + Qt5::Xml + Qt5::Network ) IF(BUILD_UPDATER)