macro(link_database_test test_target)

    add_definitions(${MYSQL_CFLAGS})

    if(APPLE)
        SET_TARGET_PROPERTIES(${test_target} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
    endif(APPLE)

    add_dependencies( ${test_target} amarokconfig_h )
    add_dependencies( ${test_target} amarokcore )
    add_dependencies( ${test_target} amaroklib)
    add_dependencies( ${test_target} amarok-sqlcollection)
    add_dependencies( ${test_target} amarok_collection-mysqlecollection)

    target_link_libraries(${test_target}
        amarokcore
        amaroklib
        amarok-sqlcollection
        amarok_collection-mysqlecollection
        ${KDE4_KDECORE_LIBS}
        ${KDE4_KIO_LIBS}
        ${KDE4_THREADWEAVER_LIBRARIES}
        ${KDE4_KDEUI_LIBS}
        ${QT_QTTEST_LIBRARY}
        ${QT_QTCORE_LIBRARY}
        ${MYSQL_LIBRARIES}
        ${CMAKE_DL_LIBS}
        ${TAGLIB-EXTRAS_LIBRARIES}
        ${TAGLIB_LIBRARIES}
        ${ZLIB_LIBRARIES})

endmacro(link_database_test)


include_directories(
  ${AMAROK_TEST_TREE}
  ${AMAROK_SOURCE_TREE}
  ${AMAROK_SOURCE_TREE}/core-impl/collections/db/sql
  ${AMAROK_SOURCE_TREE}/core-impl/logger
  ${AMAROK_UTILITY_TREE}
  ${CMAKE_BINARY_DIR}/src
  ${CMAKE_BINARY_DIR}/tests
  ${AMAROK_COLLECTION_SUPPORT_DIR}
  ${KDE4_INCLUDE_DIR}
  ${QT_INCLUDES}
  ${MYSQL_INCLUDE_DIR}
  )

#------------------------------- DatabaseUpdater Test -------------------------------

set( databaseupdatertest_SRCS
        TestDatabaseUpdater.cpp
    )

kde4_add_unit_test( testsqldatabaseupdater TESTNAME testsqldatabaseupdater ${databaseupdatertest_SRCS} )
link_database_test( testsqldatabaseupdater )

#-------------------------------- Test SqlAlbum -----------------------

set( testsqlalbum_SRCS
        TestSqlAlbum.cpp
    )


kde4_add_unit_test( testsqlalbum TESTNAME testsqlalbum ${testsqlalbum_SRCS} )

link_database_test( testsqlalbum )

#-------------------------------- Test SqlArtist -----------------------

set( testsqlartist_SRCS
        TestSqlArtist.cpp
    )


kde4_add_unit_test( testsqlartist ${testsqlartist_SRCS} )

link_database_test( testsqlartist )
#-------------------------------- Test SqlCollection -----------------------

set( testsqlcollection_SRCS
        TestSqlCollection.cpp
    )


kde4_add_unit_test( testsqlcollection ${testsqlcollection_SRCS} )

link_database_test( testsqlcollection )

#-------------------------------- Test SqlQueryMaker -----------------------

set( testsqlquerymaker_SRCS
        TestSqlQueryMaker.cpp
    )


kde4_add_unit_test( testsqlquerymaker ${testsqlquerymaker_SRCS} )

link_database_test( testsqlquerymaker )

#-------------------------------- Test SqlScanManager -----------------------

set( testsqlscanmanager_SRCS
        TestSqlScanManager.cpp
    )


kde4_add_unit_test( testsqlscanmanager ${testsqlscanmanager_SRCS} )

link_database_test( testsqlscanmanager )

#-------------------------------- Test SqlTrack -----------------------

set( testsqltrack_SRCS
        TestSqlTrack.cpp
        ${AMAROK_TEST_TREE}/MetaNotificationSpy.cpp
    )


kde4_add_unit_test( testsqltrack ${testsqltrack_SRCS} )

link_database_test( testsqltrack )

#-------------------------------- Test SqlCollectionLocation -----------------------

set( testsqlcollectionlocation_SRCS
        TestSqlCollectionLocation.cpp
        ${AMAROK_SOURCE_TREE}/core-impl/logger/ProxyLogger.cpp
    )

kde4_add_unit_test( testsqlcollectionlocation ${testsqlcollectionlocation_SRCS} )

add_dependencies( testsqlcollectionlocation amarokconfig_h )
add_dependencies( testsqlcollectionlocation amarokcore )
add_dependencies( testsqlcollectionlocation amaroklib)
add_dependencies( testsqlcollectionlocation amarok-sqlcollection)


# order matters when linking to libmyslqd.a, so beware of reordering
target_link_libraries( testsqlcollectionlocation
        amarokcore
        amaroklib
        amarok-sqlcollection
        amarok_collection-mysqlecollection
        ${KDE4_KDECORE_LIBS}
        ${KDE4_KIO_LIBS}
        ${KDE4_KDEUI_LIBS}
        ${KDE4_THREADWEAVER_LIBRARIES}
        ${QT_QTTEST_LIBRARY}
        ${QT_QTCORE_LIBRARY}
        ${MYSQL_EMBEDDED_LIBRARIES}
        ${CMAKE_DL_LIBS}
        ${TAGLIB-EXTRAS_LIBRARIES}
        ${TAGLIB_LIBRARIES}
        ${ZLIB_LIBRARIES}
        ${GOOGLEMOCK_LIBRARIES}
        )

if(NOT WIN32 AND NOT APPLE)
    target_link_libraries( testsqlcollectionlocation crypt pthread )
endif(NOT WIN32 AND NOT APPLE)

