summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-05-17 15:15:01 +0900
committerTomaž Vajngerl <quikee@gmail.com>2018-05-18 05:26:28 +0200
commit8eb15f031003f6431d41853ff70e307b617d1a5a (patch)
tree0a59185c8007cc97c2209e2bc2a75072ddb2e0b5 /vcl/qa
parent008686d760ca735210e856c68b852425c8059bb7 (diff)
Extend test for unloaded graphic
To make sure they are loaded correctly for most common graphic formats. Change-Id: Id121df0ddc763a299c5714cadd0d61740876e3dd Reviewed-on: https://gerrit.libreoffice.org/54467 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/GraphicTest.cxx65
1 files changed, 58 insertions, 7 deletions
diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index d039ba1dec25..428ebda0560d 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -12,19 +12,26 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <vcl/bitmapaccess.hxx>
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>
#include <tools/stream.hxx>
#include <vcl/pngwrite.hxx>
+using namespace css;
+
namespace
{
class GraphicTest : public CppUnit::TestFixture
{
void testUnloadedGraphic();
+ void testUnloadedGraphicLoading();
CPPUNIT_TEST_SUITE(GraphicTest);
CPPUNIT_TEST(testUnloadedGraphic);
+ CPPUNIT_TEST(testUnloadedGraphicLoading);
CPPUNIT_TEST_SUITE_END();
};
@@ -36,28 +43,30 @@ BitmapEx createBitmap()
return BitmapEx(aBitmap);
}
-void createBitmapAndExportToPNG(SvStream& rStream)
+void createBitmapAndExportForType(SvStream& rStream, OUString const& sType)
{
BitmapEx aBitmapEx = createBitmap();
- vcl::PNGWriter aWriter(aBitmapEx);
- aWriter.Write(rStream);
+ uno::Sequence<beans::PropertyValue> aFilterData;
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName(sType);
+ rGraphicFilter.ExportGraphic(aBitmapEx, "none", rStream, nFilterFormat, &aFilterData);
rStream.Seek(STREAM_SEEK_TO_BEGIN);
}
-Graphic makeUnloadedGraphic()
+Graphic makeUnloadedGraphic(OUString const& sType)
{
SvMemoryStream aStream;
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
- createBitmapAndExportToPNG(aStream);
+ createBitmapAndExportForType(aStream, sType);
return rGraphicFilter.ImportUnloadedGraphic(aStream);
}
void GraphicTest::testUnloadedGraphic()
{
// make unloaded test graphic
- Graphic aGraphic = makeUnloadedGraphic();
+ Graphic aGraphic = makeUnloadedGraphic("png");
Graphic aGraphic2 = aGraphic;
// check available
@@ -69,7 +78,7 @@ void GraphicTest::testUnloadedGraphic()
CPPUNIT_ASSERT_EQUAL(true, aGraphic2.isAvailable());
// check GetSizePixel doesn't load graphic
- aGraphic = makeUnloadedGraphic();
+ aGraphic = makeUnloadedGraphic("png");
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Height());
@@ -81,6 +90,48 @@ void GraphicTest::testUnloadedGraphic()
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
}
+void GraphicTest::testUnloadedGraphicLoading()
+{
+ const OUString aFormats[] = { "png", "gif", "jpg" };
+
+ for (OUString const& sFormat : aFormats)
+ {
+ Graphic aGraphic = makeUnloadedGraphic(sFormat);
+
+ // check available
+ CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+ CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Height());
+ CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+ CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
+ CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
+ Bitmap aBitmap(aGraphic.GetBitmapEx().GetBitmap());
+
+ {
+ Bitmap::ScopedReadAccess pReadAccess(aBitmap);
+ for (long y = 0; y < aGraphic.GetSizePixel().Height(); y++)
+ {
+ for (long x = 0; x < aGraphic.GetSizePixel().Width(); x++)
+ {
+ if (pReadAccess->HasPalette())
+ {
+ Color aColor
+ = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(y, x))
+ .GetColor();
+ CPPUNIT_ASSERT_EQUAL(OUString("ff0000"), aColor.AsRGBHexString());
+ }
+ else
+ {
+ Color aColor = pReadAccess->GetPixel(y, x).GetColor();
+ if (sFormat != "jpg")
+ CPPUNIT_ASSERT_EQUAL(OUString("ff0000"), aColor.AsRGBHexString());
+ }
+ }
+ }
+ }
+ }
+}
+
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);