Kaydet (Commit) 187174d5 authored tarafından Jens Carl's avatar Jens Carl Kaydeden (comit) Stephan Bergmann

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: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 29d35c82
# -*- 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:
......@@ -140,6 +140,7 @@ endif
# general tests
$(eval $(call gb_Module_add_check_targets,connectivity,\
CppunitTest_connectivity_commontools \
CppunitTest_connectivity_sharedresources \
))
endif
......
/* -*- 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: */
......@@ -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;
}
......
......@@ -90,6 +90,7 @@ certain functionality.
@li @c connectivity.odbc
@li @c connectivity.parse
@li @c connectivity.postgresql
@li @c connectivity.resource
@li @c connectivity.writer
@section comphelper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment