# cmake <http://www.cmake.org> test file for SMSD
# Copyright (c) 2007-2009 Michal Cihar
# vim: expandtab sw=4 ts=4 sts=4 ft=cmake:

set(PSQL_HOST 127.0.0.1 CACHE STRING "Host to use for PostgreSQL tests")
set(PSQL_DATABASE smsd CACHE STRING "Database to use for PostgreSQL tests")
set(PSQL_USER smsd CACHE STRING "User to use for PostgreSQL tests")
set(PSQL_PASSWORD smsd CACHE STRING "Password to use for PostgreSQL tests")

set(MYSQL_HOST 127.0.0.1 CACHE STRING "Host to use for MySQL tests")
set(MYSQL_DATABASE smsd CACHE STRING "Database to use for MySQL tests")
set(MYSQL_USER smsd CACHE STRING "User to use for MySQL tests")
set(MYSQL_PASSWORD smsd CACHE STRING "Password to use for MySQL tests")

configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/test-smsd.sh" "${CMAKE_CURRENT_BINARY_DIR}/run-test-smsd.sh" ESCAPE_QUOTES)
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/test-smsd-files.sh" "${CMAKE_CURRENT_BINARY_DIR}/run-test-smsd-files.sh" ESCAPE_QUOTES)

macro(smsd_testsuite _driver)
    # This test tests some functionality and setups environment
    add_test("smsd-${_driver}" "${SH_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/run-test-smsd.sh" "${_driver}")
    set_tests_properties("smsd-${_driver}" PROPERTIES
        PASS_REGULAR_EXPRESSION ".999999999999999.3.6.0.100.42"
        FAIL_REGULAR_EXPRESSION "ERROR: ;DBI error ([^5]:|[0-9][^:]);Wrong"
        )

    add_test("smsd-inject-${_driver}" "${CMAKE_CURRENT_BINARY_DIR}/gammu-smsd-inject${GAMMU_TEST_SUFFIX}" -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" TEXT 123465 -text "Lorem ipsum.")
    set_tests_properties("smsd-inject-${_driver}" PROPERTIES
        FAIL_REGULAR_EXPRESSION "DBI error;SQL failed"
        )
    add_test("smsd-inject-long-${_driver}" "${CMAKE_CURRENT_BINARY_DIR}/gammu-smsd-inject${GAMMU_TEST_SUFFIX}" -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" EMS 123465 -text "Mqukqirip ya konej eqniu rejropocejor hugiygydewl tfej nrupxujob xuemymiyliralj. Te tvyjuh qaxumur ibewfoiws zuucoz tdygu gelum L ejqigqesykl kya jdytbezy ucixh mqudemiywty nzihriduwlo yxylyujvghpv. Tiekoohunl dloijoda qelejocewu bfe bxuahadempivog. Ev mfegijox vleinley ewig qihopqu fafozmuvipc ernogtipeq acuoclzyv m poujhyerbjpipc vyq. Xty ljietenea ypep ti dik ela jozmyihipup xopujoqyjaw jojyuhietry mexykpih ysec yum zyhniet dezjiyup nuyryfsohnir Zeyoekemdoj tayqgh. Xvujuxy gysun dahyfecpetk uziyecz jogovxi fbypexsotn exymnomeatd ayiostiyvoxfy iqilo redvejf gfeypavlvaqu vfyjonytbug rgyxn siuybmulijub bxu xewz qisubevumxyzk ufuylehyzc. Nse xobq dfolizygqysj t bvowsyhyhyemim ovutpapeaempye giuuwbib.")
    set_tests_properties("smsd-inject-long-${_driver}" PROPERTIES
        FAIL_REGULAR_EXPRESSION "DBI error"
        )
    if (HAVE_ALARM)
        add_test("smsd-daemon-${_driver}" "${CMAKE_CURRENT_BINARY_DIR}/gammu-smsd${GAMMU_TEST_SUFFIX}" -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" -X 10)
        set_tests_properties("smsd-daemon-${_driver}" PROPERTIES
            FAIL_REGULAR_EXPRESSION "DBI error;SQL failed"
            )
    endif (HAVE_ALARM)
endmacro(smsd_testsuite _driver)

if (LIBDBI_FOUND AND SH_BIN AND SQLITE_BIN AND SED_BIN)
    smsd_testsuite("dbi-sqlite3")
endif (LIBDBI_FOUND AND SH_BIN AND SQLITE_BIN AND SED_BIN)

if (MYSQL_TESTING)
    smsd_testsuite("mysql")
    if (LIBDBI_FOUND)
        smsd_testsuite("dbi-mysql")
    endif (LIBDBI_FOUND)
endif (MYSQL_TESTING)

if (PSQL_TESTING)
    smsd_testsuite("pgsql")
    if (LIBDBI_FOUND)
        smsd_testsuite("dbi-pgsql")
    endif (LIBDBI_FOUND)
endif (PSQL_TESTING)

add_test("smsd-files-unicode" "${SH_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/run-test-smsd-files.sh" unicode)
set_tests_properties("smsd-files-unicode" PROPERTIES
    PASS_REGULAR_EXPRESSION ".999999999999999.3.6.0.100.42"
    FAIL_REGULAR_EXPRESSION "ERROR: ;Wrong"
    )
add_test("smsd-files-standard" "${SH_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/run-test-smsd-files.sh" standard)
set_tests_properties("smsd-files-standard" PROPERTIES
    PASS_REGULAR_EXPRESSION ".999999999999999.3.6.0.100.42"
    FAIL_REGULAR_EXPRESSION "ERROR: ;Wrong"
    )
add_test("smsd-files-detail" "${SH_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/run-test-smsd-files.sh" detail)
set_tests_properties("smsd-files-detail" PROPERTIES
    PASS_REGULAR_EXPRESSION ".999999999999999.3.6.0.100.42"
    FAIL_REGULAR_EXPRESSION "ERROR: ;Wrong"
    )

if (HAVE_ALARM)
    add_test("smsd-daemon-files-unicode" "${CMAKE_CURRENT_BINARY_DIR}/gammu-smsd${GAMMU_TEST_SUFFIX}" -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-files-unicode/.smsdrc" -X 10)
    add_test("smsd-daemon-files-standard" "${CMAKE_CURRENT_BINARY_DIR}/gammu-smsd${GAMMU_TEST_SUFFIX}" -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-files-standard/.smsdrc" -X 10)
    add_test("smsd-daemon-files-detail" "${CMAKE_CURRENT_BINARY_DIR}/gammu-smsd${GAMMU_TEST_SUFFIX}" -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-files-detail/.smsdrc" -X 10)
endif (HAVE_ALARM)
