Kaydet (Commit) 516983b7 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 SAL_WARN_IF and add some unit tests to ensure
the replacements don't some side effects.

Change-Id: I96eb00e2856e767e83596a21d30ae12a0efddf6d
Reviewed-on: https://gerrit.libreoffice.org/71252
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst c211646a
...@@ -14,6 +14,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \ ...@@ -14,6 +14,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \
comphelper/qa/container/testifcontainer \ comphelper/qa/container/testifcontainer \
comphelper/qa/unit/test_hash \ comphelper/qa/unit/test_hash \
comphelper/qa/unit/base64_test \ comphelper/qa/unit/base64_test \
comphelper/qa/unit/types_test \
)) ))
$(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test)) $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test))
......
/* -*- 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 <comphelper/types.hxx>
#include <sal/types.h>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
using namespace css;
namespace
{
class TypesTest : public CppUnit::TestFixture
{
public:
void testGetINT64();
void testGetINT32();
void testGetINT16();
void testGetDouble();
void testGetFloat();
void testGetString();
CPPUNIT_TEST_SUITE(TypesTest);
CPPUNIT_TEST(testGetINT64);
CPPUNIT_TEST(testGetINT32);
CPPUNIT_TEST(testGetINT16);
CPPUNIT_TEST(testGetDouble);
CPPUNIT_TEST(testGetFloat);
CPPUNIT_TEST(testGetString);
CPPUNIT_TEST_SUITE_END();
};
void TypesTest::testGetINT64()
{
CPPUNIT_ASSERT_EQUAL(sal_Int64(1337), ::comphelper::getINT64(uno::makeAny(sal_Int64(1337))));
uno::Any aValue;
CPPUNIT_ASSERT_EQUAL(sal_Int64(0), ::comphelper::getINT64(aValue));
}
void TypesTest::testGetINT32()
{
CPPUNIT_ASSERT_EQUAL(sal_Int32(1337), ::comphelper::getINT32(uno::makeAny(sal_Int32(1337))));
uno::Any aValue;
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ::comphelper::getINT32(aValue));
}
void TypesTest::testGetINT16()
{
CPPUNIT_ASSERT_EQUAL(sal_Int16(1337), ::comphelper::getINT16(uno::makeAny(sal_Int16(1337))));
uno::Any aValue;
CPPUNIT_ASSERT_EQUAL(sal_Int16(0), ::comphelper::getINT16(aValue));
}
void TypesTest::testGetDouble()
{
CPPUNIT_ASSERT_EQUAL(1337.1337, ::comphelper::getDouble(uno::makeAny(1337.1337)));
uno::Any aValue;
CPPUNIT_ASSERT_EQUAL(0.0, ::comphelper::getDouble(aValue));
}
void TypesTest::testGetFloat()
{
CPPUNIT_ASSERT_EQUAL(static_cast<float>(1337.0),
::comphelper::getFloat(uno::makeAny(static_cast<float>(1337.0))));
uno::Any aValue;
CPPUNIT_ASSERT_EQUAL(static_cast<float>(0.0), ::comphelper::getFloat(aValue));
}
void TypesTest::testGetString()
{
CPPUNIT_ASSERT_EQUAL(OUString("1337"), ::comphelper::getString(uno::makeAny(OUString("1337"))));
uno::Any aValue;
CPPUNIT_ASSERT_EQUAL(OUString(""), ::comphelper::getString(aValue));
}
CPPUNIT_TEST_SUITE_REGISTRATION(TypesTest);
} // namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <o3tl/any.hxx> #include <o3tl/any.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <typelib/typedescription.hxx> #include <typelib/typedescription.hxx>
#include <sal/log.hxx>
namespace comphelper namespace comphelper
...@@ -38,7 +39,8 @@ using namespace ::com::sun::star::lang; ...@@ -38,7 +39,8 @@ using namespace ::com::sun::star::lang;
sal_Int64 getINT64(const Any& _rAny) sal_Int64 getINT64(const Any& _rAny)
{ {
sal_Int64 nReturn = 0; sal_Int64 nReturn = 0;
OSL_VERIFY( _rAny >>= nReturn ); if(!(_rAny >>= nReturn))
SAL_WARN("comphelper", "conversion from Any to sal_Int64 failed");
return nReturn; return nReturn;
} }
...@@ -46,7 +48,8 @@ sal_Int64 getINT64(const Any& _rAny) ...@@ -46,7 +48,8 @@ sal_Int64 getINT64(const Any& _rAny)
sal_Int32 getINT32(const Any& _rAny) sal_Int32 getINT32(const Any& _rAny)
{ {
sal_Int32 nReturn = 0; sal_Int32 nReturn = 0;
OSL_VERIFY( _rAny >>= nReturn ); if(!(_rAny >>= nReturn))
SAL_WARN("comphelper", "conversion from Any to sal_Int32 failed");
return nReturn; return nReturn;
} }
...@@ -54,7 +57,8 @@ sal_Int32 getINT32(const Any& _rAny) ...@@ -54,7 +57,8 @@ sal_Int32 getINT32(const Any& _rAny)
sal_Int16 getINT16(const Any& _rAny) sal_Int16 getINT16(const Any& _rAny)
{ {
sal_Int16 nReturn = 0; sal_Int16 nReturn = 0;
OSL_VERIFY( _rAny >>= nReturn ); if(!(_rAny >>= nReturn))
SAL_WARN("comphelper", "conversion from Any to sal_Int16 failed");
return nReturn; return nReturn;
} }
...@@ -62,7 +66,8 @@ sal_Int16 getINT16(const Any& _rAny) ...@@ -62,7 +66,8 @@ sal_Int16 getINT16(const Any& _rAny)
double getDouble(const Any& _rAny) double getDouble(const Any& _rAny)
{ {
double nReturn = 0.0; double nReturn = 0.0;
OSL_VERIFY( _rAny >>= nReturn ); if(!(_rAny >>= nReturn))
SAL_WARN("comphelper", "conversion from Any to double failed");
return nReturn; return nReturn;
} }
...@@ -70,7 +75,8 @@ double getDouble(const Any& _rAny) ...@@ -70,7 +75,8 @@ double getDouble(const Any& _rAny)
float getFloat(const Any& _rAny) float getFloat(const Any& _rAny)
{ {
float nReturn = 0.0; float nReturn = 0.0;
OSL_VERIFY( _rAny >>= nReturn ); if(!(_rAny >>= nReturn))
SAL_WARN("comphelper", "conversion from Any to float failed");
return nReturn; return nReturn;
} }
...@@ -78,7 +84,8 @@ float getFloat(const Any& _rAny) ...@@ -78,7 +84,8 @@ float getFloat(const Any& _rAny)
OUString getString(const Any& _rAny) OUString getString(const Any& _rAny)
{ {
OUString nReturn; OUString nReturn;
OSL_VERIFY( _rAny >>= nReturn ); if(!(_rAny >>= nReturn))
SAL_WARN("comphelper", "conversion from Any to OUString failed");
return nReturn; return nReturn;
} }
......
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