macro(make_dbus_class NAME INTERFACE)
    if(${CMAKE_CURRENT_SOURCE_DIR}/interfaces.xml IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/${NAME}Adaptor.h)
        execute_process(COMMAND ${QDBUSXML2CPP_EXECUTABLE} -c ${NAME}Adaptor -i types.h -a ${CMAKE_CURRENT_BINARY_DIR}/${NAME}Adaptor ${CMAKE_CURRENT_SOURCE_DIR}/interfaces.xml ${INTERFACE})
    endif()
endmacro(make_dbus_class)

make_dbus_class(Accounts org.freedesktop.Accounts)
make_dbus_class(Input com.lomiri.AccountsService.Input)
make_dbus_class(Properties org.freedesktop.DBus.Properties)
make_dbus_class(SecurityPrivacy com.lomiri.touch.AccountsService.SecurityPrivacy)
make_dbus_class(Location com.ubuntu.location.providers.here.AccountsService)
make_dbus_class(AccountsUser org.freedesktop.Accounts.User)
make_dbus_class(AccountsPrivate com.lomiri.shell.AccountsService.Private)
make_dbus_class(LscInput com.lomiri.SystemCompositor.Input)

include_directories(
    ${GLIB_INCLUDE_DIRS}
    ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/plugins/AccountsService
    )

link_libraries(
    ${GLIB_LIBRARIES}
    )

add_definitions(-DSM_BUSNAME=sessionBus)

add_executable(mock-server
    ${CMAKE_CURRENT_BINARY_DIR}/AccountsAdaptor.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/AccountsPrivateAdaptor.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/AccountsUserAdaptor.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/InputAdaptor.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/PropertiesAdaptor.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/LocationAdaptor.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/SecurityPrivacyAdaptor.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/LscInputAdaptor.cpp
    server.cpp
    AccountsServer.cpp
    PropertiesServer.cpp
    LscServer.cpp
    )
target_link_libraries(mock-server Qt5::Core Qt5::DBus)
install(TARGETS mock-server
    DESTINATION "${SHELL_PRIVATE_FULL_LIBEXECDIR}/tests/plugins/AccountsService"
)

add_executable(test-accountsservice
    ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsService.cpp
    ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsServiceDBusAdaptor.cpp
    client.cpp
    )
target_link_libraries(test-accountsservice Qt5::Core Qt5::DBus Qt5::Test)
install(TARGETS test-accountsservice
    DESTINATION "${SHELL_PRIVATE_FULL_LIBEXECDIR}/tests/plugins/AccountsService"
)

add_lomiri_unittest(AccountsService dbus-test-runner
    ARG_PREFIX "--parameter"
    ARGS
        --task $<TARGET_FILE:mock-server>
        --task-name server
        --ignore-return
        --task $<TARGET_FILE:test-accountsservice>
        --task-name client
        --wait-for org.freedesktop.Accounts
    )
