From 981f0f2a661b4615ef9cc4fb24fd05087fb22c10 Mon Sep 17 00:00:00 2001 From: Paris Oplopoios Date: Tue, 1 Aug 2023 15:20:08 +0300 Subject: [PATCH] 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 Reviewed-by: Miklos Vajna (cherry picked from commit 8b96443e6c726a707069412b77e87be5da852150) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155240 Tested-by: Jenkins Reviewed-by: Paris Oplopoios --- desktop/CppunitTest_desktop_lib.mk | 1 + desktop/qa/desktop_lib/test_desktop_lib.cxx | 81 +++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk index d8f58cac18da..878235d4da6f 100644 --- a/desktop/CppunitTest_desktop_lib.mk +++ b/desktop/CppunitTest_desktop_lib.mk @@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \ sfx \ sofficeapp \ subsequenttest \ + svt \ sw \ test \ unotest \ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 8b21f905f71d..35cbbfe60c15 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -66,6 +66,8 @@ #include #include #include +#include +#include #if USE_TLS_NSS #include @@ -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 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 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() {