[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] /: i18n: Add unit tests for string extractions
From:       Dag Andersen <danders () get2net ! dk>
Date:       2016-12-01 7:52:19
Message-ID: E1cCMAF-0003ZU-R6 () code ! kde ! org
[Download RAW message or body]

Git commit d16b1267bc758b7532cc4d7c0dfa6e5ded41464d by Dag Andersen.
Committed on 01/12/2016 at 07:52.
Pushed by danders into branch 'master'.

i18n: Add unit tests for string extractions

Summary:
calligra_xgettext.sh have issues like:
Adding (qtundo-format) to messages that have nothing to do with undo/redo
Failing if a context string is too long

This commit includes the framework and 3 tests
Todo: Add more tests and fix calligra_xgettext.sh

Reviewers: staniek, boemann

Tags: #kexi, #calligra:_3.0

Differential Revision: https://phabricator.kde.org/D3546

M  +4    -0    CMakeLists.txt
A  +0    -0    tests/.i18n
A  +30   -0    tests/CMakeLists.txt
A  +1    -0    tests/test_i18n.cpp     [License: Trivial file]
A  +54   -0    tests/test_i18n.sh
A  +2    -0    tests/test_kundo2_i18n.cpp     [License: Trivial file]
A  +54   -0    tests/test_kundo2_i18n.sh
A  +1    -0    tests/test_kundo2_i18nc_long.cpp     [License: UNKNOWN]  *
A  +54   -0    tests/test_kundo2_i18nc_long.sh

The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.


https://commits.kde.org/calligra/d16b1267bc758b7532cc4d7c0dfa6e5ded41464d

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b8de4a2..5d0039e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1189,3 +1189,7 @@ configure_file(KoConfig.h.cmake \
${CMAKE_CURRENT_BINARY_DIR}/KoConfig.h )  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
index 0000000..e69de29
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..1e7c77d
--- /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
index 0000000..aec14fc
--- /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
index 0000000..24912dd
--- /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
index 0000000..46a9f9e
--- /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
index 0000000..db44853
--- /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
index 0000000..ef18350
--- /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
index 0000000..4eb2165
--- /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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic