# cmake <http://www.cmake.org> build file for Gammu
# Copyright © 2007 - 2009 Michal Čihař
# vim: expandtab sw=4 ts=4 sts=4:

project (gammu-tests C)

include(SetupDummyPhone)

include(GammuTuneCompiler)

# Define path for cmake tests
if (EXECUTABLE_OUTPUT_PATH)
    set (GAMMU_TEST_PATH "${EXECUTABLE_OUTPUT_PATH}/")
else (EXECUTABLE_OUTPUT_PATH)
    set (GAMMU_TEST_PATH "${CMAKE_CURRENT_BINARY_DIR}/")
endif (EXECUTABLE_OUTPUT_PATH)

# We use Gammu
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../include")

# Basic check for statemachine allocation
add_executable(statemachine-alloc statemachine-alloc.c)
target_link_libraries(statemachine-alloc libGammu ${LIBINTL_LIBRARIES})
add_test(statemachine-alloc "${GAMMU_TEST_PATH}/statemachine-alloc${GAMMU_TEST_SUFFIX}")

if (BLUETOOTH_RF_SEARCHING)
    add_executable(bluetooth_checkservicename bluetooth_checkservicename.c)
    target_link_libraries(bluetooth_checkservicename libGammu ${LIBINTL_LIBRARIES})
    add_test(bluetooth_checkservicename "${GAMMU_TEST_PATH}/bluetooth_checkservicename${GAMMU_TEST_SUFFIX}")
endif (BLUETOOTH_RF_SEARCHING)

# Basic check for sizes
add_executable(sizes sizes.c)
add_test(sizes "${GAMMU_TEST_PATH}/sizes${GAMMU_TEST_SUFFIX}")
set_tests_properties(sizes PROPERTIES
    FAIL_REGULAR_EXPRESSION "[0-9][0-9] MiB")

add_executable(base64 base64.c)
target_link_libraries(base64 libGammu ${LIBINTL_LIBRARIES})
add_test(base64 "${GAMMU_TEST_PATH}/base64${GAMMU_TEST_SUFFIX}")

# Array manipulation tests
add_executable(array-test array-test.c)
target_link_libraries (array-test array)
add_test(array "${GAMMU_TEST_PATH}/array-test${GAMMU_TEST_SUFFIX}")

# SQL backend date parsing
if (HAVE_MYSQL_MYSQL_H OR LIBDBI_FOUND OR HAVE_POSTGRESQL_LIBPQ_FE_H)
    if (LIBDBI_FOUND)
        include_directories (${LIBDBI_INCLUDE_DIR})
    endif (LIBDBI_FOUND)

    if (MYSQL_FOUND)
        include_directories (${MYSQL_INCLUDE_DIR})
    endif (MYSQL_FOUND)

    if (POSTGRES_FOUND)
        include_directories (${POSTGRES_INCLUDE_DIR})
    endif (POSTGRES_FOUND)

    add_executable(sql-parse-date sql-parse-date.c)
    target_link_libraries (sql-parse-date gsmsd)
    add_test(sql-parse-date "${GAMMU_TEST_PATH}/sql-parse-date${GAMMU_TEST_SUFFIX}")
endif (HAVE_MYSQL_MYSQL_H OR LIBDBI_FOUND OR HAVE_POSTGRESQL_LIBPQ_FE_H)

# Backup comments
if (WITH_BACKUP)
    add_executable(backup-comment backup-comment.c)
    target_link_libraries (backup-comment libGammu ${LIBINTL_LIBRARIES})
    add_test(backup-comment "${GAMMU_TEST_PATH}/backup-comment${GAMMU_TEST_SUFFIX}")
endif (WITH_BACKUP)

# Backup reading
if (WITH_BACKUP)
    add_executable(read-backup read-backup.c)
    target_link_libraries (read-backup libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB BACKUPS
        RELATIVE "${Gammu_SOURCE_DIR}/tests/backups"
        "${Gammu_SOURCE_DIR}/tests/backups/*.backup")
    list(SORT BACKUPS)

    foreach(TESTBACKUP ${BACKUPS})
        string(REPLACE .backup "" TESTNAME ${TESTBACKUP})
        add_test("read-backup-${TESTNAME}"
            "${GAMMU_TEST_PATH}/read-backup${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/backups/${TESTBACKUP}")
    endforeach(TESTBACKUP $BACKUPS)
endif (WITH_BACKUP)

# Basic check for statemachine functionality
add_executable(statemachine-init statemachine-init.c)
target_link_libraries(statemachine-init libGammu ${LIBINTL_LIBRARIES})
add_test(statemachine-init "${GAMMU_TEST_PATH}/statemachine-init${GAMMU_TEST_SUFFIX}")

# USB device parsing
if (LIBUSB_FOUND AND WITH_NOKIA_SUPPORT)
    add_executable(usb-device-parse usb-device-parse.c)
    target_link_libraries(usb-device-parse libGammu ${LIBINTL_LIBRARIES})
    add_test(usb-device-parse "${GAMMU_TEST_PATH}/usb-device-parse${GAMMU_TEST_SUFFIX}")
endif (LIBUSB_FOUND AND WITH_NOKIA_SUPPORT)

# Debug testing
add_executable(debug debug.c)
target_link_libraries(debug libGammu ${LIBINTL_LIBRARIES})
add_test(debug "${GAMMU_TEST_PATH}/debug${GAMMU_TEST_SUFFIX}")

# Check error code  descriptions
add_executable(dump-error-codes dump-error-codes.c)
target_link_libraries(dump-error-codes libGammu ${LIBINTL_LIBRARIES})
add_test(dump-error-codes "${GAMMU_TEST_PATH}/dump-error-codes${GAMMU_TEST_SUFFIX}" "-n")

# Check feature code names
add_executable(dump-features dump-features.c)
target_link_libraries(dump-features libGammu ${LIBINTL_LIBRARIES})
add_test(dump-features "${GAMMU_TEST_PATH}/dump-features${GAMMU_TEST_SUFFIX}" "-n")

# Check feature parsing
add_executable(features-parsing features-parsing.c)
target_link_libraries(features-parsing libGammu ${LIBINTL_LIBRARIES})
add_test(features-parsing "${GAMMU_TEST_PATH}/features-parsing${GAMMU_TEST_SUFFIX}" "-n")

