diff options
author | Tor Lillqvist <tml@collabora.com> | 2018-12-10 16:12:08 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2018-12-10 18:31:18 +0100 |
commit | 4f1a341bc312673b8d92e4474cc39bc3ab69aa5b (patch) | |
tree | 169e66e3087705f521d97dfdd0d6dba827d2127e /desktop/qa | |
parent | ee855a377f962eb8dff2224bb6412c2243535fb0 (diff) |
Add a localisation API to LibreOfficeKitClass
Combines the LanguageTag::Create() and Translate::get() (or nget())
functionality.
Also add an ABI test for the Kit class in the LibreOfficeKit unit
test, and a test for the translation function.
Change-Id: I78c48a8bbb434d6f204869290822830288022a53
Reviewed-on: https://gerrit.libreoffice.org/64882
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'desktop/qa')
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 74e2c09bb5af..067541dd345d 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -33,6 +33,7 @@ #include <osl/conditn.hxx> #include <osl/thread.hxx> #include <svl/srchitem.hxx> +#include <svtools/strings.hrc> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <unotools/tempfile.hxx> #include <sfx2/viewsh.hxx> @@ -118,6 +119,7 @@ public: void testCommentsImpress(); void testCommentsCallbacksWriter(); void testRunMacro(); + void testTranslate(); void testExtractParameter(); void testGetSignatureState_NonSigned(); void testGetSignatureState_Signed(); @@ -165,6 +167,7 @@ public: CPPUNIT_TEST(testCommentsImpress); CPPUNIT_TEST(testCommentsCallbacksWriter); CPPUNIT_TEST(testRunMacro); + CPPUNIT_TEST(testTranslate); CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testGetSignatureState_Signed); CPPUNIT_TEST(testGetSignatureState_NonSigned); @@ -2219,6 +2222,20 @@ void DesktopLOKTest::testRunMacro() comphelper::LibreOfficeKit::setActive(false); } +void DesktopLOKTest::testTranslate() +{ + comphelper::LibreOfficeKit::setActive(); + + LibLibreOffice_Impl aOffice; + + // Try translating to a non-existent locale, should return the English string + char *translated = aOffice.m_pOfficeClass->translateGet(&aOffice, STR_DESCRIPTION_FACTORY_WRITER, "svt", "foo"); + CPPUNIT_ASSERT_EQUAL(0, strcmp(translated, "Text Document")); + free(translated); + + comphelper::LibreOfficeKit::setActive(false); +} + void DesktopLOKTest::testExtractParameter() { comphelper::LibreOfficeKit::setActive(); @@ -2463,6 +2480,11 @@ void DesktopLOKTest::testInsertCertificatePEM() namespace { +constexpr size_t classOffset(int i) +{ + return sizeof(static_cast<struct _LibreOfficeKitClass*>(nullptr)->nSize) + i * sizeof(void*); +} + constexpr size_t documentClassOffset(int i) { return sizeof(static_cast<struct _LibreOfficeKitDocumentClass*>(nullptr)->nSize) + i * sizeof(void*); @@ -2473,6 +2495,21 @@ constexpr size_t documentClassOffset(int i) void DesktopLOKTest::testABI() { // STABLE ABI, NEVER CHANGE (unless there's a very good reason, agreed by ESC, etc.) + + CPPUNIT_ASSERT_EQUAL(classOffset(0), offsetof(struct _LibreOfficeKitClass, destroy)); + CPPUNIT_ASSERT_EQUAL(classOffset(1), offsetof(struct _LibreOfficeKitClass, documentLoad)); + CPPUNIT_ASSERT_EQUAL(classOffset(2), offsetof(struct _LibreOfficeKitClass, getError)); + CPPUNIT_ASSERT_EQUAL(classOffset(3), offsetof(struct _LibreOfficeKitClass, documentLoadWithOptions)); + CPPUNIT_ASSERT_EQUAL(classOffset(4), offsetof(struct _LibreOfficeKitClass, freeError)); + CPPUNIT_ASSERT_EQUAL(classOffset(5), offsetof(struct _LibreOfficeKitClass, registerCallback)); + CPPUNIT_ASSERT_EQUAL(classOffset(6), offsetof(struct _LibreOfficeKitClass, getFilterTypes)); + CPPUNIT_ASSERT_EQUAL(classOffset(7), offsetof(struct _LibreOfficeKitClass, setOptionalFeatures)); + CPPUNIT_ASSERT_EQUAL(classOffset(8), offsetof(struct _LibreOfficeKitClass, setDocumentPassword)); + CPPUNIT_ASSERT_EQUAL(classOffset(9), offsetof(struct _LibreOfficeKitClass, getVersionInfo)); + CPPUNIT_ASSERT_EQUAL(classOffset(10), offsetof(struct _LibreOfficeKitClass, runMacro)); + CPPUNIT_ASSERT_EQUAL(classOffset(11), offsetof(struct _LibreOfficeKitClass, translateGet)); + CPPUNIT_ASSERT_EQUAL(classOffset(12), offsetof(struct _LibreOfficeKitClass, translateNGet)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(0), offsetof(struct _LibreOfficeKitDocumentClass, destroy)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(1), offsetof(struct _LibreOfficeKitDocumentClass, saveAs)); |