From 9071cd6e59fb98ad8a2ddfb1019eaf950c716722 Mon Sep 17 00:00:00 2001 From: Adam Seskunas Date: Sat, 24 Feb 2024 21:19:37 -0800 Subject: 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/qa/cppunit/data/tdf149714.png | Bin 0 -> 1652 bytes basic/qa/cppunit/test_tdf149714.cxx | 86 ++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 basic/qa/cppunit/data/tdf149714.png create mode 100644 basic/qa/cppunit/test_tdf149714.cxx (limited to 'basic/qa') diff --git a/basic/qa/cppunit/data/tdf149714.png b/basic/qa/cppunit/data/tdf149714.png new file mode 100644 index 000000000000..d22b8451864d Binary files /dev/null and b/basic/qa/cppunit/data/tdf149714.png differ 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: */ -- cgit v1.2.3