diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1189,3 +1189,7 @@ if (SHOULD_BUILD_DEVEL_HEADERS) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/KoConfig.h DESTINATION ${INCLUDE_INSTALL_DIR}/calligra COMPONENT Devel) endif() + +if (BUILD_TESTING) + add_subdirectory(tests) +endif(BUILD_TESTING) diff --git a/tests/.i18n b/tests/.i18n new file mode 100644 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,30 @@ + +find_program(BASH_PROGRAM bash) +find_program(XGETTEXT_PROGRAM xgettext) +find_program(MSGCAT_PROGRAM msgcat) + +if (BASH_PROGRAM AND XGETTEXT_PROGRAM AND MSGCAT_PROGRAM) + macro(CALLIGRA_ADD_UNIT_TEST _TEST_NAME) + add_custom_target(${_TEST_NAME} ALL + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${_TEST_NAME}.cpp" "${CMAKE_CURRENT_BINARY_DIR}/${_TEST_NAME}.cpp" + COMMENT "Copy test files" VERBATIM + ) + add_test(${_TEST_NAME} ${BASH_PROGRAM} "${CMAKE_CURRENT_SOURCE_DIR}/${_TEST_NAME}.sh" + "${CMAKE_SOURCE_DIR}/calligra_xgettext.sh" + "${XGETTEXT_PROGRAM}" + "${MSGCAT_PROGRAM}" + "${CMAKE_CURRENT_BINARY_DIR}/po" + ) + endmacro() + + # create the podir + add_custom_target(podir ALL + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/po + COMMENT "Create podir" VERBATIM) + + # add tests here + CALLIGRA_ADD_UNIT_TEST(test_i18n) + CALLIGRA_ADD_UNIT_TEST(test_kundo2_i18n) + CALLIGRA_ADD_UNIT_TEST(test_kundo2_i18nc_long) + +endif() diff --git a/tests/test_i18n.cpp b/tests/test_i18n.cpp new file mode 100644 --- /dev/null +++ b/tests/test_i18n.cpp @@ -0,0 +1 @@ +i18n("normal i18n"); diff --git a/tests/test_i18n.sh b/tests/test_i18n.sh new file mode 100644 --- /dev/null +++ b/tests/test_i18n.sh @@ -0,0 +1,54 @@ +#! /bin/sh +# test_kundo2_i18nc_long: +# $1: calligra_xgettext.sh +# $2: xgettext +# $3: msgcat +# $4: podir + +# source the calligra_xgettext.sh script +. $1 + +# setup environment variables for calligra_xgettext.sh +XGETTEXT_PROGRAM=$2 +MSGCAT=$3 +podir=$4 + +# copy from extract-messages.sh +XGETTEXT_FLAGS="\ +--copyright-holder=This_file_is_part_of_KDE \ +--msgid-bugs-address=http://bugs.kde.org \ +--from-code=UTF-8 \ +-C --kde \ +-ci18n \ +-ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 \ +-ki18nd:2 -ki18ndc:2c,3 -ki18ndp:2,3 -ki18ndcp:2c,3,4 \ +-kki18n:1 -kki18nc:1c,2 -kki18np:1,2 -kki18ncp:1c,2,3 \ +-kki18nd:2 -kki18ndc:2c,3 -kki18ndp:2,3 -kki18ndcp:2c,3,4 \ +-kxi18n:1 -kxi18nc:1c,2 -kxi18np:1,2 -kxi18ncp:1c,2,3 \ +-kxi18nd:2 -kxi18ndc:2c,3 -kxi18ndp:2,3 -kxi18ndcp:2c,3,4 \ +-kkxi18n:1 -kkxi18nc:1c,2 -kkxi18np:1,2 -kkxi18ncp:1c,2,3 \ +-kkxi18nd:2 -kkxi18ndc:2c,3 -kkxi18ndp:2,3 -kkxi18ndcp:2c,3,4 \ +-kI18N_NOOP:1 -kI18NC_NOOP:1c,2 \ +-kI18N_NOOP2:1c,2 -kI18N_NOOP2_NOSTRIP:1c,2 \ +-ktr2i18n:1 -ktr2xi18n:1 \ +" + +# calligra_xgettext.sh wants this in one variable +XGETTEXT="$XGETTEXT_PROGRAM $XGETTEXT_FLAGS" + +potfile="test_i18n.pot" +cppfile=test_i18n.cpp + +calligra_xgettext $potfile $cppfile + +# check result +if test ! -e $podir/$potfile; then + echo "FAIL: pot file not created" + exit 2 +fi +if test 0 -ne `grep qtundo-format $podir/$potfile|wc -l`; then + echo "FAIL: to many qtundo-format strings" + exit 1 +fi + +exit 0 diff --git a/tests/test_kundo2_i18n.cpp b/tests/test_kundo2_i18n.cpp new file mode 100644 --- /dev/null +++ b/tests/test_kundo2_i18n.cpp @@ -0,0 +1,2 @@ +kundo2_i18n("test_kundo2_i18n"); +i18n("normal i18n"); diff --git a/tests/test_kundo2_i18n.sh b/tests/test_kundo2_i18n.sh new file mode 100644 --- /dev/null +++ b/tests/test_kundo2_i18n.sh @@ -0,0 +1,54 @@ +#! /bin/sh +# test_kundo2_i18n: +# $1: calligra_xgettext.sh +# $2: xgettext +# $3: msgcat +# $4: podir + +# source the calligra_xgettext.sh script +. $1 + +# setup environment variables for calligra_xgettext.sh +XGETTEXT_PROGRAM=$2 +MSGCAT=$3 +podir=$4 + +# copy from extract-messages.sh +XGETTEXT_FLAGS="\ +--copyright-holder=This_file_is_part_of_KDE \ +--msgid-bugs-address=http://bugs.kde.org \ +--from-code=UTF-8 \ +-C --kde \ +-ci18n \ +-ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 \ +-ki18nd:2 -ki18ndc:2c,3 -ki18ndp:2,3 -ki18ndcp:2c,3,4 \ +-kki18n:1 -kki18nc:1c,2 -kki18np:1,2 -kki18ncp:1c,2,3 \ +-kki18nd:2 -kki18ndc:2c,3 -kki18ndp:2,3 -kki18ndcp:2c,3,4 \ +-kxi18n:1 -kxi18nc:1c,2 -kxi18np:1,2 -kxi18ncp:1c,2,3 \ +-kxi18nd:2 -kxi18ndc:2c,3 -kxi18ndp:2,3 -kxi18ndcp:2c,3,4 \ +-kkxi18n:1 -kkxi18nc:1c,2 -kkxi18np:1,2 -kkxi18ncp:1c,2,3 \ +-kkxi18nd:2 -kkxi18ndc:2c,3 -kkxi18ndp:2,3 -kkxi18ndcp:2c,3,4 \ +-kI18N_NOOP:1 -kI18NC_NOOP:1c,2 \ +-kI18N_NOOP2:1c,2 -kI18N_NOOP2_NOSTRIP:1c,2 \ +-ktr2i18n:1 -ktr2xi18n:1 \ +" + +# calligra_xgettext.sh wants this in one variable +XGETTEXT="$XGETTEXT_PROGRAM $XGETTEXT_FLAGS" + +potfile="test_kundo2_i18n.pot" +cppfile=test_kundo2_i18n.cpp + +calligra_xgettext $potfile $cppfile + +# check result +if test ! -e $podir/$potfile; then + echo "FAIL: pot file not created" + exit 2 +fi +if test 1 -ne `grep qtundo-format $podir/$potfile|wc -l`; then + echo "FAIL: to many qtundo-format strings" + exit 1 +fi + +exit 0 diff --git a/tests/test_kundo2_i18nc_long.cpp b/tests/test_kundo2_i18nc_long.cpp new file mode 100644 --- /dev/null +++ b/tests/test_kundo2_i18nc_long.cpp @@ -0,0 +1 @@ +kundo2_i18nc("This is a long kundo2_i18nc context string. It should be so long it is put on separate line from the 'msgctxt' by xgettext.", "long kundo2 i18nc"); diff --git a/tests/test_kundo2_i18nc_long.sh b/tests/test_kundo2_i18nc_long.sh new file mode 100644 --- /dev/null +++ b/tests/test_kundo2_i18nc_long.sh @@ -0,0 +1,54 @@ +#! /bin/sh +# test_kundo2_i18nc_long: +# $1: calligra_xgettext.sh +# $2: xgettext +# $3: msgcat +# $4: podir + +# source the calligra_xgettext.sh script +. $1 + +# setup environment variables for calligra_xgettext.sh +XGETTEXT_PROGRAM=$2 +MSGCAT=$3 +podir=$4 + +# copy from extract-messages.sh +XGETTEXT_FLAGS="\ +--copyright-holder=This_file_is_part_of_KDE \ +--msgid-bugs-address=http://bugs.kde.org \ +--from-code=UTF-8 \ +-C --kde \ +-ci18n \ +-ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 \ +-ki18nd:2 -ki18ndc:2c,3 -ki18ndp:2,3 -ki18ndcp:2c,3,4 \ +-kki18n:1 -kki18nc:1c,2 -kki18np:1,2 -kki18ncp:1c,2,3 \ +-kki18nd:2 -kki18ndc:2c,3 -kki18ndp:2,3 -kki18ndcp:2c,3,4 \ +-kxi18n:1 -kxi18nc:1c,2 -kxi18np:1,2 -kxi18ncp:1c,2,3 \ +-kxi18nd:2 -kxi18ndc:2c,3 -kxi18ndp:2,3 -kxi18ndcp:2c,3,4 \ +-kkxi18n:1 -kkxi18nc:1c,2 -kkxi18np:1,2 -kkxi18ncp:1c,2,3 \ +-kkxi18nd:2 -kkxi18ndc:2c,3 -kkxi18ndp:2,3 -kkxi18ndcp:2c,3,4 \ +-kI18N_NOOP:1 -kI18NC_NOOP:1c,2 \ +-kI18N_NOOP2:1c,2 -kI18N_NOOP2_NOSTRIP:1c,2 \ +-ktr2i18n:1 -ktr2xi18n:1 \ +" + +# calligra_xgettext.sh wants this in one variable +XGETTEXT="$XGETTEXT_PROGRAM $XGETTEXT_FLAGS" + +potfile="test_kundo2_i18nc_long.pot" +cppfile=test_kundo2_i18nc_long.cpp + +calligra_xgettext $potfile $cppfile + +# check result +if test ! -e $podir/$potfile; then + echo "FAIL: pot file not created" + exit 2 +fi +if test 1 -ne `grep qtundo-format $podir/$potfile|wc -l`; then + echo "FAIL: to many qtundo-format strings" + exit 1 +fi + +exit 0