summaryrefslogtreecommitdiff
path: root/sd/qa/unit/uiimpress.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sd/qa/unit/uiimpress.cxx')
-rw-r--r--sd/qa/unit/uiimpress.cxx288
1 files changed, 266 insertions, 22 deletions
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index 286672341a3b..9bebb4e46e4e 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -16,9 +16,12 @@
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/XDrawView.hpp>
+#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/XMasterPageTarget.hpp>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/table/XMergeableCell.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
@@ -42,6 +45,9 @@
#include <svl/stritem.hxx>
#include <undo/undomanager.hxx>
#include <vcl/scheduler.hxx>
+#include <docmodel/uno/UnoThemeColor.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <comphelper/sequenceashashmap.hxx>
#include <DrawDocShell.hxx>
#include <ViewShell.hxx>
@@ -65,6 +71,8 @@ public:
virtual void tearDown() override;
void checkCurrentPageNumber(sal_uInt16 nNum);
+ void typeString(SdXImpressDocument* rImpressDocument, const std::string& rStr);
+ void typeKey(SdXImpressDocument* rImpressDocument, const sal_uInt16 nKey);
void insertStringToObject(sal_uInt16 nObj, const std::string& rStr, bool bUseEscape);
sd::slidesorter::SlideSorterViewShell* getSlideSorterViewShell();
};
@@ -96,6 +104,23 @@ void SdUiImpressTest::checkCurrentPageNumber(sal_uInt16 nNum)
CPPUNIT_ASSERT_EQUAL(nNum, nPageNumber);
}
+void SdUiImpressTest::typeKey(SdXImpressDocument* rImpressDocument, const sal_uInt16 nKey)
+{
+ rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, nKey);
+ rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, nKey);
+ Scheduler::ProcessEventsToIdle();
+}
+
+void SdUiImpressTest::typeString(SdXImpressDocument* rImpressDocument, const std::string& rStr)
+{
+ for (const char c : rStr)
+ {
+ rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0);
+ rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0);
+ Scheduler::ProcessEventsToIdle();
+ }
+}
+
void SdUiImpressTest::insertStringToObject(sal_uInt16 nObj, const std::string& rStr,
bool bUseEscape)
{
@@ -106,24 +131,17 @@ void SdUiImpressTest::insertStringToObject(sal_uInt16 nObj, const std::string& r
CPPUNIT_ASSERT_MESSAGE("No Shape", pShape);
SdrView* pView = pViewShell->GetView();
pView->MarkObj(pShape, pView->GetSdrPageView());
+ Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(!pView->IsTextEdit());
- for (const char c : rStr)
- {
- pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0);
- pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0);
- Scheduler::ProcessEventsToIdle();
- }
+ typeString(pImpressDocument, rStr);
CPPUNIT_ASSERT(pView->IsTextEdit());
if (bUseEscape)
{
- pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::ESCAPE);
- pImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::ESCAPE);
- Scheduler::ProcessEventsToIdle();
-
+ typeKey(pImpressDocument, KEY_ESCAPE);
CPPUNIT_ASSERT(!pView->IsTextEdit());
}
}
@@ -527,6 +545,86 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testmoveSlides)
CPPUNIT_ASSERT_EQUAL(OUString("Test 2"), pViewShell->GetActualPage()->GetName());
}
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf148620)
+{
+ mxComponent = loadFromDesktop("private:factory/simpress",
+ "com.sun.star.presentation.PresentationDocument");
+
+ auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
+
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString(u""), xShape->getString());
+
+ insertStringToObject(1, "one", /*bUseEscape*/ false);
+ typeKey(pXImpressDocument, KEY_RETURN);
+ typeString(pXImpressDocument, "two");
+ typeKey(pXImpressDocument, KEY_RETURN);
+ typeString(pXImpressDocument, "three");
+ typeKey(pXImpressDocument, KEY_RETURN);
+ typeString(pXImpressDocument, "four");
+ typeKey(pXImpressDocument, KEY_RETURN);
+ typeString(pXImpressDocument, "five");
+ typeKey(pXImpressDocument, KEY_RETURN);
+ typeString(pXImpressDocument, "six");
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nFive\nsix"), xShape->getString());
+
+ uno::Sequence<beans::PropertyValue> aArgs(
+ comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(sal_Int32(0)) } }));
+ dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nsix\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nsix\nFour\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nsix\nThree\nFour\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nsix\nTwo\nThree\nFour\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"six\nOne\nTwo\nThree\nFour\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nsix\nTwo\nThree\nFour\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nsix\nThree\nFour\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nsix\nFour\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nsix\nFive"), xShape->getString());
+
+ dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nFive\nsix"), xShape->getString());
+}
+
CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf141703)
{
mxComponent = loadFromDesktop("private:factory/simpress",
@@ -548,22 +646,14 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf141703)
Scheduler::ProcessEventsToIdle();
}
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'A', 0);
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'A', 0);
- Scheduler::ProcessEventsToIdle();
+ typeString(pXImpressDocument, "A");
// Move to A2 with Tab and write 'B'
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_TAB);
- Scheduler::ProcessEventsToIdle();
+ typeKey(pXImpressDocument, KEY_TAB);
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'B', 0);
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'B', 0);
- Scheduler::ProcessEventsToIdle();
+ typeString(pXImpressDocument, "B");
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::ESCAPE);
- pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::ESCAPE);
- Scheduler::ProcessEventsToIdle();
+ typeKey(pXImpressDocument, KEY_ESCAPE);
sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
SdPage* pActualPage = pViewShell->GetActualPage();
@@ -849,6 +939,160 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf142589)
CPPUNIT_ASSERT_EQUAL(false, pImpressDocument->GetDoc()->getPresentationSettings().mbCustomShow);
}
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testCharColorTheme)
+{
+ // Given an Impress document with a shape, with its text selected:
+ mxComponent = loadFromDesktop("private:factory/simpress",
+ "com.sun.star.presentation.PresentationDocument");
+ uno::Reference<drawing::XDrawPagesSupplier> xPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xPage(xPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
+ {
+ uno::Reference<text::XSimpleText> xText = xShape->getText();
+ xText->insertString(xText->getStart(), "test", false);
+ }
+ uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+ uno::Reference<view::XSelectionSupplier> xController(xModel->getCurrentController(),
+ uno::UNO_QUERY);
+ xController->select(uno::makeAny(xShape));
+ Scheduler::ProcessEventsToIdle();
+ dispatchCommand(mxComponent, ".uno:Text", {});
+ Scheduler::ProcessEventsToIdle();
+ auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
+ sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
+ SdrView* pView = pViewShell->GetView();
+ CPPUNIT_ASSERT(pView->IsTextEdit());
+ dispatchCommand(mxComponent, ".uno:SelectAll", {});
+ Scheduler::ProcessEventsToIdle();
+
+ // When picking a theme color on the sidebar:
+ uno::Sequence<beans::PropertyValue> aColorArgs = {
+ comphelper::makePropertyValue("Color", static_cast<sal_Int32>(0xdae3f3)), // 80% light blue
+ comphelper::makePropertyValue("ColorThemeIndex", static_cast<sal_Int16>(4)), // accent 1
+ comphelper::makePropertyValue("ColorLumMod", static_cast<sal_Int16>(2000)),
+ comphelper::makePropertyValue("ColorLumOff", static_cast<sal_Int16>(8000)),
+ };
+ dispatchCommand(mxComponent, ".uno:Color", aColorArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ // Then make sure the theme "metadata" is set in the document model:
+ pView->EndTextEditCurrentView();
+ CPPUNIT_ASSERT(!pView->IsTextEdit());
+ uno::Reference<container::XEnumerationAccess> xShapeParaAccess(xShape, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xPara(
+ xShapeParaAccess->createEnumeration()->nextElement(), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xPortion(xPara->createEnumeration()->nextElement(),
+ uno::UNO_QUERY);
+ {
+ uno::Reference<util::XThemeColor> xThemeColor;
+ CPPUNIT_ASSERT(xPortion->getPropertyValue("CharColorThemeReference") >>= xThemeColor);
+ CPPUNIT_ASSERT(xThemeColor.is());
+ model::ThemeColor aThemeColor;
+ model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+ CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aThemeColor.getType());
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod,
+ aThemeColor.getTransformations()[0].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), aThemeColor.getTransformations()[0].mnValue);
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff,
+ aThemeColor.getTransformations()[1].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(8000), aThemeColor.getTransformations()[1].mnValue);
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testFillColorTheme)
+{
+ // Given an Impress document with a selected shape:
+ mxComponent = loadFromDesktop("private:factory/simpress",
+ "com.sun.star.presentation.PresentationDocument");
+ uno::Reference<drawing::XDrawPagesSupplier> xPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xPage(xPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+ uno::Reference<view::XSelectionSupplier> xController(xModel->getCurrentController(),
+ uno::UNO_QUERY);
+ xController->select(uno::makeAny(xShape));
+
+ // When setting the fill color of that shape, with theme metadata & effects:
+ uno::Sequence<beans::PropertyValue> aColorArgs = {
+ comphelper::makePropertyValue("FillColor", static_cast<sal_Int32>(0xed7d31)), // orange
+ comphelper::makePropertyValue("ColorThemeIndex", static_cast<sal_Int16>(4)), // accent 1
+ comphelper::makePropertyValue("ColorLumMod", static_cast<sal_Int16>(4000)),
+ comphelper::makePropertyValue("ColorLumOff", static_cast<sal_Int16>(6000)),
+ };
+ dispatchCommand(mxComponent, ".uno:FillColor", aColorArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ // Then make sure the theme index is not lost when the sidebar sets it:
+ {
+ uno::Reference<util::XThemeColor> xThemeColor;
+ CPPUNIT_ASSERT(xShape->getPropertyValue("FillColorThemeReference") >>= xThemeColor);
+ CPPUNIT_ASSERT(xThemeColor.is());
+ model::ThemeColor aThemeColor;
+ model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+ CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aThemeColor.getType());
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod,
+ aThemeColor.getTransformations()[0].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(4000), aThemeColor.getTransformations()[0].mnValue);
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff,
+ aThemeColor.getTransformations()[1].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(6000), aThemeColor.getTransformations()[1].mnValue);
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testFillColorNoColor)
+{
+ // Given an empty Impress document:
+ mxComponent = loadFromDesktop("private:factory/simpress",
+ "com.sun.star.presentation.PresentationDocument");
+ auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
+ sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
+ SfxDispatcher* pDispatcher = pViewShell->GetViewFrame()->GetDispatcher();
+
+ // When dispatching a fill color that only has a fill style (no color), then make sure we don't
+ // crash:
+ XFillStyleItem aXFillStyleItem(drawing::FillStyle_NONE);
+ pDispatcher->ExecuteList(SID_ATTR_FILL_COLOR, SfxCallMode::RECORD, { &aXFillStyleItem });
+}
+
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testThemeShapeInsert)
+{
+ // Given a document with a theme, accent1 color is set to 0x000004:
+ mxComponent = loadFromDesktop("private:factory/simpress",
+ "com.sun.star.presentation.PresentationDocument");
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ uno::Reference<drawing::XMasterPageTarget> xMasterPageTarget(xDrawPage, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xMasterPage(xMasterPageTarget->getMasterPage(),
+ uno::UNO_QUERY);
+ comphelper::SequenceAsHashMap aMap;
+ aMap["Name"] <<= OUString("mytheme");
+ aMap["ColorSchemeName"] <<= OUString("mycolorscheme");
+ uno::Sequence<util::Color> aColorScheme
+ = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb };
+ aMap["ColorScheme"] <<= aColorScheme;
+ uno::Any aTheme(aMap.getAsConstPropertyValueList());
+ xMasterPage->setPropertyValue("Theme", aTheme);
+
+ // When inserting a shape:
+ uno::Sequence<beans::PropertyValue> aArgs = {
+ comphelper::makePropertyValue("CreateDirectly", true),
+ };
+ dispatchCommand(mxComponent, ".uno:BasicShapes.round-rectangle", aArgs);
+
+ // Then make sure the that fill color of the last shape is the accent1 color:
+ sal_Int32 nShapeIndex = xDrawPage->getCount() - 1;
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(nShapeIndex), uno::UNO_QUERY);
+ sal_Int32 nFillColor{};
+ xShape->getPropertyValue("FillColor") >>= nFillColor;
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 0 / 0x000004 (~black)
+ // - Actual : 7512015 / 0x729fcf (~blue)
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4), nFillColor);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */