sc: factor out common code
[LibreOffice.git] / basic / qa / cppunit / test_tdf149714.cxx
blob0c58038daedfbc1aa59a4c60242efa193a422299
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
11 #include <basic/sbstar.hxx>
12 #include <basic/sbmeth.hxx>
13 #include <cppunit/extensions/HelperMacros.h>
15 #include <unotest/directories.hxx>
17 namespace
19 class TestTdf149714 : public CppUnit::TestFixture
21 void testBitsPerPixel();
23 CPPUNIT_TEST_SUITE(TestTdf149714);
24 CPPUNIT_TEST(testBitsPerPixel);
25 CPPUNIT_TEST_SUITE_END();
27 StarBASICRef interpreter;
29 SbModuleRef Module()
31 test::Directories aDirectories;
32 OUString aDataFileName
33 = aDirectories.getURLFromSrc(u"basic/qa/cppunit/data/") + u"tdf149714.png";
34 OUString sBasic = uR"BAS(
36 Function GetBitsPerPixelAsString As String
37 DIM oProps(0) As New "com.sun.star.beans.PropertyValue"
38 DIM oProvider, oGraphic
40 oProps(0).Name = "URL"
41 oProps(0).Value = "$PNGFILENAME"
43 oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
44 oGraphic = oProvider.queryGraphic(oProps())
46 GetBitsPerPixelAsString = oGraphic.BitsPerPixel
48 End Function
50 )BAS"_ustr;
52 sBasic = sBasic.replaceFirst("$PNGFILENAME", aDataFileName);
54 interpreter = new StarBASIC();
55 auto mod = interpreter->MakeModule(u"BitsPerPixel"_ustr, sBasic);
57 CPPUNIT_ASSERT(mod->Compile());
58 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic());
59 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError());
60 CPPUNIT_ASSERT(mod->IsCompiled());
61 return mod;
65 void TestTdf149714::testBitsPerPixel()
67 auto m = Module();
68 auto GetBitsPerPixelAsString
69 = m->FindMethod(u"GetBitsPerPixelAsString"_ustr, SbxClassType::Method);
70 CPPUNIT_ASSERT_MESSAGE("Could not Find GetBitsPerPixelAsString in module",
71 GetBitsPerPixelAsString != nullptr);
73 SbxVariableRef returned = new SbxMethod{ *GetBitsPerPixelAsString };
74 CPPUNIT_ASSERT(returned->IsString());
76 // Without the fix in place this would fail with:
77 // - Expected: 24
78 // - Actual: True
79 CPPUNIT_ASSERT_EQUAL(u"24"_ustr, returned->GetOUString());
82 // Put the test suite in the registry
83 CPPUNIT_TEST_SUITE_REGISTRATION(TestTdf149714);
85 } // namespace
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */