[Libreoffice-commits] core.git: connectivity/CppunitTest_connectivity_sharedresources.mk connectivity/Module_connectivity.mk connectivity/qa connectivity/source include/sal

Jens Carl (via logerrit) logerrit at kemper.freedesktop.org
Tue May 7 13:48:08 UTC 2019


 connectivity/CppunitTest_connectivity_sharedresources.mk       |   41 +++
 connectivity/Module_connectivity.mk                            |    1 
 connectivity/qa/connectivity/resource/sharedresources_test.cxx |  107 ++++++++++
 connectivity/source/resource/sharedresources.cxx               |   22 +-
 include/sal/log-areas.dox                                      |    1 
 5 files changed, 165 insertions(+), 7 deletions(-)

New commits:
commit 187174d5c18f80f2e6fe03355379e5e14117791e
Author:     Jens Carl <j.carl43 at gmx.de>
AuthorDate: Thu May 2 13:48:20 2019 -0700
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue May 7 15:47:22 2019 +0200

    tdf#43157 Clean up OSL_VERIFY (replace with SAL_WARN)
    
    Replace OSL_VERIFY with if-statement and SAL_WARN and add some unit
    tests to ensure the implementation works and the replacements don't
    introduce some side effects.
    
    Change-Id: I4ed50eee53e4dba4d392ed2486186d48f919ce1d
    Reviewed-on: https://gerrit.libreoffice.org/71712
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/connectivity/CppunitTest_connectivity_sharedresources.mk b/connectivity/CppunitTest_connectivity_sharedresources.mk
new file mode 100644
index 000000000000..78209cfbbdf0
--- /dev/null
+++ b/connectivity/CppunitTest_connectivity_sharedresources.mk
@@ -0,0 +1,41 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,connectivity_sharedresources))
+
+$(eval $(call gb_CppunitTest_set_include,connectivity_sharedresources,\
+	-I$(SRCDIR)/connectivity/inc \
+	-I$(SRCDIR)/connectivity/source/inc \
+	$$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,connectivity_sharedresources))
+$(eval $(call gb_CppunitTest_use_vcl,connectivity_sharedresources))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,connectivity_sharedresources))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,connectivity_sharedresources, \
+	connectivity/qa/connectivity/resource/sharedresources_test \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,connectivity_sharedresources, \
+	dbtools \
+	sal \
+	test \
+	unotest \
+))
+
+$(eval $(call gb_CppunitTest_use_components,connectivity_sharedresources,\
+    configmgr/source/configmgr \
+    i18npool/util/i18npool \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,connectivity_sharedresources))
+
+# vim: set noet sw=4 ts=4:
diff --git a/connectivity/Module_connectivity.mk b/connectivity/Module_connectivity.mk
index a604345a4735..1a29e0798948 100644
--- a/connectivity/Module_connectivity.mk
+++ b/connectivity/Module_connectivity.mk
@@ -140,6 +140,7 @@ endif
 # general tests
 $(eval $(call gb_Module_add_check_targets,connectivity,\
 	CppunitTest_connectivity_commontools \
+	CppunitTest_connectivity_sharedresources \
 ))
 
 endif
