aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/ECMPoQmToolsTest/CMakeLists.txt57
-rw-r--r--tests/ECMPoQmToolsTest/check.cmake.in (renamed from tests/ECMPoQmToolsTest/check_tree.cmake.in)40
-rw-r--r--tests/ECMPoQmToolsTest/check_conf.cmake.in2
-rw-r--r--tests/ECMPoQmToolsTest/subdir/CMakeLists.txt5
-rw-r--r--tests/ECMPoQmToolsTest/tr_test-po/de/catalog.po22
-rw-r--r--tests/ECMPoQmToolsTest/tr_test-po/en/catalog.po22
-rw-r--r--tests/ECMPoQmToolsTest/tr_test.cpp43
8 files changed, 178 insertions, 17 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8a75ae61..9e6de12f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -101,13 +101,13 @@ add_test_macro(ECMInstallIconsTest
${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMInstallIconsTest/check_tree.cmake"
)
-if (Qt5LinguistTools_FOUND)
+if (Qt5Core_FOUND AND Qt5LinguistTools_FOUND)
set(ECMPoQmToolsTest_EXTRA_OPTIONS
--build-target install
--build-options
"-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMPoQmToolsTest/InstallDirectory"
)
add_test_macro(ECMPoQmToolsTest
- ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMPoQmToolsTest/check_tree.cmake"
+ ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMPoQmToolsTest/check.cmake"
)
endif()
diff --git a/tests/ECMPoQmToolsTest/CMakeLists.txt b/tests/ECMPoQmToolsTest/CMakeLists.txt
index 15351d2f..76d80141 100644
--- a/tests/ECMPoQmToolsTest/CMakeLists.txt
+++ b/tests/ECMPoQmToolsTest/CMakeLists.txt
@@ -9,9 +9,13 @@ file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}")
include(ECMPoQmTools)
-# Should create ${CMAKE_CURRENT_BINARY_DIR}/qmloader.cpp and set QMLOADER_PATH
-# to its path
-ecm_create_qm_loader(QMLOADER_PATH catalog)
+include(../test_helpers.cmake)
+
+
+#
+# ecm_process_po_files_as_qm
+#
+
# Should create a process-and-install.qm file and install it
ecm_process_po_files_as_qm(fr ALL
@@ -24,20 +28,63 @@ ecm_process_po_files_as_qm(fr ALL
PO_FILES only-process.po
)
+
+
+#
+# ecm_install_po_files_as_qm
+#
+
# Should create a bunch of .qm files and install them in share/locale.
# Should ignore files directly under po/ as well as directories under po/ which
# do not contain any .po files.
ecm_install_po_files_as_qm(po)
+
# Should create a bunch of .qm files and install them in
# ${CMAKE_INSTALL_LOCALEDIR}
set(CMAKE_INSTALL_LOCALEDIR custom-dir1)
ecm_install_po_files_as_qm(po-custom-dir1)
+
# Should create a bunch of .qm files and install them in
# ${LOCALE_INSTALL_DIR}
set(LOCALE_INSTALL_DIR custom-dir2)
ecm_install_po_files_as_qm(po-custom-dir2)
-# this will be run by CTest
-configure_file(check_tree.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/check_tree.cmake" @ONLY)
+unset(CMAKE_INSTALL_LOCALEDIR)
+unset(LOCALE_INSTALL_DIR)
+
+
+
+#
+# ecm_create_qm_loader
+#
+
+find_package(Qt5Core CONFIG REQUIRED)
+ecm_install_po_files_as_qm(tr_test-po)
+
+
+set(tr_test_SRCS
+ tr_test.cpp
+)
+ecm_create_qm_loader(tr_test_SRCS catalog)
+add_executable(tr_test ${tr_test_SRCS})
+target_link_libraries(tr_test PRIVATE Qt5::Core)
+
+
+# This is not something we want people to do (putting the ecm_create_qm_loader
+# call in one CMakeLists.txt file and the target it is used for in another),
+# but it's unfortunately something projects have done and we need to keep them
+# building
+unset(QMLOADER_FILES)
+ecm_create_qm_loader(QMLOADER_FILES catalog)
+assert_var_defined(QMLOADER_FILES)
+add_subdirectory(subdir)
+
+
+
+file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/check_conf.cmake"
+ INPUT "${CMAKE_CURRENT_SOURCE_DIR}/check_conf.cmake.in"
+)
+configure_file(check.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/check.cmake" @ONLY)
diff --git a/tests/ECMPoQmToolsTest/check_tree.cmake.in b/tests/ECMPoQmToolsTest/check.cmake.in
index 9f4f7c0d..ab434d2e 100644
--- a/tests/ECMPoQmToolsTest/check_tree.cmake.in
+++ b/tests/ECMPoQmToolsTest/check.cmake.in
@@ -1,6 +1,6 @@
set(BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@")
set(ACTUAL_TREE "@CMAKE_INSTALL_PREFIX@")
-set(QMLOADER_PATH "@QMLOADER_PATH@")
+include("${BINARY_DIR}/check_conf.cmake")
set(fail OFF)
@@ -9,27 +9,21 @@ macro(mark_failed msg)
set(fail ON)
endmacro()
-macro(check_strequal var expected)
- if (NOT "${${var}}" STREQUAL "${expected}")
- mark_failed("${var} is:\n \"${${var}}\"\nExpected:\n \"${expected}\"")
- endif()
-endmacro()
-
macro(check_exists file)
+ message(STATUS "Checking for ${file}")
if (NOT EXISTS ${file})
mark_failed("File \"${file}\" does not exist")
endif()
endmacro()
-check_exists(${BINARY_DIR}/ECMQmLoader.cpp)
-check_strequal(QMLOADER_PATH "${BINARY_DIR}/ECMQmLoader.cpp")
-
check_exists(${BINARY_DIR}/fr/only-process.qm)
set(exp_files
"share/locale/fr/LC_MESSAGES/process-and-install.qm"
"share/locale/es/LC_MESSAGES/install-test.qm"
"share/locale/fr/LC_MESSAGES/install-test.qm"
+ "share/locale/en/LC_MESSAGES/catalog.qm"
+ "share/locale/de/LC_MESSAGES/catalog.qm"
"custom-dir1/es/LC_MESSAGES/custom-dir1-install-test.qm"
"custom-dir1/fr/LC_MESSAGES/custom-dir1-install-test.qm"
"custom-dir2/es/LC_MESSAGES/custom-dir2-install-test.qm"
@@ -54,6 +48,32 @@ if(NOT exp_files STREQUAL actual_files)
set(fail ON)
endif()
endforeach()
+else()
+ message(STATUS "Installed translations in expected locations")
+endif()
+
+# we know we can modify the executable environment on Linux
+if("@CMAKE_SYSTEM_NAME@" STREQUAL "Linux")
+ set(exp_output_en "english text:english plural form 5")
+ set(exp_output_de "german text:german plural form 5")
+ # no french translation provided -> english fallback
+ set(exp_output_fr "${exp_output_en}")
+ foreach(exec TR_TEST TR_TEST_SUBDIR)
+ foreach(lang en de fr)
+ execute_process(
+ COMMAND "${CMAKE_COMMAND}" -E env "XDG_DATA_DIRS=${ACTUAL_TREE}/share"
+ LANGUAGE=${lang} "${${exec}_EXEC}"
+ OUTPUT_VARIABLE output
+ )
+ string(STRIP "${output}" stripped_output)
+ if(NOT stripped_output STREQUAL exp_output_${lang})
+ message(WARNING "${exec}[${lang}] output was \"${stripped_output}\", but expected \"${exp_output_${lang}}\"")
+ set(fail ON)
+ else()
+ message(STATUS "${exec}[${lang}] output was \"${stripped_output}\", as expected")
+ endif()
+ endforeach()
+ endforeach()
endif()
if (fail)
diff --git a/tests/ECMPoQmToolsTest/check_conf.cmake.in b/tests/ECMPoQmToolsTest/check_conf.cmake.in
new file mode 100644
index 00000000..9ab02e72
--- /dev/null
+++ b/tests/ECMPoQmToolsTest/check_conf.cmake.in
@@ -0,0 +1,2 @@
+set(TR_TEST_EXEC "$<TARGET_FILE:tr_test>")
+set(TR_TEST_SUBDIR_EXEC "$<TARGET_FILE:tr_test_subdir>")
diff --git a/tests/ECMPoQmToolsTest/subdir/CMakeLists.txt b/tests/ECMPoQmToolsTest/subdir/CMakeLists.txt
new file mode 100644
index 00000000..ee06b971
--- /dev/null
+++ b/tests/ECMPoQmToolsTest/subdir/CMakeLists.txt
@@ -0,0 +1,5 @@
+# QMLOADER_FILES comes from parent CMakeLists.txt. This is not something we
+# want people to do, but it's unfortunately something projects have done and we
+# need to keep them building
+add_executable(tr_test_subdir ../tr_test.cpp ${QMLOADER_FILES})
+target_link_libraries(tr_test_subdir PRIVATE Qt5::Core)
diff --git a/tests/ECMPoQmToolsTest/tr_test-po/de/catalog.po b/tests/ECMPoQmToolsTest/tr_test-po/de/catalog.po
new file mode 100644
index 00000000..6f3e328f
--- /dev/null
+++ b/tests/ECMPoQmToolsTest/tr_test-po/de/catalog.po
@@ -0,0 +1,22 @@
+msgid ""
+msgstr ""
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+"X-Language: de\n"
+"X-Qt-Contexts: true\n"
+
+#: main.cpp:12
+msgctxt "testcontext|"
+msgid "test string"
+msgstr "german text"
+
+#: main.cpp:13
+#, qt-format
+#| msgid "test plural"
+msgctxt "testcontext|"
+msgid "test plural %n"
+msgid_plural "test plural %n"
+msgstr[0] "german singular form %n"
+msgstr[1] "german plural form %n"
diff --git a/tests/ECMPoQmToolsTest/tr_test-po/en/catalog.po b/tests/ECMPoQmToolsTest/tr_test-po/en/catalog.po
new file mode 100644
index 00000000..2a7b6d28
--- /dev/null
+++ b/tests/ECMPoQmToolsTest/tr_test-po/en/catalog.po
@@ -0,0 +1,22 @@
+msgid ""
+msgstr ""
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+"X-Language: en\n"
+"X-Qt-Contexts: true\n"
+
+#: main.cpp:12
+msgctxt "testcontext|"
+msgid "test string"
+msgstr "english text"
+
+#: main.cpp:13
+#, qt-format
+#| msgid "test plural"
+msgctxt "testcontext|"
+msgid "test plural %n"
+msgid_plural "test plural %n"
+msgstr[0] "english singular form %n"
+msgstr[1] "english plural form %n"
diff --git a/tests/ECMPoQmToolsTest/tr_test.cpp b/tests/ECMPoQmToolsTest/tr_test.cpp
new file mode 100644
index 00000000..22101263
--- /dev/null
+++ b/tests/ECMPoQmToolsTest/tr_test.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Alex Merry <alex.merry@kde.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <QCoreApplication>
+#include <QTextStream>
+
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QTextStream output(stdout);
+
+ output << QCoreApplication::translate("testcontext", "test string") << ":";
+ output << QCoreApplication::translate("testcontext", "test plural %n", 0, 5) << '\n';
+
+ return 0;
+}