2018-04-28 13:37:17 +09:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2020-05-11 11:09:50 +02:00
|
|
|
#include <sal/config.h>
|
|
|
|
#include <config_oox.h>
|
2022-09-01 14:59:51 +03:00
|
|
|
#include <com/sun/star/graphic/XGraphic.hpp>
|
|
|
|
#include <com/sun/star/graphic/XGraphicTransformer.hpp>
|
2018-04-28 13:37:17 +09:00
|
|
|
#include <cppunit/TestAssert.h>
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include <cppunit/plugin/TestPlugIn.h>
|
2020-12-20 19:54:57 +02:00
|
|
|
#include <test/bootstrapfixture.hxx>
|
2018-04-28 13:37:17 +09:00
|
|
|
|
2018-05-17 15:15:01 +09:00
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
|
|
|
|
2020-12-19 01:09:27 +11:00
|
|
|
#include <vcl/BitmapReadAccess.hxx>
|
2018-04-28 13:37:17 +09:00
|
|
|
#include <vcl/graph.hxx>
|
|
|
|
#include <vcl/graphicfilter.hxx>
|
|
|
|
#include <tools/stream.hxx>
|
2019-11-18 21:18:24 +01:00
|
|
|
#include <unotest/directories.hxx>
|
2020-04-25 12:06:53 +02:00
|
|
|
#include <comphelper/DirectoryHelper.hxx>
|
|
|
|
#include <comphelper/hash.hxx>
|
|
|
|
#include <unotools/ucbstreamhelper.hxx>
|
2020-11-25 18:01:08 +01:00
|
|
|
#include <unotools/tempfile.hxx>
|
2020-12-07 17:10:56 +01:00
|
|
|
#include <vcl/cvtgrf.hxx>
|
2020-12-09 09:38:48 +01:00
|
|
|
#include <vcl/metaact.hxx>
|
2021-06-11 15:51:32 +02:00
|
|
|
#include <vcl/wmf.hxx>
|
2020-04-25 12:06:53 +02:00
|
|
|
|
|
|
|
#include <impgraph.hxx>
|
2020-12-07 17:10:56 +01:00
|
|
|
#include <graphic/GraphicFormatDetector.hxx>
|
2018-04-28 13:37:17 +09:00
|
|
|
|
2020-05-11 11:09:50 +02:00
|
|
|
#if USE_TLS_NSS
|
|
|
|
#include <nss.h>
|
|
|
|
#endif
|
|
|
|
|
2018-05-17 15:15:01 +09:00
|
|
|
using namespace css;
|
|
|
|
|
2018-04-28 13:37:17 +09:00
|
|
|
namespace
|
|
|
|
{
|
2020-12-20 19:54:57 +02:00
|
|
|
class GraphicTest : public test::BootstrapFixture
|
2018-04-28 13:37:17 +09:00
|
|
|
{
|
2020-05-11 11:09:50 +02:00
|
|
|
public:
|
|
|
|
~GraphicTest();
|
|
|
|
|
|
|
|
private:
|
2018-04-28 13:37:17 +09:00
|
|
|
void testUnloadedGraphic();
|
2018-05-17 15:15:01 +09:00
|
|
|
void testUnloadedGraphicLoading();
|
2019-09-30 21:36:56 +02:00
|
|
|
void testUnloadedGraphicWmf();
|
2019-10-31 01:36:22 +11:00
|
|
|
void testUnloadedGraphicAlpha();
|
2019-11-18 21:18:24 +01:00
|
|
|
void testUnloadedGraphicSizeUnit();
|
2020-12-06 21:14:07 +09:00
|
|
|
|
2020-11-25 18:01:08 +01:00
|
|
|
void testWMFRoundtrip();
|
2021-06-11 15:51:32 +02:00
|
|
|
void testWMFWithEmfPlusRoundtrip();
|
2020-12-07 17:10:56 +01:00
|
|
|
void testEmfToWmfConversion();
|
2018-04-28 13:37:17 +09:00
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
void testSwappingGraphic_PNG_WithGfxLink();
|
|
|
|
void testSwappingGraphic_PNG_WithoutGfxLink();
|
|
|
|
void testSwappingGraphicProperties_PNG_WithGfxLink();
|
|
|
|
void testSwappingGraphicProperties_PNG_WithoutGfxLink();
|
|
|
|
|
|
|
|
void testSwappingVectorGraphic_SVG_WithGfxLink();
|
|
|
|
void testSwappingVectorGraphic_SVG_WithoutGfxLink();
|
|
|
|
void testSwappingGraphicProperties_SVG_WithGfxLink();
|
|
|
|
void testSwappingGraphicProperties_SVG_WithoutGfxLink();
|
|
|
|
|
|
|
|
void testSwappingVectorGraphic_PDF_WithGfxLink();
|
|
|
|
void testSwappingVectorGraphic_PDF_WithoutGfxLink();
|
|
|
|
|
|
|
|
void testSwappingAnimationGraphic_GIF_WithGfxLink();
|
|
|
|
void testSwappingAnimationGraphic_GIF_WithoutGfxLink();
|
|
|
|
|
2021-02-15 14:30:01 +09:00
|
|
|
void testLoadMET();
|
|
|
|
void testLoadBMP();
|
|
|
|
void testLoadPSD();
|
|
|
|
void testLoadTGA();
|
|
|
|
void testLoadXBM();
|
|
|
|
void testLoadXPM();
|
|
|
|
void testLoadPCX();
|
|
|
|
void testLoadEPS();
|
2022-01-13 15:59:49 +01:00
|
|
|
void testLoadWEBP();
|
2022-09-08 13:37:35 +02:00
|
|
|
void testLoadSVGZ();
|
2021-02-15 14:30:01 +09:00
|
|
|
|
2021-04-15 17:39:48 +02:00
|
|
|
void testAvailableThreaded();
|
2022-09-01 14:59:51 +03:00
|
|
|
void testColorChangeToTransparent();
|
2021-04-15 17:39:48 +02:00
|
|
|
|
2018-04-28 13:37:17 +09:00
|
|
|
CPPUNIT_TEST_SUITE(GraphicTest);
|
|
|
|
CPPUNIT_TEST(testUnloadedGraphic);
|
2018-05-17 15:15:01 +09:00
|
|
|
CPPUNIT_TEST(testUnloadedGraphicLoading);
|
2019-09-30 21:36:56 +02:00
|
|
|
CPPUNIT_TEST(testUnloadedGraphicWmf);
|
2019-10-31 01:36:22 +11:00
|
|
|
CPPUNIT_TEST(testUnloadedGraphicAlpha);
|
2019-11-18 21:18:24 +01:00
|
|
|
CPPUNIT_TEST(testUnloadedGraphicSizeUnit);
|
2020-11-25 18:01:08 +01:00
|
|
|
CPPUNIT_TEST(testWMFRoundtrip);
|
2021-06-11 15:51:32 +02:00
|
|
|
CPPUNIT_TEST(testWMFWithEmfPlusRoundtrip);
|
2020-12-07 17:10:56 +01:00
|
|
|
CPPUNIT_TEST(testEmfToWmfConversion);
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
CPPUNIT_TEST(testSwappingGraphic_PNG_WithGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingGraphic_PNG_WithoutGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingGraphicProperties_PNG_WithGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingGraphicProperties_PNG_WithoutGfxLink);
|
|
|
|
|
|
|
|
CPPUNIT_TEST(testSwappingVectorGraphic_SVG_WithGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingVectorGraphic_SVG_WithoutGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingGraphicProperties_SVG_WithGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingGraphicProperties_SVG_WithoutGfxLink);
|
|
|
|
|
|
|
|
CPPUNIT_TEST(testSwappingVectorGraphic_PDF_WithGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingVectorGraphic_PDF_WithoutGfxLink);
|
|
|
|
|
|
|
|
CPPUNIT_TEST(testSwappingAnimationGraphic_GIF_WithGfxLink);
|
|
|
|
CPPUNIT_TEST(testSwappingAnimationGraphic_GIF_WithoutGfxLink);
|
2021-02-15 14:30:01 +09:00
|
|
|
|
|
|
|
CPPUNIT_TEST(testLoadMET);
|
|
|
|
CPPUNIT_TEST(testLoadBMP);
|
|
|
|
CPPUNIT_TEST(testLoadPSD);
|
|
|
|
CPPUNIT_TEST(testLoadTGA);
|
|
|
|
CPPUNIT_TEST(testLoadXBM);
|
|
|
|
CPPUNIT_TEST(testLoadXPM);
|
|
|
|
CPPUNIT_TEST(testLoadPCX);
|
|
|
|
CPPUNIT_TEST(testLoadEPS);
|
2022-01-13 15:59:49 +01:00
|
|
|
CPPUNIT_TEST(testLoadWEBP);
|
2022-09-08 13:37:35 +02:00
|
|
|
CPPUNIT_TEST(testLoadSVGZ);
|
2021-02-15 14:30:01 +09:00
|
|
|
|
2021-04-15 17:39:48 +02:00
|
|
|
CPPUNIT_TEST(testAvailableThreaded);
|
2022-09-01 14:59:51 +03:00
|
|
|
CPPUNIT_TEST(testColorChangeToTransparent);
|
2021-04-15 17:39:48 +02:00
|
|
|
|
2018-04-28 13:37:17 +09:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
2020-05-11 11:09:50 +02:00
|
|
|
GraphicTest::~GraphicTest()
|
|
|
|
{
|
|
|
|
#if USE_TLS_NSS
|
|
|
|
NSS_Shutdown();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-10-31 01:36:22 +11:00
|
|
|
BitmapEx createBitmap(bool alpha = false)
|
2018-04-28 13:37:17 +09:00
|
|
|
{
|
2021-03-13 12:00:28 +09:00
|
|
|
Bitmap aBitmap(Size(120, 100), vcl::PixelFormat::N24_BPP);
|
2018-04-28 13:37:17 +09:00
|
|
|
aBitmap.Erase(COL_LIGHTRED);
|
|
|
|
|
2019-10-31 01:36:22 +11:00
|
|
|
aBitmap.SetPrefSize(Size(6000, 5000));
|
|
|
|
aBitmap.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
|
|
|
|
|
|
|
|
if (alpha)
|
|
|
|
{
|
|
|
|
sal_uInt8 uAlphaValue = 0x80;
|
|
|
|
AlphaMask aAlphaMask(Size(120, 100), &uAlphaValue);
|
|
|
|
|
|
|
|
return BitmapEx(aBitmap, aAlphaMask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return BitmapEx(aBitmap);
|
|
|
|
}
|
2018-04-28 13:37:17 +09:00
|
|
|
}
|
|
|
|
|
2020-11-13 14:29:59 +02:00
|
|
|
void createBitmapAndExportForType(SvStream& rStream, std::u16string_view sType, bool alpha)
|
2018-04-28 13:37:17 +09:00
|
|
|
{
|
2019-10-31 01:36:22 +11:00
|
|
|
BitmapEx aBitmapEx = createBitmap(alpha);
|
2018-04-28 13:37:17 +09:00
|
|
|
|
2018-05-17 15:15:01 +09:00
|
|
|
uno::Sequence<beans::PropertyValue> aFilterData;
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName(sType);
|
2022-04-28 14:12:35 +02:00
|
|
|
rGraphicFilter.ExportGraphic(aBitmapEx, u"none", rStream, nFilterFormat, &aFilterData);
|
2018-04-28 13:37:17 +09:00
|
|
|
|
|
|
|
rStream.Seek(STREAM_SEEK_TO_BEGIN);
|
|
|
|
}
|
|
|
|
|
2020-11-13 14:29:59 +02:00
|
|
|
Graphic makeUnloadedGraphic(std::u16string_view sType, bool alpha = false)
|
2018-04-28 13:37:17 +09:00
|
|
|
{
|
|
|
|
SvMemoryStream aStream;
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
2019-10-31 01:36:22 +11:00
|
|
|
createBitmapAndExportForType(aStream, sType, alpha);
|
2018-04-28 13:37:17 +09:00
|
|
|
return rGraphicFilter.ImportUnloadedGraphic(aStream);
|
|
|
|
}
|
|
|
|
|
2020-04-25 12:06:53 +02:00
|
|
|
std::string toHexString(const std::vector<unsigned char>& a)
|
|
|
|
{
|
|
|
|
std::stringstream aStrm;
|
|
|
|
for (auto& i : a)
|
|
|
|
{
|
|
|
|
aStrm << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aStrm.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<SvStream> createStream(OUString const& rSwapFileURL)
|
|
|
|
{
|
|
|
|
std::unique_ptr<SvStream> xStream;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xStream = ::utl::UcbStreamHelper::CreateStream(
|
|
|
|
rSwapFileURL, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE);
|
|
|
|
}
|
|
|
|
catch (const css::uno::Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return xStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<unsigned char> calculateHash(std::unique_ptr<SvStream>& rStream)
|
|
|
|
{
|
|
|
|
comphelper::Hash aHashEngine(comphelper::HashType::SHA1);
|
|
|
|
const sal_uInt32 nSize(rStream->remainingSize());
|
|
|
|
std::vector<sal_uInt8> aData(nSize);
|
|
|
|
aHashEngine.update(aData.data(), nSize);
|
|
|
|
return aHashEngine.finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkBitmap(Graphic& rGraphic)
|
|
|
|
{
|
|
|
|
bool bResult = true;
|
|
|
|
|
|
|
|
Bitmap aBitmap(rGraphic.GetBitmapEx().GetBitmap());
|
|
|
|
{
|
|
|
|
Bitmap::ScopedReadAccess pReadAccess(aBitmap);
|
2020-10-19 15:12:38 +02:00
|
|
|
for (tools::Long y = 0; y < rGraphic.GetSizePixel().Height(); y++)
|
2020-04-25 12:06:53 +02:00
|
|
|
{
|
2020-10-19 15:12:38 +02:00
|
|
|
for (tools::Long x = 0; x < rGraphic.GetSizePixel().Width(); x++)
|
2020-04-25 12:06:53 +02:00
|
|
|
{
|
|
|
|
if (pReadAccess->HasPalette())
|
|
|
|
{
|
|
|
|
sal_uInt32 nIndex = pReadAccess->GetPixelIndex(y, x);
|
|
|
|
Color aColor = pReadAccess->GetPaletteColor(nIndex);
|
|
|
|
bResult &= (aColor == Color(0xff, 0x00, 0x00));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Color aColor = pReadAccess->GetPixel(y, x);
|
|
|
|
bResult &= (aColor == Color(0xff, 0x00, 0x00));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
2021-01-10 16:41:27 +00:00
|
|
|
constexpr OUStringLiteral DATA_DIRECTORY = u"/vcl/qa/cppunit/data/";
|
|
|
|
constexpr OUStringLiteral PDFEXPORT_DATA_DIRECTORY = u"/vcl/qa/cppunit/pdfexport/data/";
|
2019-11-18 21:18:24 +01:00
|
|
|
|
2021-02-15 14:30:01 +09:00
|
|
|
Graphic loadGraphic(std::u16string_view const& rFilename)
|
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aFilename = aDirectories.getURLFromSrc(DATA_DIRECTORY) + rFilename;
|
|
|
|
SvFileStream aFileStream(aFilename, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
|
|
|
|
Graphic aGraphic;
|
2022-04-28 14:12:35 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, rGraphicFilter.ImportGraphic(aGraphic, u"", aFileStream,
|
|
|
|
GRFILTER_FORMAT_DONTKNOW));
|
2021-02-15 14:30:01 +09:00
|
|
|
return aGraphic;
|
|
|
|
}
|
|
|
|
|
2021-04-15 17:39:48 +02:00
|
|
|
Graphic importUnloadedGraphic(std::u16string_view const& rFilename)
|
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aFilename = aDirectories.getURLFromSrc(DATA_DIRECTORY) + rFilename;
|
|
|
|
SvFileStream aFileStream(aFilename, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
return rGraphicFilter.ImportUnloadedGraphic(aFileStream);
|
|
|
|
}
|
|
|
|
|
2018-04-28 13:37:17 +09:00
|
|
|
void GraphicTest::testUnloadedGraphic()
|
|
|
|
{
|
|
|
|
// make unloaded test graphic
|
2020-11-13 14:29:59 +02:00
|
|
|
Graphic aGraphic = makeUnloadedGraphic(u"png");
|
2018-04-28 13:37:17 +09:00
|
|
|
Graphic aGraphic2 = aGraphic;
|
|
|
|
|
|
|
|
// check available
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic2.isAvailable());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic2.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic2.isAvailable());
|
|
|
|
|
|
|
|
// check GetSizePixel doesn't load graphic
|
2020-11-13 14:29:59 +02:00
|
|
|
aGraphic = makeUnloadedGraphic(u"png");
|
2018-04-28 13:37:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
2020-11-13 09:04:59 +03:00
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
|
2018-04-28 13:37:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
2019-10-31 01:36:22 +11:00
|
|
|
// check GetPrefSize doesn't load graphic
|
2020-11-13 09:04:59 +03:00
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(6000), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(5000), aGraphic.GetPrefSize().Height());
|
2019-10-31 01:36:22 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
2018-04-28 13:37:17 +09:00
|
|
|
// check GetSizeBytes loads graphic
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
2020-04-25 12:06:53 +02:00
|
|
|
|
|
|
|
//check Type
|
2020-11-13 14:29:59 +02:00
|
|
|
aGraphic = makeUnloadedGraphic(u"png");
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
2018-04-28 13:37:17 +09:00
|
|
|
}
|
|
|
|
|
2018-05-17 15:15:01 +09:00
|
|
|
void GraphicTest::testUnloadedGraphicLoading()
|
|
|
|
{
|
2022-01-13 15:59:49 +01:00
|
|
|
const OUString aFormats[] = { "png", "gif", "jpg", "tif", "webp" };
|
2018-05-17 15:15:01 +09:00
|
|
|
|
|
|
|
for (OUString const& sFormat : aFormats)
|
|
|
|
{
|
|
|
|
Graphic aGraphic = makeUnloadedGraphic(sFormat);
|
|
|
|
|
|
|
|
// check available
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
2020-11-13 09:04:59 +03:00
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
|
2018-05-17 15:15:01 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
|
2020-04-25 12:06:53 +02:00
|
|
|
if (sFormat != "jpg")
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
|
2018-05-17 15:15:01 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 21:36:56 +02:00
|
|
|
void GraphicTest::testUnloadedGraphicWmf()
|
|
|
|
{
|
|
|
|
// Create some in-memory WMF data, set its own preferred size to 99x99.
|
|
|
|
BitmapEx aBitmapEx = createBitmap();
|
|
|
|
SvMemoryStream aStream;
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
2020-11-13 14:29:59 +02:00
|
|
|
sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName(u"wmf");
|
2019-09-30 21:36:56 +02:00
|
|
|
Graphic aGraphic(aBitmapEx);
|
|
|
|
aGraphic.SetPrefSize(Size(99, 99));
|
|
|
|
aGraphic.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
|
2022-04-28 14:12:35 +02:00
|
|
|
rGraphicFilter.ExportGraphic(aGraphic, u"none", aStream, nFilterFormat);
|
2019-09-30 21:36:56 +02:00
|
|
|
aStream.Seek(STREAM_SEEK_TO_BEGIN);
|
|
|
|
|
|
|
|
// Now lazy-load this WMF data, with a custom preferred size of 42x42.
|
|
|
|
Size aMtfSize100(42, 42);
|
|
|
|
aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100);
|
|
|
|
aGraphic.makeAvailable();
|
|
|
|
|
|
|
|
// Without the accompanying fix in place, this test would have failed with:
|
|
|
|
// - Expected: 42x42
|
|
|
|
// - Actual : 99x99
|
2019-10-01 12:26:03 +02:00
|
|
|
// i.e. the custom preferred size was lost after lazy-load.
|
2019-09-30 21:36:56 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Size(42, 42), aGraphic.GetPrefSize());
|
|
|
|
}
|
|
|
|
|
2019-10-31 01:36:22 +11:00
|
|
|
void GraphicTest::testUnloadedGraphicAlpha()
|
|
|
|
{
|
|
|
|
// make unloaded test graphic with alpha
|
2020-11-13 14:29:59 +02:00
|
|
|
Graphic aGraphic = makeUnloadedGraphic(u"png", true);
|
2019-10-31 01:36:22 +11:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsAlpha());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsTransparent());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// make unloaded test graphic without alpha
|
2020-11-13 14:29:59 +02:00
|
|
|
aGraphic = makeUnloadedGraphic(u"png", false);
|
2019-10-31 01:36:22 +11:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsAlpha());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsTransparent());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
}
|
|
|
|
|
2019-11-18 21:18:24 +01:00
|
|
|
void GraphicTest::testUnloadedGraphicSizeUnit()
|
|
|
|
{
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "inch-size.emf";
|
|
|
|
Size aMtfSize100(42, 42);
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100);
|
2020-12-26 12:41:08 +09:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(Size(42, 42), aGraphic.GetPrefSize());
|
|
|
|
|
|
|
|
// Force it to swap in
|
2019-11-18 21:18:24 +01:00
|
|
|
aGraphic.makeAvailable();
|
|
|
|
|
|
|
|
// Without the accompanying fix in place, this test would have failed with:
|
|
|
|
// - Expected: 400x363
|
|
|
|
// - Actual : 42x42
|
|
|
|
// i.e. a mm100 size was used as a hint and the inch size was set for a non-matching unit.
|
|
|
|
CPPUNIT_ASSERT_EQUAL(Size(400, 363), aGraphic.GetPrefSize());
|
|
|
|
}
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
void GraphicTest::testWMFRoundtrip()
|
|
|
|
{
|
|
|
|
// Load a WMF file.
|
|
|
|
test::Directories aDirectories;
|
2020-12-28 17:56:40 +01:00
|
|
|
OUString aURL = aDirectories.getURLFromSrc(u"vcl/qa/cppunit/data/roundtrip.wmf");
|
2020-12-06 21:14:07 +09:00
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
sal_uInt64 nExpectedSize = aStream.TellEnd();
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
|
|
|
|
|
|
|
// Save as WMF.
|
|
|
|
utl::TempFile aTempFile;
|
|
|
|
aTempFile.EnableKillingFile();
|
|
|
|
sal_uInt16 nFormat = rGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
|
|
|
|
SvStream& rOutStream = *aTempFile.GetStream(StreamMode::READWRITE);
|
2022-04-28 14:12:35 +02:00
|
|
|
rGraphicFilter.ExportGraphic(aGraphic, u"", rOutStream, nFormat);
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
// Check if we preserved the WMF data perfectly.
|
|
|
|
sal_uInt64 nActualSize = rOutStream.TellEnd();
|
|
|
|
|
|
|
|
// Without the accompanying fix in place, this test would have failed with:
|
|
|
|
// - Expected: 6475
|
|
|
|
// - Actual : 2826
|
|
|
|
// i.e. we lost some of the WMF data on roundtrip.
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nExpectedSize, nActualSize);
|
|
|
|
}
|
|
|
|
|
2021-06-11 15:51:32 +02:00
|
|
|
int getEmfPlusActionsCount(const Graphic& graphic)
|
|
|
|
{
|
|
|
|
const GDIMetaFile& metafile = graphic.GetGDIMetaFile();
|
|
|
|
int emfPlusCount = 0;
|
|
|
|
for (size_t i = 0; i < metafile.GetActionSize(); ++i)
|
|
|
|
{
|
|
|
|
MetaAction* action = metafile.GetAction(i);
|
|
|
|
if (action->GetType() == MetaActionType::COMMENT)
|
|
|
|
{
|
|
|
|
const MetaCommentAction* commentAction = static_cast<const MetaCommentAction*>(action);
|
|
|
|
if (commentAction->GetComment() == "EMF_PLUS")
|
|
|
|
++emfPlusCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return emfPlusCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getPolygonActionsCount(const Graphic& graphic)
|
|
|
|
{
|
|
|
|
const GDIMetaFile& metafile = graphic.GetGDIMetaFile();
|
|
|
|
int polygonCount = 0;
|
|
|
|
for (size_t i = 0; i < metafile.GetActionSize(); ++i)
|
|
|
|
{
|
|
|
|
MetaAction* action = metafile.GetAction(i);
|
|
|
|
if (action->GetType() == MetaActionType::POLYGON)
|
|
|
|
++polygonCount;
|
|
|
|
}
|
|
|
|
return polygonCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testWMFWithEmfPlusRoundtrip()
|
|
|
|
{
|
|
|
|
// Load a WMF file.
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(u"vcl/qa/cppunit/data/wmf-embedded-emfplus.wmf");
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
sal_uInt64 nExpectedSize = aStream.TellEnd();
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_GREATER(0, getEmfPlusActionsCount(aGraphic));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, getPolygonActionsCount(aGraphic));
|
|
|
|
|
|
|
|
for (bool useConvertMetafile : { false, true })
|
|
|
|
{
|
|
|
|
// Save as WMF.
|
|
|
|
utl::TempFile aTempFile;
|
|
|
|
aTempFile.EnableKillingFile();
|
|
|
|
SvStream& rOutStream = *aTempFile.GetStream(StreamMode::READWRITE);
|
|
|
|
if (useConvertMetafile)
|
|
|
|
ConvertGraphicToWMF(aGraphic, rOutStream, nullptr);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_uInt16 nFormat = rGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
|
2022-04-28 14:12:35 +02:00
|
|
|
rGraphicFilter.ExportGraphic(aGraphic, u"", rOutStream, nFormat);
|
2021-06-11 15:51:32 +02:00
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nExpectedSize, rOutStream.TellEnd());
|
|
|
|
|
|
|
|
rOutStream.Seek(0);
|
|
|
|
Graphic aNewGraphic = rGraphicFilter.ImportUnloadedGraphic(rOutStream);
|
|
|
|
// Check that reading the WMF back preserves the EMF+ actions in it.
|
|
|
|
CPPUNIT_ASSERT_GREATER(0, getEmfPlusActionsCount(aNewGraphic));
|
|
|
|
// EmfReader::ReadEnhWMF() drops non-EMF+ drawing actions if EMF+ is found.
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, getPolygonActionsCount(aNewGraphic));
|
|
|
|
|
|
|
|
// With EMF+ disabled there should be no EMF+ actions.
|
2021-06-14 14:22:16 +02:00
|
|
|
auto aVectorGraphicData = std::make_shared<VectorGraphicData>(
|
|
|
|
aNewGraphic.GetGfxLink().getDataContainer(), VectorGraphicDataType::Wmf);
|
2021-06-11 15:51:32 +02:00
|
|
|
aVectorGraphicData->setEnableEMFPlus(false);
|
|
|
|
Graphic aNoEmfPlusGraphic(aVectorGraphicData);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, getEmfPlusActionsCount(aNoEmfPlusGraphic));
|
|
|
|
CPPUNIT_ASSERT_GREATER(0, getPolygonActionsCount(aNoEmfPlusGraphic));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 17:10:56 +01:00
|
|
|
void GraphicTest::testEmfToWmfConversion()
|
|
|
|
{
|
|
|
|
// Load EMF data.
|
|
|
|
GraphicFilter aGraphicFilter;
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "to-wmf.emf";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
Graphic aGraphic;
|
|
|
|
// This similar to an application/x-openoffice-wmf mime type in manifest.xml in the ODF case.
|
2022-07-30 01:47:54 +03:00
|
|
|
sal_uInt16 nFormatEMF = aGraphicFilter.GetImportFormatNumberForShortName(u"EMF");
|
2020-12-07 17:10:56 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
|
2022-07-30 01:47:54 +03:00
|
|
|
aGraphicFilter.ImportGraphic(aGraphic, u"", aStream, nFormatEMF));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Emf, aGraphic.getVectorGraphicData()->getType());
|
2020-12-07 17:10:56 +01:00
|
|
|
|
|
|
|
// Save as WMF.
|
|
|
|
sal_uInt16 nFilterType = aGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
|
|
|
|
SvMemoryStream aGraphicStream;
|
2022-04-28 14:12:35 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
|
|
|
|
aGraphicFilter.ExportGraphic(aGraphic, u"", aGraphicStream, nFilterType));
|
2020-12-07 17:10:56 +01:00
|
|
|
aGraphicStream.Seek(0);
|
|
|
|
vcl::GraphicFormatDetector aDetector(aGraphicStream, OUString());
|
|
|
|
CPPUNIT_ASSERT(aDetector.detect());
|
2022-08-09 23:24:58 +03:00
|
|
|
CPPUNIT_ASSERT(aDetector.checkWMF());
|
2020-12-07 17:10:56 +01:00
|
|
|
|
|
|
|
// Without the accompanying fix in place, this test would have failed with:
|
|
|
|
// - Expected: WMF
|
|
|
|
// - Actual : EMF
|
|
|
|
// i.e. EMF data was requested to be converted to WMF, but the output was still EMF.
|
2022-07-30 01:47:54 +03:00
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("WMF"),
|
|
|
|
vcl::getImportFormatShortName(aDetector.getMetadata().mnFormat));
|
2020-12-09 09:38:48 +01:00
|
|
|
|
|
|
|
// Import the WMF result and check for traces of EMF+ in it.
|
|
|
|
Graphic aWmfGraphic;
|
|
|
|
aGraphicStream.Seek(0);
|
2022-07-30 01:47:54 +03:00
|
|
|
sal_uInt16 nFormatWMF = aGraphicFilter.GetImportFormatNumberForShortName(u"WMF");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(
|
|
|
|
ERRCODE_NONE, aGraphicFilter.ImportGraphic(aWmfGraphic, u"", aGraphicStream, nFormatWMF));
|
2020-12-09 09:38:48 +01:00
|
|
|
int nCommentCount = 0;
|
|
|
|
for (size_t i = 0; i < aWmfGraphic.GetGDIMetaFile().GetActionSize(); ++i)
|
|
|
|
{
|
|
|
|
MetaAction* pAction = aWmfGraphic.GetGDIMetaFile().GetAction(i);
|
|
|
|
if (pAction->GetType() == MetaActionType::COMMENT)
|
|
|
|
{
|
|
|
|
auto pComment = static_cast<MetaCommentAction*>(pAction);
|
|
|
|
if (pComment->GetComment().startsWith("EMF_PLUS"))
|
|
|
|
{
|
|
|
|
++nCommentCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Without the accompanying fix in place, this test would have failed with:
|
|
|
|
// - Expected less or equal than: 4
|
|
|
|
// - Actual : 8
|
|
|
|
// i.e. even more EMF+ comments were left in the WMF output. The ideal would be to get this down
|
|
|
|
// to 0, though.
|
|
|
|
CPPUNIT_ASSERT_LESSEQUAL(4, nCommentCount);
|
2020-12-07 17:10:56 +01:00
|
|
|
}
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
void GraphicTest::testSwappingGraphic_PNG_WithGfxLink()
|
2020-04-25 12:06:53 +02:00
|
|
|
{
|
|
|
|
// Prepare Graphic from a PNG image first
|
2020-11-13 14:29:59 +02:00
|
|
|
Graphic aGraphic = makeUnloadedGraphic(u"png");
|
2020-04-25 12:06:53 +02:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
|
2020-11-13 09:04:59 +03:00
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
|
2020-05-14 16:02:31 +02:00
|
|
|
|
|
|
|
BitmapChecksum aChecksumBeforeSwapping = aGraphic.GetChecksum();
|
2020-04-25 12:06:53 +02:00
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsGfxLink());
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(319), aGraphic.GetGfxLink().GetDataSize());
|
|
|
|
|
|
|
|
// We loaded the Graphic and made it available
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
2020-12-06 21:14:07 +09:00
|
|
|
// Get the declared byte size of the graphic
|
|
|
|
sal_uLong rByteSize = aGraphic.GetSizeBytes();
|
|
|
|
|
|
|
|
// Check the swap file (shouldn't exist)
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileURL().isEmpty());
|
|
|
|
|
|
|
|
// Swapping out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Byte size doesn't change when we swapped out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
|
|
|
|
// Check the swap file (still shouldn't exist)
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileURL().isEmpty());
|
|
|
|
|
|
|
|
// Let's swap in
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(aChecksumBeforeSwapping, aGraphic.GetChecksum());
|
|
|
|
|
|
|
|
// Check the bitmap
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingGraphic_PNG_WithoutGfxLink()
|
|
|
|
{
|
|
|
|
// Prepare Graphic from a PNG image first
|
|
|
|
|
|
|
|
// Make sure to construct the Graphic from BitmapEx, so that we
|
|
|
|
// don't have the GfxLink present.
|
|
|
|
Graphic aGraphic(makeUnloadedGraphic(u"png").GetBitmapEx());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
BitmapChecksum aChecksumBeforeSwapping = aGraphic.GetChecksum();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
|
|
|
|
|
|
|
|
// We loaded the Graphic and made it available
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
2020-04-25 12:06:53 +02:00
|
|
|
// Get the declared byte size of the graphic
|
|
|
|
sal_uLong rByteSize = aGraphic.GetSizeBytes();
|
|
|
|
OUString rSwapFileURL = aGraphic.ImplGetImpGraphic()->getSwapFileURL();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, rSwapFileURL.isEmpty());
|
|
|
|
|
|
|
|
// Swapping out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Byte size doesn't change when we swapped out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
|
|
|
|
// Let's check the swap file
|
|
|
|
rSwapFileURL = aGraphic.ImplGetImpGraphic()->getSwapFileURL();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, comphelper::DirectoryHelper::fileExists(rSwapFileURL));
|
|
|
|
|
|
|
|
{ // Check the swap file content
|
|
|
|
std::unique_ptr<SvStream> xStream = createStream(rSwapFileURL);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(xStream));
|
|
|
|
|
|
|
|
// Check size of the stream
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(36079), xStream->remainingSize());
|
2020-04-25 12:06:53 +02:00
|
|
|
|
|
|
|
std::vector<unsigned char> aHash = calculateHash(xStream);
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("9347511e3b80dfdfaadf91a3bdef55a8ae85552b"),
|
2020-04-25 12:06:53 +02:00
|
|
|
toHexString(aHash));
|
|
|
|
}
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
// SWAP IN
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
// reset the checksum to make sure we don't get the cached value
|
|
|
|
aGraphic.ImplGetImpGraphic()->resetChecksum();
|
2020-05-14 16:02:31 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(aChecksumBeforeSwapping, aGraphic.GetChecksum());
|
2020-04-25 12:06:53 +02:00
|
|
|
|
|
|
|
// File shouldn't be available anymore
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, comphelper::DirectoryHelper::fileExists(rSwapFileURL));
|
|
|
|
|
|
|
|
// Check the bitmap
|
2020-11-13 09:04:59 +03:00
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
|
|
|
|
}
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
void GraphicTest::testSwappingGraphicProperties_PNG_WithGfxLink()
|
|
|
|
{
|
|
|
|
// Prepare Graphic from a PNG image
|
|
|
|
Graphic aGraphic = makeUnloadedGraphic(u"png");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Origin URL
|
|
|
|
aGraphic.setOriginURL("Origin URL");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
|
|
|
|
//Set PrefMapMode
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::Map100thMM, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
aGraphic.SetPrefMapMode(MapMode(MapUnit::MapTwip));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
|
|
|
|
// Set the PrefSize
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(6000), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(5000), aGraphic.GetPrefSize().Height());
|
|
|
|
aGraphic.SetPrefSize(Size(200, 100));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
|
|
|
|
// SWAP OUT
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Check properties
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Check properties
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingGraphicProperties_PNG_WithoutGfxLink()
|
|
|
|
{
|
|
|
|
// Prepare Graphic from a PNG image
|
|
|
|
Graphic aGraphic(makeUnloadedGraphic(u"png").GetBitmapEx());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Origin URL
|
|
|
|
aGraphic.setOriginURL("Origin URL");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
|
|
|
|
//Set PrefMapMode
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::Map100thMM, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
aGraphic.SetPrefMapMode(MapMode(MapUnit::MapTwip));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
|
|
|
|
// Set the PrefSize
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(6000), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(5000), aGraphic.GetPrefSize().Height());
|
|
|
|
aGraphic.SetPrefSize(Size(200, 100));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
|
|
|
|
// SWAP OUT
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Check properties
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Check properties
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingVectorGraphic_SVG_WithGfxLink()
|
2020-04-25 12:06:53 +02:00
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
2020-12-06 21:14:07 +09:00
|
|
|
// Loaded into "prepared" state
|
2020-04-25 12:06:53 +02:00
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
// Check that the state is as expected
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Load the vector graphic
|
2020-12-06 21:14:07 +09:00
|
|
|
auto pVectorData = aGraphic.getVectorGraphicData();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(pVectorData));
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
2020-12-29 10:42:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(223), pVectorData->getBinaryDataContainer().getSize());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsGfxLink());
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(223), aGraphic.GetGfxLink().GetDataSize());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
// Remember checksum so we can compare after swapping back in again
|
|
|
|
BitmapChecksum aBitmapChecksumBeforeSwapping = aGraphic.GetBitmapEx().GetChecksum();
|
|
|
|
|
|
|
|
// Check we are not swapped out yet
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Get the declared byte size of the graphic
|
|
|
|
sal_uLong rByteSize = aGraphic.GetSizeBytes();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uLong(223), rByteSize);
|
|
|
|
|
|
|
|
// Make sure we don't have a file
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileURL().isEmpty());
|
|
|
|
|
|
|
|
// SWAP OUT the Graphic and make sure it's not available currently
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// We use GfxLink so no swap file in this case
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileURL().isEmpty());
|
|
|
|
|
|
|
|
// Byte size doesn't change when we swapped out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Compare that the checksum of the bitmap is still the same
|
|
|
|
CPPUNIT_ASSERT_EQUAL(aBitmapChecksumBeforeSwapping, aGraphic.GetBitmapEx().GetChecksum());
|
|
|
|
|
|
|
|
// Byte size shouldn't change
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingVectorGraphic_SVG_WithoutGfxLink()
|
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
|
|
|
|
Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
2020-12-29 10:42:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(223),
|
|
|
|
aInputGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
// Create graphic
|
|
|
|
Graphic aGraphic(aInputGraphic.getVectorGraphicData());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
|
2020-12-29 10:42:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(223),
|
|
|
|
aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
|
|
|
|
|
2020-04-25 12:06:53 +02:00
|
|
|
BitmapChecksum aBitmapChecksumBeforeSwapping = aGraphic.GetBitmapEx().GetChecksum();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Get the declared byte size of the graphic
|
|
|
|
sal_uLong rByteSize = aGraphic.GetSizeBytes();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uLong(223), rByteSize);
|
2020-12-06 21:14:07 +09:00
|
|
|
|
2020-04-25 12:06:53 +02:00
|
|
|
OUString rSwapFileURL = aGraphic.ImplGetImpGraphic()->getSwapFileURL();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, rSwapFileURL.isEmpty());
|
|
|
|
|
|
|
|
// Swapping out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Byte size doesn't change when we swapped out
|
|
|
|
// TODO: In case we don't trigger GetBitmapEx (above) the size is 0
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
|
|
|
|
// Let's check the swap file
|
|
|
|
rSwapFileURL = aGraphic.ImplGetImpGraphic()->getSwapFileURL();
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, rSwapFileURL.isEmpty());
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, comphelper::DirectoryHelper::fileExists(rSwapFileURL));
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
{
|
|
|
|
// Check the swap file content
|
2020-04-25 12:06:53 +02:00
|
|
|
std::unique_ptr<SvStream> xStream = createStream(rSwapFileURL);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(xStream));
|
|
|
|
|
|
|
|
// Check size of the stream
|
2020-12-26 12:41:08 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(247), xStream->remainingSize());
|
2020-04-25 12:06:53 +02:00
|
|
|
|
|
|
|
std::vector<unsigned char> aHash = calculateHash(xStream);
|
2020-12-26 12:41:08 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("666820973fd95e6cd9e7bc5f1c53732acbc99326"),
|
2020-04-25 12:06:53 +02:00
|
|
|
toHexString(aHash));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's swap in
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
// Check the Graphic
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
|
|
|
|
|
2020-12-29 10:42:17 +09:00
|
|
|
size_t nVectorByteSize = aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(223), nVectorByteSize);
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
|
|
|
|
|
2020-04-25 12:06:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(aBitmapChecksumBeforeSwapping, aGraphic.GetBitmapEx().GetChecksum());
|
|
|
|
|
|
|
|
// File shouldn't be available anymore
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, comphelper::DirectoryHelper::fileExists(rSwapFileURL));
|
|
|
|
}
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
void GraphicTest::testSwappingGraphicProperties_SVG_WithGfxLink()
|
|
|
|
{
|
2020-12-20 19:54:57 +02:00
|
|
|
// FIXME: the DPI check should be removed when either (1) the test is fixed to work with
|
|
|
|
// non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
|
|
|
|
if (!IsDefaultDPI())
|
|
|
|
return;
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
// We check that Graphic properties like MapMode, PrefSize are properly
|
|
|
|
// restored through a swap cycle
|
|
|
|
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
|
|
|
// Loaded into "prepared" state
|
|
|
|
|
|
|
|
// Load the vector graphic
|
|
|
|
auto pVectorData = aGraphic.getVectorGraphicData();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(pVectorData));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Origin URL
|
|
|
|
aGraphic.setOriginURL("Origin URL");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
|
|
|
|
// Check size in pixels
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
// Set and check the PrefSize
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Height());
|
|
|
|
aGraphic.SetPrefSize(Size(200, 100));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
|
|
|
|
// SWAP OUT the Graphic and make sure it's not available currently
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Check properties
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Check properties
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingGraphicProperties_SVG_WithoutGfxLink()
|
|
|
|
{
|
2020-12-20 19:54:57 +02:00
|
|
|
// FIXME: the DPI check should be removed when either (1) the test is fixed to work with
|
|
|
|
// non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
|
|
|
|
if (!IsDefaultDPI())
|
|
|
|
return;
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
|
|
|
|
Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
2020-12-29 10:42:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(223),
|
|
|
|
aInputGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
// Create graphic
|
|
|
|
Graphic aGraphic(aInputGraphic.getVectorGraphicData());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Origin URL
|
|
|
|
aGraphic.setOriginURL("Origin URL");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
|
|
|
|
// Check size in pixels
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
// Set and check the PrefSize
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Height());
|
|
|
|
aGraphic.SetPrefSize(Size(200, 100));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
|
|
|
|
// SWAP OUT the Graphic and make sure it's not available currently
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(OUString("Origin URL"), aGraphic.getOriginURL());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingVectorGraphic_PDF_WithGfxLink()
|
2020-08-17 07:44:57 +02:00
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(PDFEXPORT_DATA_DIRECTORY) + "SimpleMultiPagePDF.pdf";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Load the vector graphic
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
|
2020-12-06 21:14:07 +09:00
|
|
|
|
2020-08-17 07:44:57 +02:00
|
|
|
// Set the page index
|
|
|
|
aGraphic.getVectorGraphicData()->setPageIndex(1);
|
|
|
|
|
2020-12-29 10:42:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, aGraphic.getVectorGraphicData()->getType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(17693),
|
|
|
|
aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
|
2020-08-17 07:44:57 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
// SWAP OUT
|
2020-08-17 07:44:57 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
// SWAP IN
|
2020-08-17 07:44:57 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
|
|
|
|
}
|
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
void GraphicTest::testSwappingVectorGraphic_PDF_WithoutGfxLink()
|
2020-11-25 18:01:08 +01:00
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
2020-12-06 21:14:07 +09:00
|
|
|
OUString aURL = aDirectories.getURLFromSrc(PDFEXPORT_DATA_DIRECTORY) + "SimpleMultiPagePDF.pdf";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
|
|
|
|
|
|
|
// Create graphic
|
|
|
|
Graphic aGraphic(aInputGraphic.getVectorGraphicData());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
|
|
|
|
|
|
|
|
// Set the page index
|
|
|
|
aGraphic.getVectorGraphicData()->setPageIndex(1);
|
|
|
|
|
2020-12-29 10:42:17 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, aGraphic.getVectorGraphicData()->getType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(17693),
|
|
|
|
aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// SWAP OUT
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingAnimationGraphic_GIF_WithGfxLink()
|
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "123_Numbers.gif";
|
2020-11-25 18:01:08 +01:00
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
2020-12-06 21:14:07 +09:00
|
|
|
// Loaded into "prepared" state
|
2020-11-25 18:01:08 +01:00
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
// Check that the state is as expected
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
2020-11-25 18:01:08 +01:00
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
2020-11-25 18:01:08 +01:00
|
|
|
|
2020-12-06 21:14:07 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsGfxLink());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(124), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(146), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(1515), aGraphic.GetGfxLink().GetDataSize());
|
|
|
|
|
|
|
|
// Remember checksum so we can compare after swapping back in again
|
|
|
|
BitmapChecksum aBitmapChecksumBeforeSwapping = aGraphic.GetBitmapEx().GetChecksum();
|
|
|
|
|
|
|
|
// Check we are not swapped out yet
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Get the declared byte size of the graphic
|
|
|
|
sal_uLong rByteSize = aGraphic.GetSizeBytes();
|
2021-04-19 16:07:23 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uLong(89552), rByteSize);
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
// Make sure we don't have a file
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileURL().isEmpty());
|
|
|
|
|
|
|
|
// SWAP OUT the Graphic and make sure it's not available currently
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// We use GfxLink so no swap file in this case
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileURL().isEmpty());
|
|
|
|
|
|
|
|
// Byte size doesn't change when we swapped out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Compare that the checksum of the bitmap is still the same
|
|
|
|
CPPUNIT_ASSERT_EQUAL(aBitmapChecksumBeforeSwapping, aGraphic.GetBitmapEx().GetChecksum());
|
|
|
|
|
|
|
|
// Byte size shouldn't change
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testSwappingAnimationGraphic_GIF_WithoutGfxLink()
|
|
|
|
{
|
|
|
|
test::Directories aDirectories;
|
|
|
|
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "123_Numbers.gif";
|
|
|
|
SvFileStream aStream(aURL, StreamMode::READ);
|
|
|
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
|
|
|
|
Graphic aGraphic(aInputGraphic.GetAnimation());
|
|
|
|
|
|
|
|
// Check animation graphic
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsAnimated());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(124), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(146), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
|
|
|
|
|
|
|
|
// We loaded the Graphic and made it available
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// Get the declared byte size of the graphic
|
|
|
|
sal_uLong rByteSize = aGraphic.GetSizeBytes();
|
|
|
|
OUString rSwapFileURL = aGraphic.ImplGetImpGraphic()->getSwapFileURL();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, rSwapFileURL.isEmpty());
|
|
|
|
|
|
|
|
// SWAP OUT
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
|
|
|
|
// Byte size doesn't change when we swapped out
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
|
|
|
|
|
|
|
// Let's check the swap file
|
|
|
|
rSwapFileURL = aGraphic.ImplGetImpGraphic()->getSwapFileURL();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, comphelper::DirectoryHelper::fileExists(rSwapFileURL));
|
|
|
|
|
|
|
|
{
|
|
|
|
// Check the swap file content
|
|
|
|
std::unique_ptr<SvStream> xStream = createStream(rSwapFileURL);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, bool(xStream));
|
|
|
|
|
|
|
|
// Check size of the stream
|
2021-04-19 16:07:23 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(15139), xStream->remainingSize());
|
2020-12-06 21:14:07 +09:00
|
|
|
|
|
|
|
std::vector<unsigned char> aHash = calculateHash(xStream);
|
2021-04-19 16:07:23 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ecae5354edd9cf98553eb3153e44181f56d35338"),
|
2020-12-06 21:14:07 +09:00
|
|
|
toHexString(aHash));
|
|
|
|
}
|
|
|
|
|
|
|
|
// SWAP IN
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
|
|
|
|
|
|
|
|
// File shouldn't be available anymore
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false, comphelper::DirectoryHelper::fileExists(rSwapFileURL));
|
|
|
|
|
|
|
|
// Check the bitmap
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(124), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(146), aGraphic.GetSizePixel().Height());
|
|
|
|
|
|
|
|
// Byte size is still the same
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
|
2020-11-25 18:01:08 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 14:30:01 +09:00
|
|
|
void GraphicTest::testLoadMET()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.met");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::GdiMetafile, aGraphic.GetType());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testLoadBMP()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.bmp");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testLoadPSD()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.psd");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testLoadTGA()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.tga");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testLoadXBM()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.xbm");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testLoadXPM()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.xpm");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testLoadPCX()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.pcx");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicTest::testLoadEPS()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.eps");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::GdiMetafile, aGraphic.GetType());
|
|
|
|
}
|
|
|
|
|
2022-01-13 15:59:49 +01:00
|
|
|
void GraphicTest::testLoadWEBP()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.webp");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
|
|
|
|
}
|
|
|
|
|
2022-09-08 13:37:35 +02:00
|
|
|
void GraphicTest::testLoadSVGZ()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = loadGraphic(u"TypeDetectionExample.svgz");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
|
2022-09-22 11:38:35 +02:00
|
|
|
const auto[scalingX, scalingY] = getDPIScaling();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingX), aGraphic.GetSizePixel().Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingY), aGraphic.GetSizePixel().Height());
|
2022-09-08 13:37:35 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 17:39:48 +02:00
|
|
|
void GraphicTest::testAvailableThreaded()
|
|
|
|
{
|
|
|
|
Graphic jpgGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.jpg");
|
|
|
|
Graphic jpgGraphic2 = importUnloadedGraphic(u"Exif1.jpg");
|
|
|
|
Graphic pngGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.png");
|
|
|
|
Graphic pngGraphic2 = importUnloadedGraphic(u"testBasicMorphology.png");
|
|
|
|
std::vector<Graphic*> graphics = { &jpgGraphic1, &jpgGraphic2, &pngGraphic1, &pngGraphic2 };
|
2021-04-19 12:09:02 +02:00
|
|
|
std::vector<Size> sizes;
|
2021-04-15 17:39:48 +02:00
|
|
|
for (auto& graphic : graphics)
|
2021-04-19 12:09:02 +02:00
|
|
|
{
|
2021-04-15 17:39:48 +02:00
|
|
|
CPPUNIT_ASSERT(!graphic->isAvailable());
|
2021-04-19 12:09:02 +02:00
|
|
|
sizes.push_back(graphic->GetSizePixel());
|
|
|
|
}
|
2021-04-15 17:39:48 +02:00
|
|
|
GraphicFilter& graphicFilter = GraphicFilter::GetGraphicFilter();
|
|
|
|
graphicFilter.MakeGraphicsAvailableThreaded(graphics);
|
2021-04-19 12:09:02 +02:00
|
|
|
int i = 0;
|
2021-04-15 17:39:48 +02:00
|
|
|
for (auto& graphic : graphics)
|
2021-04-19 12:09:02 +02:00
|
|
|
{
|
2021-04-15 17:39:48 +02:00
|
|
|
CPPUNIT_ASSERT(graphic->isAvailable());
|
2021-04-19 12:09:02 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sizes[i], graphic->GetSizePixel());
|
|
|
|
++i;
|
|
|
|
}
|
2021-04-15 17:39:48 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 14:59:51 +03:00
|
|
|
void GraphicTest::testColorChangeToTransparent()
|
|
|
|
{
|
|
|
|
Graphic aGraphic = importUnloadedGraphic(u"testColorChange-red-linear-gradient.png");
|
|
|
|
|
|
|
|
auto xGraphic = aGraphic.GetXGraphic();
|
|
|
|
uno::Reference<graphic::XGraphicTransformer> xGraphicTransformer{ xGraphic, uno::UNO_QUERY };
|
|
|
|
::Color nColorFrom{ ColorTransparency, 0x00, 0xFF, 0x00, 0x00 };
|
|
|
|
::Color nColorTo{ ColorTransparency, 0xFF, 0xFF, 0x00, 0x00 };
|
|
|
|
sal_uInt8 nTolerance{ 15 };
|
|
|
|
|
|
|
|
auto xGraphicAfter = xGraphicTransformer->colorChange(
|
|
|
|
xGraphic, static_cast<sal_Int32>(nColorFrom), nTolerance, static_cast<sal_Int32>(nColorTo),
|
|
|
|
static_cast<sal_Int8>(nColorTo.GetAlpha()));
|
|
|
|
|
|
|
|
Graphic aGraphicAfter{ xGraphicAfter };
|
|
|
|
const BitmapEx& rBitmapAfter = aGraphicAfter.GetBitmapExRef();
|
|
|
|
const BitmapEx& rBitmapBefore = aGraphic.GetBitmapExRef();
|
|
|
|
// Without the accompanying fix in place, this test would have failed with:
|
|
|
|
// - Expected: rgba[ff000000]
|
|
|
|
// - Actual : rgba[f00000ff]
|
|
|
|
// i.e. the color change to transparent didn't apply correctly
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nColorTo, rBitmapAfter.GetPixelColor(386, 140));
|
|
|
|
|
|
|
|
// Test if color stayed same on 410,140
|
|
|
|
// colorChange with nTolerance 15 shouldn't change this pixel.
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rBitmapBefore.GetPixelColor(410, 140),
|
|
|
|
rBitmapAfter.GetPixelColor(410, 140));
|
|
|
|
}
|
|
|
|
|
2018-04-28 13:37:17 +09:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|