diff --git a/connectivity/qa/connectivity/resource/sharedresources_test.cxx b/connectivity/qa/connectivity/resource/sharedresources_test.cxx
new file mode 100644
index 000000000000..2ef68eca8be8
--- /dev/null
+++ b/connectivity/qa/connectivity/resource/sharedresources_test.cxx
@@ -0,0 +1,107 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+
+#include <resource/sharedresources.hxx>
+#include <strings.hrc>
+
+#include <utility>
+#include <vector>
+
+using namespace css;
+
+namespace connectivity_test
+{
+#define TEST_SOURCE_STRING NC_("TEST_SOURCE_STRING", "UnitTest")
+#define TEST_SOURCE_ONE_SUBSTITUTION NC_("TEST_SOURCE_ONE_SUBSTITUTION", "One substitution $sub$")
+#define TEST_SOURCE_TWO_SUBSTITUTION                                                               \
+    NC_("TEST_SOURCE_TWO_SUBSTITUTION", "Two substitution $sub0$ $sub1$")
+#define TEST_SOURCE_THREE_SUBSTITUTION                                                             \
+    NC_("TEST_SOURCE_THREE_SUBSTITUTION", "Three substitution $sub0$ $sub1$ $sub2$")
+
+class SharedResourcesTest : public test::BootstrapFixture
+{
+public:
+    SharedResourcesTest();
+
+    void testGetSourceString();
+    void testGetSourceStringWithSubstitutionOne();
+    void testGetSourceStringWithSubstitutionTwo();
+    void testGetSourceStringWithSubstitutionThree();
+    void testGetSourceStringWithSubstitutionVector();
+
+    CPPUNIT_TEST_SUITE(SharedResourcesTest);
+
+    CPPUNIT_TEST(testGetSourceString);
+    CPPUNIT_TEST(testGetSourceStringWithSubstitutionOne);
+    CPPUNIT_TEST(testGetSourceStringWithSubstitutionTwo);
+    CPPUNIT_TEST(testGetSourceStringWithSubstitutionThree);
+    CPPUNIT_TEST(testGetSourceStringWithSubstitutionVector);
+
+    CPPUNIT_TEST_SUITE_END();
+
+private:
+    ::connectivity::SharedResources m_aResource;
+};
+
+SharedResourcesTest::SharedResourcesTest()
+    : test::BootstrapFixture(false, false)
+{
+}
+
+void SharedResourcesTest::testGetSourceString()
+{
+    CPPUNIT_ASSERT_EQUAL(OUString("UnitTest"), m_aResource.getResourceString(TEST_SOURCE_STRING));
+}
+
+void SharedResourcesTest::testGetSourceStringWithSubstitutionOne()
+{
+    CPPUNIT_ASSERT_EQUAL(OUString("One substitution UnitTest"),
+                         m_aResource.getResourceStringWithSubstitution(TEST_SOURCE_ONE_SUBSTITUTION,
+                                                                       "$sub$", "UnitTest"));
+}
+
+void SharedResourcesTest::testGetSourceStringWithSubstitutionTwo()
+{
+    CPPUNIT_ASSERT_EQUAL(OUString("Two substitution UnitTest1 UnitTest2"),
+                         m_aResource.getResourceStringWithSubstitution(TEST_SOURCE_TWO_SUBSTITUTION,
+                                                                       "$sub0$", "UnitTest1",
+                                                                       "$sub1$", "UnitTest2"));
+}
+
+void SharedResourcesTest::testGetSourceStringWithSubstitutionThree()
+{
+    CPPUNIT_ASSERT_EQUAL(OUString("Three substitution UnitTest1 UnitTest2 UnitTest3"),
+                         m_aResource.getResourceStringWithSubstitution(
+                             TEST_SOURCE_THREE_SUBSTITUTION, "$sub0$", "UnitTest1", "$sub1$",
+                             "UnitTest2", "$sub2$", "UnitTest3"));
+}
+
+void SharedResourcesTest::testGetSourceStringWithSubstitutionVector()
+{
+    std::vector<std::pair<const sal_Char*, OUString>> aStringToSubstitutes;
+    aStringToSubstitutes.push_back(std::pair<const sal_Char*, OUString>("$sub0$", "vector0"));
+    aStringToSubstitutes.push_back(std::pair<const sal_Char*, OUString>("$sub1$", "vector1"));
+    aStringToSubstitutes.push_back(std::pair<const sal_Char*, OUString>("$sub2$", "vector2"));
+
+    CPPUNIT_ASSERT_EQUAL(OUString("Three substitution vector0 vector1 vector2"),
+                         m_aResource.getResourceStringWithSubstitution(
+                             TEST_SOURCE_THREE_SUBSTITUTION, aStringToSubstitutes));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SharedResourcesTest);
+
+} // namespace connectivity_test
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/connectivity/source/resource/sharedresources.cxx b/connectivity/source/resource/sharedresources.cxx
index c2ff0bd86092..87185d66b83a 100644
--- a/connectivity/source/resource/sharedresources.cxx
+++ b/connectivity/source/resource/sharedresources.cxx
@@ -25,6 +25,7 @@
 #include <tools/diagnose_ex.h>
 #include <unotools/resmgr.hxx>
 #include <osl/diagnose.h>
