Test paintPartTile behavior for views with different schemes

It would be the case that sometimes paintPartTile would use a different
view to draw the tiles without first checking if they have matching
schemes, which would cause bad tiles and previews

Change-Id: I3a268552132718a25eccbc4284c82dc31c6ca2fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155154
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 8b96443e6c726a707069412b77e87be5da852150)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155240
Tested-by: Jenkins
Reviewed-by: Paris Oplopoios <parisoplop@gmail.com>
This commit is contained in:
Paris Oplopoios 2023-08-01 15:20:08 +03:00 committed by Paris Oplopoios
parent 3bf0f056eb
commit 981f0f2a66
2 changed files with 82 additions and 0 deletions

View file

@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \
sfx \
sofficeapp \
subsequenttest \
svt \
sw \
test \
unotest \

View file

@ -66,6 +66,8 @@
#include <vcl/BitmapTools.hxx>
#include <vcl/filter/PngImageWriter.hxx>
#include <vcl/filter/PDFiumLibrary.hxx>
#include <svtools/colorcfg.hxx>
#include <sal/types.h>
#if USE_TLS_NSS
#include <nss.h>
@ -186,6 +188,7 @@ public:
void testTrackChanges();
void testRedlineCalc();
void testPaintPartTile();
void testPaintPartTileDifferentSchemes();
#if HAVE_MORE_FONTS
void testGetFontSubset();
#endif
@ -257,6 +260,7 @@ public:
CPPUNIT_TEST(testTrackChanges);
CPPUNIT_TEST(testRedlineCalc);
CPPUNIT_TEST(testPaintPartTile);
CPPUNIT_TEST(testPaintPartTileDifferentSchemes);
#if HAVE_MORE_FONTS
CPPUNIT_TEST(testGetFontSubset);
#endif
@ -2304,6 +2308,83 @@ void DesktopLOKTest::testPaintPartTile()
//CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
}
void DesktopLOKTest::testPaintPartTileDifferentSchemes()
{
Color aDarkColor(0x1c, 0x1c, 0x1c);
// Add a minimal dark scheme
{
svtools::EditableColorConfig aColorConfig;
svtools::ColorConfigValue aValue;
aValue.bIsVisible = true;
aValue.nColor = aDarkColor;
aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue);
aColorConfig.AddScheme(u"Dark");
}
// Add a minimal light scheme
{
svtools::EditableColorConfig aColorConfig;
svtools::ColorConfigValue aValue;
aValue.bIsVisible = true;
aValue.nColor = COL_WHITE;
aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue);
aColorConfig.AddScheme(u"Light");
}
// This view will default to light scheme
LibLODocument_Impl* pDocument = loadDoc("2slides.odp");
pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
int nView1 = pDocument->m_pDocumentClass->getView(pDocument);
// Create a second view
pDocument->m_pDocumentClass->createView(pDocument);
pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
// Go to the second slide in the second view
pDocument->m_pDocumentClass->setPart(pDocument, 1);
// Set to dark scheme
{
uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence(
{
{ "NewTheme", uno::Any(OUString("Dark")) },
}
);
dispatchCommand(mxComponent, ".uno:ChangeTheme", aPropertyValues);
}
constexpr int nCanvasWidth = 256;
constexpr int nCanvasHeight = 256;
// Just a random pixel in the middle of the canvas
constexpr int nPixelX = 128;
constexpr int nPixelY = 128 * nCanvasWidth;
std::array<sal_uInt8, nCanvasWidth * nCanvasHeight * 4> aPixels;
// Both parts should be painted with dark scheme
pDocument->m_pDocumentClass->paintPartTile(pDocument, aPixels.data(), 0, 0, nCanvasWidth, nCanvasHeight, 0, 0, nCanvasWidth, nCanvasHeight);
Color aPixel(aPixels[nPixelX + nPixelY + 0], aPixels[nPixelX + nPixelY + 1], aPixels[nPixelX + nPixelY + 2]);
CPPUNIT_ASSERT_EQUAL(aDarkColor, aPixel);
pDocument->m_pDocumentClass->paintPartTile(pDocument, aPixels.data(), 0, 0, nCanvasWidth, nCanvasHeight, 0, 0, nCanvasWidth, nCanvasHeight);
aPixel = Color(aPixels[nPixelX + nPixelY + 0], aPixels[nPixelX + nPixelY + 1], aPixels[nPixelX + nPixelY + 2]);
CPPUNIT_ASSERT_EQUAL(aDarkColor, aPixel);
// Switch back to first view
pDocument->m_pDocumentClass->setView(pDocument, nView1);
// Both parts should be painted with light scheme
pDocument->m_pDocumentClass->paintPartTile(pDocument, aPixels.data(), 0, 0, nCanvasWidth, nCanvasHeight, 0, 0, nCanvasWidth, nCanvasHeight);
aPixel = Color(aPixels[nPixelX + nPixelY + 0], aPixels[nPixelX + nPixelY + 1], aPixels[nPixelX + nPixelY + 2]);
CPPUNIT_ASSERT_EQUAL(COL_WHITE, aPixel);
pDocument->m_pDocumentClass->paintPartTile(pDocument, aPixels.data(), 0, 0, nCanvasWidth, nCanvasHeight, 0, 0, nCanvasWidth, nCanvasHeight);
aPixel = Color(aPixels[nPixelX + nPixelY + 0], aPixels[nPixelX + nPixelY + 1], aPixels[nPixelX + nPixelY + 2]);
CPPUNIT_ASSERT_EQUAL(COL_WHITE, aPixel);
}
#if HAVE_MORE_FONTS
void DesktopLOKTest::testGetFontSubset()
{