From 9071cd6e59fb98ad8a2ddfb1019eaf950c716722 Mon Sep 17 00:00:00 2001 From: Adam Seskunas Date: Sat, 24 Feb 2024 21:19:37 -0800 Subject: [PATCH] tdf#149714 BitsPerPixel property of Graphic has Boolean UNO type - vcl change UNO type of UnoGraphicProperty::BitsPerPixel to sal_Int8 instead of sal_uInt8 which maps to BOOLEAN causing Basic to convert non-0 values to True - basic add CppUnitTest since thats where the problem was occuring Change-Id: I0111199151fb5e001b6362e1359ad90bb039f064 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163899 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- basic/CppunitTest_basic_macros.mk | 1 + basic/qa/cppunit/data/tdf149714.png | Bin 0 -> 1652 bytes basic/qa/cppunit/test_tdf149714.cxx | 86 ++++++++++++++++++++ vcl/source/graphic/UnoGraphicDescriptor.cxx | 2 +- 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 basic/qa/cppunit/data/tdf149714.png create mode 100644 basic/qa/cppunit/test_tdf149714.cxx diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk index 9d8050e7b4e5..a67508f800a2 100644 --- a/basic/CppunitTest_basic_macros.mk +++ b/basic/CppunitTest_basic_macros.mk @@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \ basic/qa/cppunit/test_vba \ basic/qa/cppunit/test_global_as_new \ basic/qa/cppunit/test_global_array \ + basic/qa/cppunit/test_tdf149714 \ )) $(eval $(call gb_CppunitTest_use_libraries,basic_macros, \ diff --git a/basic/qa/cppunit/data/tdf149714.png b/basic/qa/cppunit/data/tdf149714.png new file mode 100644 index 0000000000000000000000000000000000000000..d22b8451864d713f2cd5be1eb2addb7e123a8baa GIT binary patch literal 1652 zcmbW2XHXLc6vqQ7OHr{^Awq>#HbGHF5fQOrlPDX4j1&+;L`F#1L=aIVObH`pC?i7> z0uqLW69*7L3=kk;G@uA*2mu+ThFRM0_S$~<|Ni&C_u<{W_wH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urbLVNmtq)1=7wG*2}ei!XI5eM|&9n1vX;JDzWzC1kPa9=;DMq#=amY4*l z>&O2JeqChNI!AS-w?}H`>qJ(o=gygB?L?bSC}4|h^0p5PR4Oh_@ZqS+)bVBIoNMxDkH2--evAu~703WPD5Fp=`9tv7i+ zb2qMuRiOSfcHG2&IrKU#!>g|F+TmBoSUZLFys?@=H(jHRLM{0qX;c;iYwFHPDIc#j zy(wE2-zF>t{$fh^Q0S^_a$xr>9$54bfh^Ngj`nw(-w0N+7OC7y7+%RBJk3iyR^_HC yt-sPhO?yT;Y(Z3o>@~uk%+dchx82mwL8;4 literal 0 HcmV?d00001 diff --git a/basic/qa/cppunit/test_tdf149714.cxx b/basic/qa/cppunit/test_tdf149714.cxx new file mode 100644 index 000000000000..76713508560c --- /dev/null +++ b/basic/qa/cppunit/test_tdf149714.cxx @@ -0,0 +1,86 @@ +/* -*- 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 +#include +#include +#include + +#include + +namespace +{ +class TestTdf149714 : public CppUnit::TestFixture +{ + void testBitsPerPixel(); + + CPPUNIT_TEST_SUITE(TestTdf149714); + CPPUNIT_TEST(testBitsPerPixel); + CPPUNIT_TEST_SUITE_END(); + + StarBASICRef interpreter; + + SbModuleRef Module() + { + test::Directories aDirectories; + OUString aDataFileName + = aDirectories.getURLFromSrc(u"basic/qa/cppunit/data/") + u"tdf149714.png"; + OUString sBasic = uR"BAS( + +Function GetBitsPerPixelAsString As String + DIM oProps(0) As New "com.sun.star.beans.PropertyValue" + DIM oProvider, oGraphic + + oProps(0).Name = "URL" + oProps(0).Value = "$PNGFILENAME" + + oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") + oGraphic = oProvider.queryGraphic(oProps()) + + GetBitsPerPixelAsString = oGraphic.BitsPerPixel + +End Function + +)BAS"_ustr; + + sBasic = sBasic.replaceFirst("$PNGFILENAME", aDataFileName); + + interpreter = new StarBASIC(); + auto mod = interpreter->MakeModule("BitsPerPixel", sBasic); + + CPPUNIT_ASSERT(mod->Compile()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError()); + CPPUNIT_ASSERT(mod->IsCompiled()); + return mod; + } +}; + +void TestTdf149714::testBitsPerPixel() +{ + auto m = Module(); + auto GetBitsPerPixelAsString = m->FindMethod("GetBitsPerPixelAsString", SbxClassType::Method); + CPPUNIT_ASSERT_MESSAGE("Could not Find GetBitsPerPixelAsString in module", + GetBitsPerPixelAsString != nullptr); + + SbxVariableRef returned = new SbxMethod{ *GetBitsPerPixelAsString }; + CPPUNIT_ASSERT(returned->IsString()); + + // Without the fix in place this would fail with: + // - Expected: 24 + // - Actual: True + CPPUNIT_ASSERT_EQUAL(OUString{ "24" }, returned->GetOUString()); +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION(TestTdf149714); + +} // namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/source/graphic/UnoGraphicDescriptor.cxx b/vcl/source/graphic/UnoGraphicDescriptor.cxx index e83ac98959f8..32ffe48fd68f 100644 --- a/vcl/source/graphic/UnoGraphicDescriptor.cxx +++ b/vcl/source/graphic/UnoGraphicDescriptor.cxx @@ -236,7 +236,7 @@ rtl::Reference<::comphelper::PropertySetInfo> GraphicDescriptor::createPropertyS { OUString( "MimeType" ), static_cast< sal_Int32 >( UnoGraphicProperty::MimeType ), cppu::UnoType< OUString >::get(), beans::PropertyAttribute::READONLY, 0 }, { OUString( "SizePixel" ), static_cast< sal_Int32 >( UnoGraphicProperty::SizePixel ), cppu::UnoType< awt::Size >::get(), beans::PropertyAttribute::READONLY, 0 }, { OUString( "Size100thMM" ), static_cast< sal_Int32 >( UnoGraphicProperty::Size100thMM ), cppu::UnoType< awt::Size >::get(), beans::PropertyAttribute::READONLY, 0 }, - { OUString( "BitsPerPixel" ), static_cast< sal_Int32 >( UnoGraphicProperty::BitsPerPixel ), cppu::UnoType< sal_uInt8 >::get(), beans::PropertyAttribute::READONLY, 0 }, + { OUString( "BitsPerPixel" ), static_cast< sal_Int32 >( UnoGraphicProperty::BitsPerPixel ), cppu::UnoType< sal_Int8 >::get(), beans::PropertyAttribute::READONLY, 0 }, { OUString( "Transparent" ), static_cast< sal_Int32 >( UnoGraphicProperty::Transparent ), cppu::UnoType< sal_Bool >::get(), beans::PropertyAttribute::READONLY, 0 }, { OUString( "Alpha" ), static_cast< sal_Int32 >( UnoGraphicProperty::Alpha ), cppu::UnoType< sal_Bool >::get(), beans::PropertyAttribute::READONLY, 0 }, { OUString( "Animated" ), static_cast< sal_Int32 >( UnoGraphicProperty::Animated ), cppu::UnoType< sal_Bool >::get(), beans::PropertyAttribute::READONLY, 0 },