+#include <sal/log.hxx>
 
 namespace connectivity
 {
@@ -139,7 +140,8 @@ namespace connectivity
                 const sal_Char* _pAsciiPatternToReplace, const OUString& _rStringToSubstitute ) const
     {
         OUString sString( SharedResources_Impl::getInstance().getResourceString(pResId) );
-        OSL_VERIFY( lcl_substitute( sString, _pAsciiPatternToReplace, _rStringToSubstitute ) );
+        if ( !lcl_substitute( sString, _pAsciiPatternToReplace, _rStringToSubstitute ) )
+            SAL_WARN("connectivity.resource", "Unable to substitute " << _pAsciiPatternToReplace << " with " << _rStringToSubstitute);
         return sString;
     }
 
@@ -149,8 +151,10 @@ namespace connectivity
                 const sal_Char* _pAsciiPatternToReplace2, const OUString& _rStringToSubstitute2 ) const
     {
         OUString sString( SharedResources_Impl::getInstance().getResourceString(pResId) );
-        OSL_VERIFY( lcl_substitute( sString, _pAsciiPatternToReplace1, _rStringToSubstitute1 ) );
-        OSL_VERIFY( lcl_substitute( sString, _pAsciiPatternToReplace2, _rStringToSubstitute2 ) );
+        if( !lcl_substitute( sString, _pAsciiPatternToReplace1, _rStringToSubstitute1 ) )
+            SAL_WARN("connectivity.resource", "Unable to substitute " << _pAsciiPatternToReplace1 << " with " << _rStringToSubstitute1);
+        if( !lcl_substitute( sString, _pAsciiPatternToReplace2, _rStringToSubstitute2 ) )
+            SAL_WARN("connectivity.resource", "Unable to substitute " << _pAsciiPatternToReplace2 << " with " << _rStringToSubstitute2);
         return sString;
     }
 
@@ -161,9 +165,12 @@ namespace connectivity
                 const sal_Char* _pAsciiPatternToReplace3, const OUString& _rStringToSubstitute3 ) const
     {
         OUString sString( SharedResources_Impl::getInstance().getResourceString(pResId) );
-        OSL_VERIFY( lcl_substitute( sString, _pAsciiPatternToReplace1, _rStringToSubstitute1 ) );
-        OSL_VERIFY( lcl_substitute( sString, _pAsciiPatternToReplace2, _rStringToSubstitute2 ) );
-        OSL_VERIFY( lcl_substitute( sString, _pAsciiPatternToReplace3, _rStringToSubstitute3 ) );
+        if( !lcl_substitute( sString, _pAsciiPatternToReplace1, _rStringToSubstitute1 ) )
+            SAL_WARN("connectivity.resource", "Unable to substitute " << _pAsciiPatternToReplace1 << " with " << _rStringToSubstitute1);
+        if( !lcl_substitute( sString, _pAsciiPatternToReplace2, _rStringToSubstitute2 ) )
+            SAL_WARN("connectivity.resource", "Unable to substitute " << _pAsciiPatternToReplace2 << " with " << _rStringToSubstitute2);
+        if( !lcl_substitute( sString, _pAsciiPatternToReplace3, _rStringToSubstitute3 ) )
+            SAL_WARN("connectivity.resource", "Unable to substitute " << _pAsciiPatternToReplace3 << " with " << _rStringToSubstitute3);
         return sString;
     }
 
@@ -172,7 +179,8 @@ namespace connectivity
     {
         OUString sString( SharedResources_Impl::getInstance().getResourceString(pResId) );
         for(const auto& [rPattern, rReplace] : _rStringToSubstitutes)
-            OSL_VERIFY( lcl_substitute( sString, rPattern, rReplace ) );
+            if( !lcl_substitute( sString, rPattern, rReplace ) )
+                SAL_WARN("connectivity.resource", "Unable to substitute " << rPattern << " with " << rReplace);
 
         return sString;
     }
diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index da6fd1c4a171..d72710a1f79e 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -90,6 +90,7 @@ certain functionality.
 @li @c connectivity.odbc
 @li @c connectivity.parse
 @li @c connectivity.postgresql
+ at li @c connectivity.resource
 @li @c connectivity.writer
 
 @section comphelper


More information about the Libreoffice-commits mailing list