# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: none
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
add_definitions( -DMESSAGECORE_DATA_DIR="${CMAKE_SOURCE_DIR}/messagecore/autotests/data" )
add_definitions( -DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
add_definitions( -DGNUPGHOME="${CMAKE_BINARY_DIR}/messagecore/autotests/gnupg_home")

include( ${CMAKE_SOURCE_DIR}/cmake/modules/kdepim_add_gpg_crypto_test.cmake )

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/part)

# Convenience macro to add messagecomposer unit tests.
macro( add_messagecomposer_test _source )
    get_filename_component( _name ${_source} NAME_WE )
    ecm_add_test(${ARGV}
        TEST_NAME ${_name}
        NAME_PREFIX "messagecomposer-"
        LINK_LIBRARIES
            KF${KF_MAJOR_VERSION}::I18n
            KPim${KF_MAJOR_VERSION}::MailTransport
            KPim${KF_MAJOR_VERSION}::Mime
            KPim${KF_MAJOR_VERSION}::MessageComposer
            KPim${KF_MAJOR_VERSION}::MimeTreeParser
            KPim${KF_MAJOR_VERSION}::MessageCore
            KPim${KF_MAJOR_VERSION}::TemplateParser
            KPim${KF_MAJOR_VERSION}::PimTextEdit
            Qt::Test
            KPim${KF_MAJOR_VERSION}::IdentityManagementWidgets
            KF${KF_MAJOR_VERSION}::Contacts
            KPim${KF_MAJOR_VERSION}::AkonadiCore
            KF${KF_MAJOR_VERSION}::XmlGui
            KPim${KF_MAJOR_VERSION}::Libkdepim
            KF${KF_MAJOR_VERSION}::IconThemes
            KF${KF_MAJOR_VERSION}::Completion
    )

    if (TARGET Qt::Core5Compat)
        target_link_libraries(${_name} Qt::Core5Compat)
    endif()
endmacro()

macro( add_messagecomposer_cryptotest _source )
    set( _test cryptofunctions.cpp setupenv.cpp ${_source} )
    get_filename_component( _name ${_source} NAME_WE )
    add_executable( ${_name} ${_test}  ${_name}.h )
    target_link_libraries(
        ${_name}
        KF${KF_MAJOR_VERSION}::I18n
        KPim${KF_MAJOR_VERSION}::Mime
        KPim${KF_MAJOR_VERSION}::MessageComposer
        KPim${KF_MAJOR_VERSION}::MimeTreeParser
        KPim${KF_MAJOR_VERSION}::MessageCore
        KPim${KF_MAJOR_VERSION}::Libkleo
        KPim${KF_MAJOR_VERSION}::Libkdepim
        KPim${KF_MAJOR_VERSION}::PimTextEdit
        KPim${KF_MAJOR_VERSION}::AkonadiCore
        Qt::Test
        KF${KF_MAJOR_VERSION}::IconThemes
        KF${KF_MAJOR_VERSION}::Completion
        KPim${KF_MAJOR_VERSION}::MailTransport
        KF${KF_MAJOR_VERSION}::Contacts
    )
    add_gpg_crypto_test(${_name} messagecomposer-${_name})
    set_tests_properties(messagecomposer-${_name} PROPERTIES
        ENVIRONMENT "LC_ALL=en_US.UTF-8"
    )
endmacro()


# Utility stuff.
add_messagecomposer_test( draftstatustest.cpp )
add_messagecomposer_test( utiltest.cpp )
add_messagecomposer_test( messagefactoryngtest.cpp setupenv.cpp)
add_messagecomposer_test( plugineditorcheckbeforesendparamstest.cpp )
add_messagecomposer_test( replystrategytest.cpp )

# Non-content jobs.
add_messagecomposer_test( skeletonmessagejobtest.cpp )

# Basic content jobs.
add_messagecomposer_test( singlepartjobtest.cpp )
add_messagecomposer_test( multipartjobtest.cpp )

# More complex content jobs.
add_messagecomposer_test( attachmentjobtest.cpp )
add_messagecomposer_test( maintextjobtest.cpp )
add_messagecomposer_test( itipjobtest.cpp )

# Composer.
add_messagecomposer_test( composertest.cpp )
add_messagecomposer_cryptotest( cryptocomposertest.cpp )
add_messagecomposer_test( infoparttest.cpp )
add_messagecomposer_test( textparttest.cpp )
add_messagecomposer_test( globalparttest.cpp )
add_messagecomposer_cryptotest( composerviewbasetest.cpp )

add_messagecomposer_test( recipientseditortest.cpp )

# SendLater
add_messagecomposer_test( sendlaterdialogtest.cpp )
add_messagecomposer_test( sendlaterinfotest.cpp )

# Crypto
add_messagecomposer_cryptotest( autocryptheadersjobtest.cpp )
add_messagecomposer_cryptotest( signjobtest.cpp )
add_messagecomposer_cryptotest( encryptjobtest.cpp )
add_messagecomposer_cryptotest( signencrypttest.cpp )
add_messagecomposer_cryptotest( signandencrypttest.cpp )
add_messagecomposer_cryptotest( autocryptresolvercoretest.cpp )
add_messagecomposer_cryptotest( keyresolvertest.cpp )

set(AKONADI_RUN_POSTGRES_ISOLATED_TESTS FALSE)
set(AKONADI_RUN_MYSQL_ISOLATED_TESTS FALSE)

ecm_add_test(followupreminderselectdatedialogtest.cpp
    NAME_PREFIX "messagecomposer-"
    LINK_LIBRARIES
        KPim${KF_MAJOR_VERSION}::AkonadiCore
        KPim${KF_MAJOR_VERSION}::AkonadiWidgets
        KF${KF_MAJOR_VERSION}::CalendarCore
        KPim${KF_MAJOR_VERSION}::MessageComposer
        Qt::Test
)

ecm_add_test(attachmentvcardfromaddressbookjobtest.cpp
    NAME_PREFIX "messagecomposer-"
    LINK_LIBRARIES
        KF${KF_MAJOR_VERSION}::Contacts
        KPim${KF_MAJOR_VERSION}::MessageComposer
        Qt::Test
)
