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

include(SetupDummyPhone)

# Scripts need to be in same directory as built gammu module!


if (WITH_BACKUP)
    configure_file("examples/backup-convertor.py" "${CMAKE_CURRENT_BINARY_DIR}/test-backup-convertor.py" COPY_ONLY)
    file(GLOB VFORMATS "${CMAKE_CURRENT_SOURCE_DIR}/../tests/vcards/*.vcf"
        "${CMAKE_CURRENT_SOURCE_DIR}/../tests/vcal/*.ics"
        "${CMAKE_CURRENT_SOURCE_DIR}/../tests/vcal/*.vcs")
    foreach(VCF ${VFORMATS})
        get_filename_component(TESTNAME "${VCF}" NAME_WE)
        get_filename_component(TYPE "${VCF}" EXT)
        add_test("py-backup-${TESTNAME}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-backup-convertor.py" "${VCF}" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.backup")
        add_test("py-backup-${TESTNAME}-backup" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-backup-convertor.py" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.backup" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}-backup.backup")
        if (${TYPE} STREQUAL .vcf)
            foreach (EXT lmb vcf ldif)
                add_test("py-backup-${TESTNAME}-${EXT}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-backup-convertor.py" "${VCF}" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.${EXT}")
                add_test("py-backup-${TESTNAME}-${EXT}-backup" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-backup-convertor.py" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.${EXT}" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}-${EXT}.backup")
            endforeach (EXT)
        else (${TYPE} STREQUAL .vcf)
            foreach (EXT vcs ics)
                add_test("py-backup-${TESTNAME}-${EXT}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-backup-convertor.py" "${VCF}" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.${EXT}")
                add_test("py-backup-${TESTNAME}-${EXT}-backup" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-backup-convertor.py" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.${EXT}" "${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}-${EXT}.backup")
            endforeach (EXT)
        endif (${TYPE} STREQUAL .vcf)
    endforeach(VCF)
endif (WITH_BACKUP)

configure_file("examples/pdu-decoder.py" "${CMAKE_CURRENT_BINARY_DIR}/pdu-decoder.py" COPY_ONLY)
add_test("py-pdu-decode"  ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/pdu-decoder.py" "079124602009999002AB098106845688F8907080517375809070805183018000")

configure_file("examples/sms-encode-decode.py" "${CMAKE_CURRENT_BINARY_DIR}/test-sms-encode-decode.py" COPY_ONLY)
add_test("py-sms-encode-decode" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-sms-encode-decode.py")
set_tests_properties("py-sms-encode-decode" PROPERTIES FAIL_REGULAR_EXPRESSION "Comparsion: False")

configure_file("examples/sms-encode-decode-unicode.py" "${CMAKE_CURRENT_BINARY_DIR}/test-sms-encode-decode-unicode.py" COPY_ONLY)
add_test("py-sms-encode-decode-unicode" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-sms-encode-decode-unicode.py")
set_tests_properties("py-sms-encode-decode-unicode" PROPERTIES FAIL_REGULAR_EXPRESSION "Comparsion: False")

configure_file("examples/sms-encode-decode-gsm.py" "${CMAKE_CURRENT_BINARY_DIR}/test-sms-encode-decode-gsm.py" COPY_ONLY)
add_test("py-sms-encode-decode-gsm" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-sms-encode-decode-gsm.py")
set_tests_properties("py-sms-encode-decode-gsm" PROPERTIES FAIL_REGULAR_EXPRESSION "Comparsion: False")

configure_file("examples/sms-link.py" "${CMAKE_CURRENT_BINARY_DIR}/test-sms-link.py" COPY_ONLY)
add_test("py-sms-link" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-sms-link.py")
set_tests_properties("py-sms-link" PROPERTIES PASS_REGULAR_EXPRESSION "Comparsion: True")

if (WITH_BACKUP)
    configure_file("examples/listfilesystem.py" "${CMAKE_CURRENT_BINARY_DIR}/test-listfilesystem.py" COPY_ONLY)
    add_test("py-listfilesystem" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-listfilesystem.py" -c "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
    set_tests_properties("py-listfilesystem" PROPERTIES PASS_REGULAR_EXPRESSION "     .    .-- Folder \"dir1-2-3\"")
    add_test("py-listfilesystem-f" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-listfilesystem.py" -c "${CMAKE_CURRENT_BINARY_DIR}/.gammurc" -f)
    set_tests_properties("py-listfilesystem-f" PROPERTIES PASS_REGULAR_EXPRESSION "dir2/dir2-5/file4")

    configure_file("examples/data/cgi.jpg" "${CMAKE_CURRENT_BINARY_DIR}/cgi.jpg" COPY_ONLY)
    configure_file("examples/filesystem-test.py" "${CMAKE_CURRENT_BINARY_DIR}/test-filesystem-test.py" COPY_ONLY)
    add_test("py-filesystem-test" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-filesystem-test.py" -c "${CMAKE_CURRENT_BINARY_DIR}/.gammurc" -f testdir -t "${CMAKE_CURRENT_BINARY_DIR}/cgi.jpg")

    configure_file("examples/dummy-phone.py" "${CMAKE_CURRENT_BINARY_DIR}/test-dummy-phone.py" COPY_ONLY)
    add_test("py-dummy-phone" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-dummy-phone.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
    #set_tests_properties("py-dummy-phone" PROPERTIES PASS_REGULAR_EXPRESSION "Comparsion: True")

    configure_file("examples/vcs.py" "${CMAKE_CURRENT_BINARY_DIR}/test-vcs.py" COPY_ONLY)
    add_test("py-vcs" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-vcs.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")

    configure_file("examples/worker.py" "${CMAKE_CURRENT_BINARY_DIR}/test-worker.py" COPY_ONLY)
    add_test("py-worker" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-worker.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")

    configure_file("examples/service-numbers.py" "${CMAKE_CURRENT_BINARY_DIR}/service-numbers.py" COPY_ONLY)
    add_test("py-service-numbers" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/service-numbers.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc" "1234")

    configure_file("examples/batteryinfo.py" "${CMAKE_CURRENT_BINARY_DIR}/batteryinfo.py" COPY_ONLY)
    add_test("py-batteryinfo" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/batteryinfo.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")

    configure_file("examples/sendsms.py" "${CMAKE_CURRENT_BINARY_DIR}/sendsms.py" COPY_ONLY)
    add_test("py-sendsms" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/sendsms.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc" "+420800123456")

    configure_file("examples/sendlongsms.py" "${CMAKE_CURRENT_BINARY_DIR}/sendlongsms.py" COPY_ONLY)
    add_test("py-sendlongsms" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/sendlongsms.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc" "+420800123456")

    configure_file("examples/dialvoice.py" "${CMAKE_CURRENT_BINARY_DIR}/dialvoice.py" COPY_ONLY)
    add_test("py-dialvoice" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/dialvoice.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc" "1234")

    configure_file("examples/setdiverts.py" "${CMAKE_CURRENT_BINARY_DIR}/setdiverts.py" COPY_ONLY)
    add_test("py-setdiverts" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/setdiverts.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc" "1234")

    configure_file("examples/getdiverts.py" "${CMAKE_CURRENT_BINARY_DIR}/getdiverts.py" COPY_ONLY)
    add_test("py-getdiverts" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/getdiverts.py" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
endif (WITH_BACKUP)

configure_file("examples/setconfig.py" "${CMAKE_CURRENT_BINARY_DIR}/setconfig.py" COPY_ONLY)
add_test("py-setconfig" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/setconfig.py")

configure_file("examples/decodesms.py" "${CMAKE_CURRENT_BINARY_DIR}/decodesms.py" COPY_ONLY)
add_test("py-decodesms" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/decodesms.py")

if (LIBDBI_FOUND AND SQLITE_BIN AND WITH_BACKUP)
    configure_file("examples/smsd-testing.py" "${CMAKE_CURRENT_BINARY_DIR}/test-smsd-testing.py" @ONLY)
    add_test("py-smsd-testing" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/test-smsd-testing.py")
endif (LIBDBI_FOUND AND SQLITE_BIN AND WITH_BACKUP)

add_test("py-smscounter-foobar" ${PYTHON_EXECUTABLE} -c "import gammu; print gammu.SMSCounter('foobar')")
set_tests_properties("py-smscounter-foobar" PROPERTIES PASS_REGULAR_EXPRESSION "\(1, 154\)")

add_test("py-smscounter-long" ${PYTHON_EXECUTABLE} -c "import gammu; print gammu.SMSCounter('foobar fjsa;kjfkasdjfkljsklfjaskdljfkljasdfkljqilui143uu51o23rjhskdf jasdklfjasdklf jasdfkljasdlkfj;asd;lfjaskdljf431ou983jdfaskljfklsdjdkljasfl sdfjasdfkl jafklsda')")
set_tests_properties("py-smscounter-long" PROPERTIES PASS_REGULAR_EXPRESSION "\(2, 156\)")
