diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-04 17:31:55 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-08 11:54:22 +0100 |
commit | 248be1fe7d31499fe7e237bb15ec67b55962c1a7 (patch) | |
tree | d2a3693af5d555f5c6cca31b625a9001af21e869 /svx/qa | |
parent | 444bf8710d5da7b584fbcb94693e4ed8d2e29297 (diff) |
UnoApiTest: simplify code by using tempfile member
SwModelTestBase does the same. this will help to make
SwModelTestBase inherit from UnoApiTest
Change-Id: If1c824cf92f0e8b70253e4d5fdeddcaa521d4632
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142287
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svx/qa')
-rw-r--r-- | svx/qa/unit/core.cxx | 5 | ||||
-rw-r--r-- | svx/qa/unit/customshapes.cxx | 24 | ||||
-rw-r--r-- | svx/qa/unit/svdraw.cxx | 4 | ||||
-rw-r--r-- | svx/qa/unit/unodraw.cxx | 4 | ||||
-rw-r--r-- | svx/qa/unit/xoutdev.cxx | 12 |
5 files changed, 17 insertions, 32 deletions
diff --git a/svx/qa/unit/core.cxx b/svx/qa/unit/core.cxx index c3a9d3e3a2de..e627215807d2 100644 --- a/svx/qa/unit/core.cxx +++ b/svx/qa/unit/core.cxx @@ -43,16 +43,15 @@ CPPUNIT_TEST_FIXTURE(Test, testChartExportToPdf) uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); // When exporting that chart to PDF: - utl::TempFileNamed aTempFile; GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "application/pdf", - aTempFile.GetURL()); + maTempFile.GetURL()); // Then make sure we get a valid, non-empty PDF: auto pPdfium = vcl::pdf::PDFiumLibrary::get(); if (!pPdfium) return; SvMemoryStream aMemory; - aMemory.WriteStream(*aTempFile.GetStream(StreamMode::READ)); + aMemory.WriteStream(*maTempFile.GetStream(StreamMode::READ)); std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = pPdfium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); // Without the accompanying fix in place, this test would have failed, because the output was diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx index 7d711f67d17e..efe322d54e76 100644 --- a/svx/qa/unit/customshapes.cxx +++ b/svx/qa/unit/customshapes.cxx @@ -162,14 +162,12 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf145700_3D_NonUI) // Generate bitmap from shape uno::Reference<drawing::XShape> xShape = getShape(0); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", aTempFile.GetURL()); + GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", maTempFile.GetURL()); // Read bitmap and test color // The expected values are taken from an image generated by Word // Without the changed methods the colors were in range RGB(17,11,17) to RGB(87,55,89). - SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ); + SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ); vcl::PngImageReader aPNGReader(aFileStream); BitmapEx aBMPEx = aPNGReader.read(); Bitmap aBMP = aBMPEx.GetBitmap(); @@ -200,14 +198,12 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf145700_3D_FrontLightDim) // Generate bitmap from shape uno::Reference<drawing::XShape> xShape = getShape(0); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", aTempFile.GetURL()); + GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", maTempFile.GetURL()); // Read bitmap and test color // The expected values are taken from an image generated by Word // Without the changed methods the nColorDistance was 476 and 173 respectively. - SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ); + SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ); vcl::PngImageReader aPNGReader(aFileStream); BitmapEx aBMPEx = aPNGReader.read(); Bitmap aBMP = aBMPEx.GetBitmap(); @@ -231,12 +227,10 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf145700_3D_FirstLightHarsh) // Generate bitmap from shape uno::Reference<drawing::XShape> xShape = getShape(0); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", aTempFile.GetURL()); + GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", maTempFile.GetURL()); // Read bitmap and test color in center - SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ); + SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ); vcl::PngImageReader aPNGReader(aFileStream); BitmapEx aBMPEx = aPNGReader.read(); Bitmap aBMP = aBMPEx.GetBitmap(); @@ -1198,9 +1192,7 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf148501_OctagonBevel) // Generate bitmap from shape uno::Reference<drawing::XShape> xShape = getShape(0); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", aTempFile.GetURL()); + GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "image/png", maTempFile.GetURL()); // Read bitmap and test color // expected in order top-left, top, top-right, right, bottom-right: @@ -1208,7 +1200,7 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf148501_OctagonBevel) // Without applied patch the colors were: // RGB(193|214,236), RGB(193|214,236), RGB(80|111|145), RGB(23|32|41), RGB(193|214|236) // So we test segments top, right and bottom-right. - SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ); + SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ); vcl::PngImageReader aPNGReader(aFileStream); BitmapEx aBMPEx = aPNGReader.read(); Bitmap aBMP = aBMPEx.GetBitmap(); diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 82824d048c80..4373d2b5d608 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -494,10 +494,10 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testPageViewDrawLayerClip) loadFromURL(u"page-view-draw-layer-clip.docx"); // When saving that document to PDF: - utl::TempFileNamed aTempFile = save("writer_pdf_Export"); + save("writer_pdf_Export"); // Then make sure that line shape gets clipped: - SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); SvMemoryStream aMemory; aMemory.WriteStream(aFile); std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); diff --git a/svx/qa/unit/unodraw.cxx b/svx/qa/unit/unodraw.cxx index 5b75d0352813..aa8039737148 100644 --- a/svx/qa/unit/unodraw.cxx +++ b/svx/qa/unit/unodraw.cxx @@ -66,10 +66,8 @@ CPPUNIT_TEST_FIXTURE(UnodrawTest, testWriterGraphicExport) // picture. xExportFilter->setSourceDocument(xShape); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); uno::Sequence<beans::PropertyValue> aProperties( - comphelper::InitPropertySequence({ { "URL", uno::Any(aTempFile.GetURL()) }, + comphelper::InitPropertySequence({ { "URL", uno::Any(maTempFile.GetURL()) }, { "MediaType", uno::Any(OUString("image/jpeg")) } })); CPPUNIT_ASSERT(xExportFilter->filter(aProperties)); } diff --git a/svx/qa/unit/xoutdev.cxx b/svx/qa/unit/xoutdev.cxx index 52eb64ed7b1f..db28fa5b9279 100644 --- a/svx/qa/unit/xoutdev.cxx +++ b/svx/qa/unit/xoutdev.cxx @@ -49,15 +49,13 @@ CPPUNIT_TEST_FIXTURE(XOutdevTest, testPdfGraphicExport) GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, aStream)); // Export it. - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); XOutFlags const eFlags = XOutFlags::DontExpandFilename | XOutFlags::DontAddExtension | XOutFlags::UseNativeIfPossible; - OUString aTempURL = aTempFile.GetURL(); + OUString aTempURL = maTempFile.GetURL(); XOutBitmap::WriteGraphic(aGraphic, aTempURL, "pdf", eFlags); // Assert that the output looks like a PDF. - SvStream* pStream = aTempFile.GetStream(StreamMode::READ); + SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream->TellEnd() > 5); sal_uInt8 sFirstBytes[5]; pStream->ReadBytes(sFirstBytes, 5); @@ -77,14 +75,12 @@ CPPUNIT_TEST_FIXTURE(XOutdevTest, testTdf60684) GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, aStream)); // Export it. - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); XOutFlags const eFlags = XOutFlags::DontExpandFilename | XOutFlags::DontAddExtension | XOutFlags::UseNativeIfPossible; - OUString aTempURL = aTempFile.GetURL(); + OUString aTempURL = maTempFile.GetURL(); XOutBitmap::WriteGraphic(aGraphic, aTempURL, "png", eFlags); - SvStream* pStream = aTempFile.GetStream(StreamMode::READ); + SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream->TellEnd() > 4); sal_uInt8 sFirstBytes[4]; pStream->ReadBytes(sFirstBytes, 4); |