# Check network codes decoding
add_executable(network-codes network-codes.c)
target_link_libraries(network-codes libGammu ${LIBINTL_LIBRARIES})
add_test(network-codes "${GAMMU_TEST_PATH}/network-codes${GAMMU_TEST_SUFFIX}" "-n")

if (WITH_BACKUP)
    # smsbackup parsing
    add_executable(smsbackup smsbackup.c)
    target_link_libraries(smsbackup messagedisplay)
    target_link_libraries(smsbackup libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB VCARDS
        RELATIVE "${Gammu_SOURCE_DIR}/tests/smsbackups"
        "${Gammu_SOURCE_DIR}/tests/smsbackups/*.smsbackup")
    list(SORT VCARDS)

    foreach(TESTVCARD ${VCARDS})
        string(REPLACE .smsbackup "" TESTNAME ${TESTVCARD})
        add_test("smsbackup-${TESTNAME}"
            "${GAMMU_TEST_PATH}/smsbackup${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/smsbackups/${TESTVCARD}")
    endforeach(TESTVCARD $VCARDS)
endif (WITH_BACKUP)

if (WITH_BACKUP)
    # vCard parsing
    add_executable(vcard-read vcard-read.c)
    target_link_libraries(vcard-read memorydisplay)
    target_link_libraries(vcard-read libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB VCARDS
        RELATIVE "${Gammu_SOURCE_DIR}/tests/vcards"
        "${Gammu_SOURCE_DIR}/tests/vcards/*.vcf")
    list(SORT VCARDS)

    foreach(TESTVCARD ${VCARDS})
        string(REPLACE vcf backup TESTBACKUP ${TESTVCARD})
        string(REPLACE .vcf "" TESTNAME ${TESTVCARD})
        add_test("vcard-read-${TESTNAME}"
            "${GAMMU_TEST_PATH}/vcard-read${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/vcards/${TESTVCARD}"
            "${Gammu_SOURCE_DIR}/tests/vcards/${TESTBACKUP}")
    endforeach(TESTVCARD $VCARDS)

    file(GLOB VCARDS
        RELATIVE "${Gammu_SOURCE_DIR}/tests/vcards-failing"
        "${Gammu_SOURCE_DIR}/tests/vcards-failing/*.vcf")
    list(SORT VCARDS)

    foreach(TESTVCARD ${VCARDS})
        string(REPLACE vcf backup TESTBACKUP ${TESTVCARD})
        string(REPLACE .vcf "" TESTNAME ${TESTVCARD})
        add_test("vcard-read-${TESTNAME}"
            "${GAMMU_TEST_PATH}/vcard-read${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/vcards-failing/${TESTVCARD}"
            "${Gammu_SOURCE_DIR}/tests/vcards-failing/${TESTBACKUP}")
        set_tests_properties(
            "vcard-read-${TESTNAME}"
            PROPERTIES WILL_FAIL TRUE)
    endforeach(TESTVCARD $VCARDS)

    # LDIF parsing
    add_executable(ldif-read ldif-read.c)
    target_link_libraries(ldif-read memorydisplay)
    target_link_libraries(ldif-read libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB LDIFS
        RELATIVE "${Gammu_SOURCE_DIR}/tests/ldif"
        "${Gammu_SOURCE_DIR}/tests/ldif/*.ldif")
    list(SORT LDIFS)

    foreach(TESTLDIF ${LDIFS})
        string(REPLACE ldif backup TESTBACKUP ${TESTLDIF})
        string(REPLACE .ldif "" TESTNAME ${TESTLDIF})
        add_test("ldif-read-${TESTNAME}"
            "${GAMMU_TEST_PATH}/ldif-read${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/ldif/${TESTLDIF}"
            "${Gammu_SOURCE_DIR}/tests/ldif/${TESTBACKUP}")
    endforeach(TESTLDIF $LDIFS)

endif (WITH_BACKUP)

# [iv]Calendar parsing
if (WITH_BACKUP)
    add_executable(cal-read cal-read.c)
    target_link_libraries(cal-read libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB VCALS
        RELATIVE "${Gammu_SOURCE_DIR}/tests/vcal"
        "${Gammu_SOURCE_DIR}/tests/vcal/*.vcs")
    list(SORT VCALS)

    foreach(TESTVCAL ${VCALS})
        string(REPLACE vcs backup TESTBACKUP ${TESTVCAL})
        string(REPLACE .vcs "" TESTNAME ${TESTVCAL})
        add_test("cal-read-${TESTNAME}"
            "${GAMMU_TEST_PATH}/cal-read${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/vcal/${TESTVCAL}"
            "${Gammu_SOURCE_DIR}/tests/vcal/${TESTBACKUP}")
    endforeach(TESTVCAL $VCALS)

    # List test cases
    file(GLOB VCALS
        RELATIVE "${Gammu_SOURCE_DIR}/tests/vcal"
        "${Gammu_SOURCE_DIR}/tests/vcal/*.ics")
    list(SORT VCALS)

    foreach(TESTVCAL ${VCALS})
        string(REPLACE ics backup TESTBACKUP ${TESTVCAL})
        string(REPLACE .ics "" TESTNAME ${TESTVCAL})
        add_test("cal-read-${TESTNAME}"
            "${GAMMU_TEST_PATH}/cal-read${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/vcal/${TESTVCAL}"
            "${Gammu_SOURCE_DIR}/tests/vcal/${TESTBACKUP}")
    endforeach(TESTVCAL $VCALS)
endif (WITH_BACKUP)

# SMS parsing
if (WITH_NOKIA6110)
    add_executable(sms-nokia-01 sms-nokia-01.c)
    target_link_libraries(sms-nokia-01 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-01 messagedisplay)
    add_test(sms-nokia-01 "${GAMMU_TEST_PATH}/sms-nokia-01${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6110)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-02 sms-nokia-02.c)
    target_link_libraries(sms-nokia-02 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-02 messagedisplay)
    add_test(sms-nokia-02 "${GAMMU_TEST_PATH}/sms-nokia-02${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-03 sms-nokia-03.c)
    target_link_libraries(sms-nokia-03 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-03 messagedisplay)
    add_test(sms-nokia-03 "${GAMMU_TEST_PATH}/sms-nokia-03${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-04 sms-nokia-04.c)
    target_link_libraries(sms-nokia-04 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-04 messagedisplay)
    add_test(sms-nokia-04 "${GAMMU_TEST_PATH}/sms-nokia-04${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-05 sms-nokia-05.c)
    target_link_libraries(sms-nokia-05 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-05 messagedisplay)
    add_test(sms-nokia-05 "${GAMMU_TEST_PATH}/sms-nokia-05${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-06 sms-nokia-06.c)
    target_link_libraries(sms-nokia-06 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-06 messagedisplay)
    add_test(sms-nokia-06 "${GAMMU_TEST_PATH}/sms-nokia-06${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-07 sms-nokia-07.c)
    target_link_libraries(sms-nokia-07 libGammu ${LIBINTL_LIBRARIES})
    add_test(sms-nokia-07 "${GAMMU_TEST_PATH}/sms-nokia-07${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-08 sms-nokia-08.c)
    target_link_libraries(sms-nokia-08 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-08 messagedisplay)
    add_test(sms-nokia-08 "${GAMMU_TEST_PATH}/sms-nokia-08${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-09 sms-nokia-09.c)
    target_link_libraries(sms-nokia-09 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-09 messagedisplay)
    add_test(sms-nokia-09 "${GAMMU_TEST_PATH}/sms-nokia-09${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-10 sms-nokia-10.c)
    target_link_libraries(sms-nokia-10 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-10 messagedisplay)
    add_test(sms-nokia-10 "${GAMMU_TEST_PATH}/sms-nokia-10${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-11 sms-nokia-11.c)
    target_link_libraries(sms-nokia-11 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-11 messagedisplay)
    add_test(sms-nokia-11 "${GAMMU_TEST_PATH}/sms-nokia-11${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-12 sms-nokia-12.c)
    target_link_libraries(sms-nokia-12 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-12 messagedisplay)
    add_test(sms-nokia-12 "${GAMMU_TEST_PATH}/sms-nokia-12${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-13 sms-nokia-13.c)
    target_link_libraries(sms-nokia-13 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-13 messagedisplay)
    add_test(sms-nokia-13 "${GAMMU_TEST_PATH}/sms-nokia-13${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-14 sms-nokia-14.c)
    target_link_libraries(sms-nokia-14 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-14 messagedisplay)
    add_test(sms-nokia-14 "${GAMMU_TEST_PATH}/sms-nokia-14${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-15 sms-nokia-15.c)
    target_link_libraries(sms-nokia-15 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-15 messagedisplay)
    add_test(sms-nokia-15 "${GAMMU_TEST_PATH}/sms-nokia-15${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-16 sms-nokia-16.c)
    target_link_libraries(sms-nokia-16 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-16 messagedisplay)
    add_test(sms-nokia-16 "${GAMMU_TEST_PATH}/sms-nokia-16${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-17 sms-nokia-17.c)
    target_link_libraries(sms-nokia-17 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-17 messagedisplay)
    add_test(sms-nokia-17 "${GAMMU_TEST_PATH}/sms-nokia-17${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6510)
    add_executable(sms-nokia-18 sms-nokia-18.c)
    target_link_libraries(sms-nokia-18 libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-nokia-18 messagedisplay)
    add_test(sms-nokia-18 "${GAMMU_TEST_PATH}/sms-nokia-18${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6510)

if (WITH_NOKIA6110)
# Nokia ringtone
    add_executable(nokia-6110-ringtone nokia-6110-ringtone.c)
    target_link_libraries(nokia-6110-ringtone libGammu ${LIBINTL_LIBRARIES})
    add_test(nokia-6110-ringtone "${GAMMU_TEST_PATH}/nokia-6110-ringtone${GAMMU_TEST_SUFFIX}")
endif (WITH_NOKIA6110)

if (WITH_ATGEN)
    # AT SMS parsing
    add_executable(sms-at-parse sms-at-parse.c)
    target_link_libraries(sms-at-parse libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(sms-at-parse messagedisplay)

    # AT SMS parsing - simple PDU decoder
    add_executable(pdu-decode pdu-decode.c)

    # List test cases for success
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-sms"
        "${Gammu_SOURCE_DIR}/tests/at-sms/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("sms-at-parse-${TESTNAME}"
            "${GAMMU_TEST_PATH}/sms-at-parse${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-sms/${TESTMESSAGE}")
        add_test("pdu-decode-${TESTNAME}"
            "${GAMMU_TEST_PATH}/pdu-decode${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-sms/${TESTMESSAGE}")
    endforeach(TESTMESSAGE $MESSAGES)

    # List test cases for TXT mode
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-sms-txt"
        "${Gammu_SOURCE_DIR}/tests/at-sms-txt/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("sms-at-parse-${TESTNAME}"
            "${GAMMU_TEST_PATH}/sms-at-parse${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-sms-txt/${TESTMESSAGE}"
            "TXT")
    endforeach(TESTMESSAGE $MESSAGES)

    # List test cases for failure
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-sms-failing"
        "${Gammu_SOURCE_DIR}/tests/at-sms-failing/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("sms-at-parse-fail-${TESTNAME}"
            "${GAMMU_TEST_PATH}/sms-at-parse${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-sms-failing/${TESTMESSAGE}")
        add_test("pdu-decode-fail-${TESTNAME}"
            "${GAMMU_TEST_PATH}/pdu-decode${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-sms-failing/${TESTMESSAGE}")
        set_tests_properties(
            "pdu-decode-fail-${TESTNAME}"
            "sms-at-parse-fail-${TESTNAME}"
            PROPERTIES WILL_FAIL TRUE)
    endforeach(TESTMESSAGE $MESSAGES)

    # List test cases
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-sms"
        "${Gammu_SOURCE_DIR}/tests/at-sms/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
    endforeach(TESTMESSAGE $MESSAGES)

    # AT model parsing
    add_executable(get-model-at get-model-at.c)
    target_link_libraries(get-model-at libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-model"
        "${Gammu_SOURCE_DIR}/tests/at-model/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("get-model-at-${TESTNAME}"
            "${GAMMU_TEST_PATH}/get-model-at${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-model/${TESTMESSAGE}")
    endforeach(TESTMESSAGE $MESSAGES)

    # Samsung memory parsing
    add_executable(samsung-get-memory samsung-get-memory.c)
    target_link_libraries(samsung-get-memory libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(samsung-get-memory memorydisplay)

    # List test cases
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/samsung-memory"
        "${Gammu_SOURCE_DIR}/tests/samsung-memory/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("samsung-get-memory-${TESTNAME}"
            "${GAMMU_TEST_PATH}/samsung-get-memory${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/samsung-memory/${TESTMESSAGE}")
    endforeach(TESTMESSAGE $MESSAGES)

    # AT getting of available phone memories
    add_executable(at-get-smsmemories at-get-smsmemories.c)
    target_link_libraries(at-get-smsmemories libGammu ${LIBINTL_LIBRARIES})

    # List test cases for all memories
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-cpms"
        "${Gammu_SOURCE_DIR}/tests/at-cpms/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("at-get-smsmemories-${TESTNAME}"
            "${GAMMU_TEST_PATH}/at-get-smsmemories${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-cpms/${TESTMESSAGE}")
        set_tests_properties("at-get-smsmemories-${TESTNAME}" PROPERTIES
            PASS_REGULAR_EXPRESSION "read: ME : ok, SM : ok, save: ME : ok, SM = ok")
    endforeach(TESTMESSAGE $MESSAGES)

    # List test cases for just SM
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-cpms-sm"
        "${Gammu_SOURCE_DIR}/tests/at-cpms-sm/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("at-get-smsmemories-sm-${TESTNAME}"
            "${GAMMU_TEST_PATH}/at-get-smsmemories${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-cpms-sm/${TESTMESSAGE}")
        set_tests_properties("at-get-smsmemories-sm-${TESTNAME}" PROPERTIES
            PASS_REGULAR_EXPRESSION "read: ME : N/A, SM : ok, save: ME : N/A, SM = ok")
    endforeach(TESTMESSAGE $MESSAGES)

    # AT CNMI parsing
    add_executable(at-cnmi-reply at-cnmi-reply.c)
    target_link_libraries(at-cnmi-reply libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-cnmi"
        "${Gammu_SOURCE_DIR}/tests/at-cnmi/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("at-cnmi-reply-${TESTNAME}"
            "${GAMMU_TEST_PATH}/at-cnmi-reply${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-cnmi/${TESTMESSAGE}")
    endforeach(TESTMESSAGE $MESSAGES)

    # AT CREG parsing
    add_executable(at-creg-reply at-creg-reply.c)
    target_link_libraries(at-creg-reply libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-creg"
        "${Gammu_SOURCE_DIR}/tests/at-creg/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("at-creg-reply-${TESTNAME}"
            "${GAMMU_TEST_PATH}/at-creg-reply${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-creg/${TESTMESSAGE}")
    endforeach(TESTMESSAGE $MESSAGES)

    # AT memory parsing
    add_executable(at-getmemory-reply at-getmemory-reply.c)
    target_link_libraries(at-getmemory-reply libGammu ${LIBINTL_LIBRARIES})
    target_link_libraries(at-getmemory-reply memorydisplay)

    macro(at_getmemory_reply_test _file _charset _test)

    add_test("at-getmemory-reply-${_file}"
            "${GAMMU_TEST_PATH}/at-getmemory-reply${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-getmemory/${_file}.dump"
            "${_charset}")
    set_tests_properties("at-getmemory-reply-${_file}"
        PROPERTIES PASS_REGULAR_EXPRESSION "${_test}")

    endmacro(at_getmemory_reply_test _file _charset _test)

    at_getmemory_reply_test(samsung PCCP437 AsistZahr)
    at_getmemory_reply_test(samsung-p900 PCCP437 "My Tempo")
    at_getmemory_reply_test(with-time UTF8 "Mama GSM")
    at_getmemory_reply_test(with-date-time UTF8 "60122256476")
    at_getmemory_reply_test(ucs2 UCS2 "Stanley Paul")
    at_getmemory_reply_test(ucs2-motorola UCS2 "Virchow Klinikum St. 31")
    at_getmemory_reply_test(nokia-2730 UCS2 "Steve  Vinson")

    # AT USSD replies parsing
    add_executable(at-ussd-reply at-ussd-reply.c)
    target_link_libraries(at-ussd-reply libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-ussd"
        "${Gammu_SOURCE_DIR}/tests/at-ussd/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        string(REGEX REPLACE ".*-(.*)\\.dump" "\\1" PHONE_MODEL ${TESTMESSAGE})
        add_test("at-ussd-reply-${TESTNAME}"
            "${GAMMU_TEST_PATH}/at-ussd-reply${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-ussd/${TESTMESSAGE}" "${PHONE_MODEL}")
    endforeach(TESTMESSAGE $MESSAGES)

    # AT SMSC parsing
    add_executable(get-smsc-at get-smsc-at.c)
    target_link_libraries(get-smsc-at libGammu ${LIBINTL_LIBRARIES})

    # List test cases
    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-smsc"
        "${Gammu_SOURCE_DIR}/tests/at-smsc/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("get-smsc-at-${TESTNAME}"
            "${GAMMU_TEST_PATH}/get-smsc-at${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-smsc/${TESTMESSAGE}")
    endforeach(TESTMESSAGE $MESSAGES)

    file(GLOB MESSAGES
        RELATIVE "${Gammu_SOURCE_DIR}/tests/at-smsc-failing"
        "${Gammu_SOURCE_DIR}/tests/at-smsc-failing/*.dump")
    list(SORT MESSAGES)

    foreach(TESTMESSAGE ${MESSAGES})
        string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
        add_test("get-smsc-at-${TESTNAME}"
            "${GAMMU_TEST_PATH}/get-smsc-at${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/at-smsc-failing/${TESTMESSAGE}")
        set_tests_properties(
            "get-smsc-at-${TESTNAME}"
            PROPERTIES WILL_FAIL TRUE)
    endforeach(TESTMESSAGE $MESSAGES)

    if (WITH_BACKUP)
        # AT SMS encoding
        add_executable(sms-at-encode sms-at-encode.c)
        target_link_libraries(sms-at-encode libGammu ${LIBINTL_LIBRARIES})

        # List test cases
        file(GLOB MESSAGES
            RELATIVE "${Gammu_SOURCE_DIR}/tests/at-sms-encode"
            "${Gammu_SOURCE_DIR}/tests/at-sms-encode/*.backup")
        list(SORT MESSAGES)

        foreach(TESTMESSAGE ${MESSAGES})
            string(REPLACE .backup "" TESTNAME ${TESTMESSAGE})
            string(REPLACE backup dump TESTDUMP ${TESTMESSAGE})
            add_test("sms-at-encode-${TESTNAME}"
                "${GAMMU_TEST_PATH}/sms-at-encode${GAMMU_TEST_SUFFIX}"
                "${Gammu_SOURCE_DIR}/tests/at-sms-encode/${TESTMESSAGE}"
                "${Gammu_SOURCE_DIR}/tests/at-sms-encode/${TESTDUMP}")
        endforeach(TESTMESSAGE $MESSAGES)
    endif (WITH_BACKUP)
endif (WITH_ATGEN)

if (WITH_OBEXGEN)
    # OBEX entries splitting
    add_executable(obex-vcard-split obex-vcard-split.c)
    target_link_libraries(obex-vcard-split libGammu ${LIBINTL_LIBRARIES})

    # Tests
    add_test(obex-vcard-split-se-3
            "${GAMMU_TEST_PATH}/obex-vcard-split${GAMMU_TEST_SUFFIX}"
            "${Gammu_SOURCE_DIR}/tests/vcards/se-3.vcf"
            499)

endif (WITH_OBEXGEN)

# SMS encoding
add_executable(sms-encode-decode sms-encode-decode.c)
target_link_libraries(sms-encode-decode libGammu ${LIBINTL_LIBRARIES})
target_link_libraries(sms-encode-decode messagedisplay)
add_test(sms-encode-decode "${GAMMU_TEST_PATH}/sms-encode-decode${GAMMU_TEST_SUFFIX}")

# SMS encoding from commandline
add_executable(sms-cmdline sms-cmdline.c)
target_link_libraries(sms-cmdline libGammu ${LIBINTL_LIBRARIES})
target_link_libraries(sms-cmdline messagedisplay)
target_link_libraries(sms-cmdline messagecmdline)

add_test(sms-cmdline-TEXT "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213 -text aaafdsfdfasd)
set_tests_properties(sms-cmdline-TEXT PROPERTIES
    PASS_REGULAR_EXPRESSION "Remote number        : \"213\"")

add_test(sms-cmdline-TEXT-smsc "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213 -text aaafdsfdfasd -smscnumber 132465)
set_tests_properties(sms-cmdline-TEXT-smsc PROPERTIES
PASS_REGULAR_EXPRESSION "Remote number        : \"213\"")

add_test(sms-cmdline-TEXT-textutf8 "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213 -unicode -textutf8 "Zkouška šíleně žlutého koně.")
set_tests_properties(sms-cmdline-TEXT-textutf8 PROPERTIES
    PASS_REGULAR_EXPRESSION "Coding               : Unicode \\(no compression\\)")


add_test(sms-cmdline-TEXT-16 "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213
        -text fdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdd
        -autolen 600 -16bit)
set_tests_properties(sms-cmdline-TEXT-16 PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : Concatenated \\(linked\\) message, ID \\(16 bit\\) [0-9]*, 2 parts")

add_test(sms-cmdline-TEXT-autolen "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213
        -text fdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasddfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasddfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdd
        -autolen 200)
set_tests_properties(sms-cmdline-TEXT-autolen PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : Concatenated \\(linked\\) message, ID \\(8 bit\\) [0-9]*, 2 parts")

add_test(sms-cmdline-TEXT-len "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213
        -text fdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdd
        -len 100)
set_tests_properties(sms-cmdline-TEXT-len PROPERTIES
    FAIL_REGULAR_EXPRESSION "User Data Header     : Concatenated \\(linked\\) message")

add_test(sms-cmdline-TEXT-len-1 "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213
        -text fdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdfdasfasfasfdsafasdfasdffasdfasdfasaaafdsfdfasdd
        -len -1)
set_tests_properties(sms-cmdline-TEXT-len-1 PROPERTIES
    FAIL_REGULAR_EXPRESSION "Wrong message length \\(\"-1\"\\)"
    WILL_FAIL TRUE)

add_test(sms-cmdline-TEXT-unicode "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    TEXT 213 -text aaafdsfdfasd -unicode)
set_tests_properties(sms-cmdline-TEXT-unicode PROPERTIES
    PASS_REGULAR_EXPRESSION "Coding               : Unicode \\(no compression\\)")

add_test(sms-cmdline-TEXT-voice "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    text 213 -text aaafdsfdfasd -unicode -enablevoice)
set_tests_properties(sms-cmdline-TEXT-voice PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : Enables voice indicator")

add_test(sms-cmdline-EMS "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    EMS 213 -text "aaafdsfdfasddsadsadsadsadijfdsalkfjla sdjflkjlfk fdsaf dsa fdsaf dsafafdasfsadfdsaf dsafdsa fdsaf dasfdsafdsafdsaf dsafdsaf daaafdsfdfasddsadsadsadsadijfdsalkfjla sdjflkjlfk fdsaf dsa fdsaf dsafafdasfsadfdsaf dsafdsa fdsaf dasfdsafdsafdsaf dsafdsaf dsafdsaf")
set_tests_properties(sms-cmdline-EMS PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : Concatenated \\(linked\\) message, ID \\(8 bit\\) [0-9]*, 2 parts")

add_test(sms-cmdline-EMS-empty "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    EMS 213)
set_tests_properties(sms-cmdline-EMS-empty PROPERTIES
    FAIL_REGULAR_EXPRESSION "Entry is empty"
    WILL_FAIL TRUE)

add_test(sms-cmdline-EMS-misc "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    EMS 213
        -defsound 99
        -defanimation 1
        -protected 0
        -text "foo" -format l
        -text bar -format r
        -text moo -format b
        -text mee -format i
        -text bee -format u
        -text geee -format t)
set_tests_properties(sms-cmdline-EMS-misc PROPERTIES
    PASS_REGULAR_EXPRESSION "EMS sound ID         : 99"
    )

add_test(sms-cmdline-EMS-ring "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    EMS 54654654 -protected 1 -toneSElong  ${RINGTONE_TEST_FILE})

add_test(sms-cmdline-EMS-unicodefile "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    EMS 213 -unicodefiletext ${Gammu_SOURCE_DIR}/tests/text-unicode.txt -unicode)
set_tests_properties(sms-cmdline-EMS-unicodefile PROPERTIES
    PASS_REGULAR_EXPRESSION "Coding               : Unicode \\(no compression\\)")

add_test(sms-cmdline-RINGTONE "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    RINGTONE 54654654 ${RINGTONE_TEST_FILE})
set_tests_properties(sms-cmdline-RINGTONE PROPERTIES
    PASS_REGULAR_EXPRESSION "Ringtone \"AxelF\"")

add_test(sms-cmdline-MMS "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    MMSINDICATOR 800123456 http://wammu.eu/ Wammu Gammu)
set_tests_properties(sms-cmdline-MMS PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : MMS indicator, ID \\(8 bit\\) [0-9]*, part 1 of 1")

add_test(sms-cmdline-WAP "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    WAPINDICATOR 800123456 http://wammu.eu/ Wammu)
set_tests_properties(sms-cmdline-WAP PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : MMS indicator, ID \\(8 bit\\) [0-9]*, part 1 of 1")

if (WITH_BACKUP)
    add_test(sms-cmdline-TODO "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
        TODO 132132  ${Gammu_SOURCE_DIR}/tests/vcal/02.vcs  1)
    set_tests_properties(sms-cmdline-TODO PROPERTIES
        PASS_REGULAR_EXPRESSION "User Data Header     : Nokia calendar note, ID \\(8 bit\\) [0-9]*, part 2 of 2")

    add_test(sms-cmdline-CALENDAR "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
        CALENDAR 132132  ${Gammu_SOURCE_DIR}/tests/vcal/UK32Holidays.ics  30)
    set_tests_properties(sms-cmdline-CALENDAR PROPERTIES
        PASS_REGULAR_EXPRESSION "SUMMARY:Bank Holiday")

    add_test(sms-cmdline-VCARD "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
        VCARD21 132132  ${Gammu_SOURCE_DIR}/tests/vcards/yahoo.vcf ME 1)
    set_tests_properties(sms-cmdline-VCARD PROPERTIES
        PASS_REGULAR_EXPRESSION "User Data Header     : Concatenated \\(linked\\) message, ID \\(8 bit\\) [0-9]*, 2 parts")
endif (WITH_BACKUP)

add_test(sms-cmdline-SMSTEMPLATE "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    SMSTEMPLATE 213 -text aaafdsfdfasd)
# Not sure if this is really correct...
set_tests_properties(sms-cmdline-SMSTEMPLATE PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : User UDH")

add_test(sms-cmdline-PICTURE "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    PICTURE 213 ${LOGO_TEST_FILE})
set_tests_properties(sms-cmdline-PICTURE PROPERTIES
    PASS_REGULAR_EXPRESSION "###################   ##    ##     #     #     ##   ## ### ##   ###   ##")

add_test(sms-cmdline-OPERATOR "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    OPERATOR 213 ${LOGO_TEST_FILE} -netcode "230 03")
set_tests_properties(sms-cmdline-OPERATOR PROPERTIES
    PASS_REGULAR_EXPRESSION "Operator logo for 230 03 network \\(Vodafone, Czech Republic\\)")

add_test(sms-cmdline-CALLER "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    CALLER 213 ${LOGO_TEST_FILE})
set_tests_properties(sms-cmdline-CALLER PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : Nokia caller logo")

add_test(sms-cmdline-ANIMATION "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    ANIMATION 213 6
        ${LOGO_TEST_FILE}
        ${LOGO_TEST_FILE}
        ${LOGO_TEST_FILE}
        ${LOGO_TEST_FILE}
        ${LOGO_TEST_FILE}
        ${LOGO_TEST_FILE})
set_tests_properties(sms-cmdline-ANIMATION PROPERTIES
    PASS_REGULAR_EXPRESSION "Number of messages: 14")

add_test(sms-cmdline-PROFILE "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
    PROFILE 213
        -bitmap ${LOGO_TEST_FILE}
        -ringtone ${RINGTONE_TEST_FILE})
set_tests_properties(sms-cmdline-PROFILE PROPERTIES
    PASS_REGULAR_EXPRESSION "User Data Header     : Nokia profile, ID \\(8 bit\\) [0-9]*, 3 parts")

if (WITH_BACKUP)
    add_test(sms-cmdline-BOOKMARK "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
        BOOKMARK 213 ${Gammu_SOURCE_DIR}/tests/misc/wap-bookmark.backup 1)
    set_tests_properties(sms-cmdline-BOOKMARK PROPERTIES
        PASS_REGULAR_EXPRESSION "User Data Header     : Nokia WAP bookmark")

    add_test(sms-cmdline-WAPSETTINGS "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
        WAPSETTINGS 213 ${Gammu_SOURCE_DIR}/tests/misc/wap-settings.backup 1 GPRS)
    set_tests_properties(sms-cmdline-WAPSETTINGS PROPERTIES
        PASS_REGULAR_EXPRESSION "User Data Header     : Nokia WAP bookmark or WAP/MMS settings, ID \\(8 bit\\) [0-9]*, 2 parts")

    add_test(sms-cmdline-MMSSETTINGS "${GAMMU_TEST_PATH}/sms-cmdline${GAMMU_TEST_SUFFIX}"
        MMSSETTINGS 213 ${Gammu_SOURCE_DIR}/tests/misc/mms-settings.backup 1)
    set_tests_properties(sms-cmdline-MMSSETTINGS PROPERTIES
        PASS_REGULAR_EXPRESSION "User Data Header     : Nokia WAP bookmark or WAP/MMS settings, ID \\(8 bit\\) [0-9]*, 2 parts")
endif (WITH_BACKUP)

if (WITH_ATGEN)
    # Samsung parser tests
    add_executable(at-samsung at-samsung.c)
    target_link_libraries(at-samsung libGammu ${LIBINTL_LIBRARIES})
    add_test(at-samsung "${GAMMU_TEST_PATH}/at-samsung${GAMMU_TEST_SUFFIX}")

    # Motorola parser tests
    add_executable(at-motorola at-motorola.c)
    target_link_libraries(at-motorola libGammu ${LIBINTL_LIBRARIES})
    add_test(at-motorola "${GAMMU_TEST_PATH}/at-motorola${GAMMU_TEST_SUFFIX}")

    # AT parser tests
    add_executable(at-parser at-parser.c)
    target_link_libraries(at-parser libGammu ${LIBINTL_LIBRARIES})
    add_test(at-parser "${GAMMU_TEST_PATH}/at-parser${GAMMU_TEST_SUFFIX}")

    # AT dispatch tests
    add_executable(at-dispatch at-dispatch.c)
    target_link_libraries(at-dispatch libGammu ${LIBINTL_LIBRARIES})
    add_test(at-dispatch "${GAMMU_TEST_PATH}/at-dispatch${GAMMU_TEST_SUFFIX}")

    # AT text encoding/decoding
    add_executable(at-charset at-charset.c)
    target_link_libraries(at-charset libGammu ${LIBINTL_LIBRARIES})
    add_test(at-charset "${GAMMU_TEST_PATH}/at-charset${GAMMU_TEST_SUFFIX}")
endif (WITH_ATGEN)

# Line parser tests
add_executable(line-splitting line-splitting.c)
target_link_libraries(line-splitting libGammu ${LIBINTL_LIBRARIES})
add_test(line-splitting "${GAMMU_TEST_PATH}/line-splitting${GAMMU_TEST_SUFFIX}")

# Config file parsing
add_executable(config config.c)
target_link_libraries(config libGammu ${LIBINTL_LIBRARIES})
file(GLOB CONFIGS
    RELATIVE "${Gammu_SOURCE_DIR}/tests/configs"
    "${Gammu_SOURCE_DIR}/tests/configs/tabs-*")
list(SORT CONFIGS)

foreach(TESTCONFIG ${CONFIGS})
    add_test(config-${TESTCONFIG} "${GAMMU_TEST_PATH}/config${GAMMU_TEST_SUFFIX}" "${Gammu_SOURCE_DIR}/tests/configs/${TESTCONFIG}")
    set_tests_properties(config-${TESTCONFIG} PROPERTIES
        PASS_REGULAR_EXPRESSION "DEBUG_LEVEL: 'textall'")
endforeach(TESTCONFIG $CONFIGS)


# INI file parsing
add_executable(inifile inifile.c)
target_link_libraries(inifile libGammu ${LIBINTL_LIBRARIES})
file(GLOB INIFILES
    RELATIVE "${Gammu_SOURCE_DIR}/tests/inifiles"
    "${Gammu_SOURCE_DIR}/tests/inifiles/*.ini")
list(SORT INIFILES)

foreach(TESTINIFILE ${INIFILES})
    add_test(inifile-${TESTINIFILE} "${GAMMU_TEST_PATH}/inifile${GAMMU_TEST_SUFFIX}" "${Gammu_SOURCE_DIR}/tests/inifiles/${TESTINIFILE}")
endforeach(TESTINIFILE $INIFILES)

# Examples
add_executable(phone-info "${Gammu_SOURCE_DIR}/docs/examples/phone-info.c")
target_link_libraries(phone-info libGammu ${LIBINTL_LIBRARIES})
add_executable(custom-config "${Gammu_SOURCE_DIR}/docs/examples/custom-config.c")
target_link_libraries(custom-config libGammu ${LIBINTL_LIBRARIES})
add_executable(sms-send "${Gammu_SOURCE_DIR}/docs/examples/sms-send.c")
target_link_libraries(sms-send libGammu ${LIBINTL_LIBRARIES})
add_executable(long-sms "${Gammu_SOURCE_DIR}/docs/examples/long-sms.c")
target_link_libraries(long-sms libGammu ${LIBINTL_LIBRARIES})
add_executable(sms-read "${Gammu_SOURCE_DIR}/docs/examples/sms-read.c")
target_link_libraries(sms-read libGammu ${LIBINTL_LIBRARIES})
add_executable(smsd "${Gammu_SOURCE_DIR}/docs/examples/smsd.c")
target_link_libraries(smsd libGammu ${LIBINTL_LIBRARIES} gsmsd)

# Examples tests, works with dummy phone
if (WITH_BACKUP)
    add_test(phone-info "${GAMMU_TEST_PATH}/phone-info${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
    add_test(custom-config "${GAMMU_TEST_PATH}/custom-config${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammu-dummy" none dummy)
    add_test(sms-send "${GAMMU_TEST_PATH}/sms-send${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
    add_test(long-sms "${GAMMU_TEST_PATH}/long-sms${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
    add_test(sms-read "${GAMMU_TEST_PATH}/sms-read${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
endif (WITH_BACKUP)


# Auto generated include tests begin
# Do not modify this section, change gen-include-test.sh instead

# Test for header gammu-backup.h
add_executable(include-backup include-backup.c)
target_link_libraries(include-backup libGammu ${LIBINTL_LIBRARIES})
add_test(include-backup "${GAMMU_TEST_PATH}/include-backup${GAMMU_TEST_SUFFIX}")

# Test for header gammu-bitmap.h
add_executable(include-bitmap include-bitmap.c)
target_link_libraries(include-bitmap libGammu ${LIBINTL_LIBRARIES})
add_test(include-bitmap "${GAMMU_TEST_PATH}/include-bitmap${GAMMU_TEST_SUFFIX}")

# Test for header gammu-calendar.h
add_executable(include-calendar include-calendar.c)
target_link_libraries(include-calendar libGammu ${LIBINTL_LIBRARIES})
add_test(include-calendar "${GAMMU_TEST_PATH}/include-calendar${GAMMU_TEST_SUFFIX}")

# Test for header gammu-callback.h
add_executable(include-callback include-callback.c)
target_link_libraries(include-callback libGammu ${LIBINTL_LIBRARIES})
add_test(include-callback "${GAMMU_TEST_PATH}/include-callback${GAMMU_TEST_SUFFIX}")

# Test for header gammu-call.h
add_executable(include-call include-call.c)
target_link_libraries(include-call libGammu ${LIBINTL_LIBRARIES})
add_test(include-call "${GAMMU_TEST_PATH}/include-call${GAMMU_TEST_SUFFIX}")

# Test for header gammu-category.h
add_executable(include-category include-category.c)
target_link_libraries(include-category libGammu ${LIBINTL_LIBRARIES})
add_test(include-category "${GAMMU_TEST_PATH}/include-category${GAMMU_TEST_SUFFIX}")

# Test for header gammu-datetime.h
add_executable(include-datetime include-datetime.c)
target_link_libraries(include-datetime libGammu ${LIBINTL_LIBRARIES})
add_test(include-datetime "${GAMMU_TEST_PATH}/include-datetime${GAMMU_TEST_SUFFIX}")

# Test for header gammu-debug.h
add_executable(include-debug include-debug.c)
target_link_libraries(include-debug libGammu ${LIBINTL_LIBRARIES})
add_test(include-debug "${GAMMU_TEST_PATH}/include-debug${GAMMU_TEST_SUFFIX}")

# Test for header gammu-error.h
add_executable(include-error include-error.c)
target_link_libraries(include-error libGammu ${LIBINTL_LIBRARIES})
add_test(include-error "${GAMMU_TEST_PATH}/include-error${GAMMU_TEST_SUFFIX}")

# Test for header gammu-file.h
add_executable(include-file include-file.c)
target_link_libraries(include-file libGammu ${LIBINTL_LIBRARIES})
add_test(include-file "${GAMMU_TEST_PATH}/include-file${GAMMU_TEST_SUFFIX}")

# Test for header gammu-info.h
add_executable(include-info include-info.c)
target_link_libraries(include-info libGammu ${LIBINTL_LIBRARIES})
add_test(include-info "${GAMMU_TEST_PATH}/include-info${GAMMU_TEST_SUFFIX}")

# Test for header gammu-inifile.h
add_executable(include-inifile include-inifile.c)
target_link_libraries(include-inifile libGammu ${LIBINTL_LIBRARIES})
add_test(include-inifile "${GAMMU_TEST_PATH}/include-inifile${GAMMU_TEST_SUFFIX}")

# Test for header gammu-keys.h
add_executable(include-keys include-keys.c)
target_link_libraries(include-keys libGammu ${LIBINTL_LIBRARIES})
add_test(include-keys "${GAMMU_TEST_PATH}/include-keys${GAMMU_TEST_SUFFIX}")

# Test for header gammu-limits.h
add_executable(include-limits include-limits.c)
target_link_libraries(include-limits libGammu ${LIBINTL_LIBRARIES})
add_test(include-limits "${GAMMU_TEST_PATH}/include-limits${GAMMU_TEST_SUFFIX}")

# Test for header gammu-memory.h
add_executable(include-memory include-memory.c)
target_link_libraries(include-memory libGammu ${LIBINTL_LIBRARIES})
add_test(include-memory "${GAMMU_TEST_PATH}/include-memory${GAMMU_TEST_SUFFIX}")

# Test for header gammu-message.h
add_executable(include-message include-message.c)
target_link_libraries(include-message libGammu ${LIBINTL_LIBRARIES})
add_test(include-message "${GAMMU_TEST_PATH}/include-message${GAMMU_TEST_SUFFIX}")

# Test for header gammu-misc.h
add_executable(include-misc include-misc.c)
target_link_libraries(include-misc libGammu ${LIBINTL_LIBRARIES})
add_test(include-misc "${GAMMU_TEST_PATH}/include-misc${GAMMU_TEST_SUFFIX}")

# Test for header gammu-nokia.h
add_executable(include-nokia include-nokia.c)
target_link_libraries(include-nokia libGammu ${LIBINTL_LIBRARIES})
add_test(include-nokia "${GAMMU_TEST_PATH}/include-nokia${GAMMU_TEST_SUFFIX}")

# Test for header gammu-ringtone.h
add_executable(include-ringtone include-ringtone.c)
target_link_libraries(include-ringtone libGammu ${LIBINTL_LIBRARIES})
add_test(include-ringtone "${GAMMU_TEST_PATH}/include-ringtone${GAMMU_TEST_SUFFIX}")

# Test for header gammu-security.h
add_executable(include-security include-security.c)
target_link_libraries(include-security libGammu ${LIBINTL_LIBRARIES})
add_test(include-security "${GAMMU_TEST_PATH}/include-security${GAMMU_TEST_SUFFIX}")

# Test for header gammu-settings.h
add_executable(include-settings include-settings.c)
target_link_libraries(include-settings libGammu ${LIBINTL_LIBRARIES})
add_test(include-settings "${GAMMU_TEST_PATH}/include-settings${GAMMU_TEST_SUFFIX}")

# Test for header gammu-smsd.h
add_executable(include-smsd include-smsd.c)
target_link_libraries(include-smsd libGammu ${LIBINTL_LIBRARIES})
add_test(include-smsd "${GAMMU_TEST_PATH}/include-smsd${GAMMU_TEST_SUFFIX}")

# Test for header gammu-statemachine.h
add_executable(include-statemachine include-statemachine.c)
target_link_libraries(include-statemachine libGammu ${LIBINTL_LIBRARIES})
add_test(include-statemachine "${GAMMU_TEST_PATH}/include-statemachine${GAMMU_TEST_SUFFIX}")

# Test for header gammu-types.h
add_executable(include-types include-types.c)
target_link_libraries(include-types libGammu ${LIBINTL_LIBRARIES})
add_test(include-types "${GAMMU_TEST_PATH}/include-types${GAMMU_TEST_SUFFIX}")

# Test for header gammu-unicode.h
add_executable(include-unicode include-unicode.c)
target_link_libraries(include-unicode libGammu ${LIBINTL_LIBRARIES})
add_test(include-unicode "${GAMMU_TEST_PATH}/include-unicode${GAMMU_TEST_SUFFIX}")

# Test for header gammu-wap.h
add_executable(include-wap include-wap.c)
target_link_libraries(include-wap libGammu ${LIBINTL_LIBRARIES})
add_test(include-wap "${GAMMU_TEST_PATH}/include-wap${GAMMU_TEST_SUFFIX}")

# Auto generated include tests end

# Test for GetInt
add_executable(getint getint.c)
target_link_libraries(getint cmdline)
set(GETINT_PASS 1 23213 3213213 -321312 -1)
set(GETINT_FAIL 1a 24432f xxx foo 3243243243243243232432432432432)
foreach(NUM ${GETINT_PASS})
    add_test(getint-${NUM} "${GAMMU_TEST_PATH}/getint${GAMMU_TEST_SUFFIX}" "${NUM}")
    set_tests_properties(
        getint-${NUM}
        PROPERTIES
        PASS_REGULAR_EXPRESSION "Result: ${NUM}")
endforeach(NUM ${GETINT_PASS})
foreach(NUM ${GETINT_FAIL})
    add_test(getint-${NUM} "${GAMMU_TEST_PATH}/getint${GAMMU_TEST_SUFFIX}" "${NUM}")
    set_tests_properties(
        getint-${NUM}
        PROPERTIES WILL_FAIL TRUE)
endforeach(NUM ${GETINT_FAIL})

# Test for locking, only on !WIN32 and if we can write to lock dir
if (NOT WIN32)
    execute_process(COMMAND test -w /var/lock/ RESULT_VARIABLE VAR_LOCK_WRITABLE)
    if (VAR_LOCK_WRITABLE EQUAL 0)
        add_executable(locking locking.c)
        target_link_libraries(locking libGammu ${LIBINTL_LIBRARIES})
        add_test(locking "${GAMMU_TEST_PATH}/locking${GAMMU_TEST_SUFFIX}")
    else (VAR_LOCK_WRITABLE EQUAL 0)
        message("/var/lock is not writable, skipping locking tests!")
    endif (VAR_LOCK_WRITABLE EQUAL 0)
endif (NOT WIN32)
