tdf#148620: sd: move UITest to CppUnittest
hopefully this will fix the sporadic failures of
UITest_impress_tests2 in Jenkins
Change-Id: I3df2484b07a0cf7a0efdafb7235c3ff83f187200
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139928
Tested-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sd/qa/uitest/impress_tests2/tdf148620.py b/sd/qa/uitest/impress_tests2/tdf148620.py
deleted file mode 100644
index f52284f..0000000
--- a/sd/qa/uitest/impress_tests2/tdf148620.py
+++ /dev/null
@@ -1,89 +0,0 @@
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
#
from uitest.uihelper.common import get_state_as_dict
from libreoffice.uno.propertyvalue import mkPropertyValues
from uitest.framework import UITestCase
class Tdf148620(UITestCase):
def test_Tdf148620(self):
with self.ui_test.create_doc_in_start_center("impress") as document:
xTemplateDlg = self.xUITest.getTopFocusWindow()
xCancelBtn = xTemplateDlg.getChild("close")
self.ui_test.close_dialog_through_button(xCancelBtn)
xDoc = self.xUITest.getTopFocusWindow()
xEditWin = xDoc.getChild("impress_win")
xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
xEditWin.executeAction("TYPE", mkPropertyValues({"TEXT":"one"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"TEXT":"two"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"TEXT":"three"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"TEXT":"four"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"TEXT":"five"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
xEditWin.executeAction("TYPE", mkPropertyValues({"TEXT":"six"}))
self.assertEqual("One\nTwo\nThree\nFour\nFive\nsix", document.DrawPages[0].getByIndex(1).String)
xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
xArgs = mkPropertyValues({"KeyModifier": 0})
self.xUITest.executeCommandWithParameters(".uno:OutlineUp", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nTwo\nThree\nFour\nsix\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineUp", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nTwo\nThree\nsix\nFour\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineUp", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nTwo\nsix\nThree\nFour\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineUp", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nsix\nTwo\nThree\nFour\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineUp", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("six\nOne\nTwo\nThree\nFour\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineDown", xArgs)
xToolkit.processEventsToIdle()
# Without the fix in place, this test would have failed with
# AssertionError: 'One\nsix\nTwo\nThree\nFour\nFive' != 'One\nTwo\nsix\nThree\nFour\nFive'
self.assertEqual("One\nsix\nTwo\nThree\nFour\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineDown", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nTwo\nsix\nThree\nFour\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineDown", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nTwo\nThree\nsix\nFour\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineDown", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nTwo\nThree\nFour\nsix\nFive", document.DrawPages[0].getByIndex(1).String)
self.xUITest.executeCommandWithParameters(".uno:OutlineDown", xArgs)
xToolkit.processEventsToIdle()
self.assertEqual("One\nTwo\nThree\nFour\nFive\nsix", document.DrawPages[0].getByIndex(1).String)
# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index b309b4e..3642bef 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -67,6 +67,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();
FileFormat* getFormat(sal_Int32 nExportType);
@@ -100,6 +102,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)
{
@@ -110,24 +129,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());
}
}
@@ -586,6 +598,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",
@@ -607,22 +699,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();