From a779115ee56769b7691b02e4b8739c5c8f81258e Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 14 Nov 2015 16:59:01 +0100 Subject: [PATCH 335/398] CppunitTest_desktop_lib: add Writer comments textcase Fails without e.g. the last hunk of commit 1ba9d7fd2a7a3e2b4f52ed0f5efdf7df867b9db3 (sw lok: forward key events to annotation window if necessary, 2015-11-12). Change-Id: I7f39530881f6141fea956b751aa57eb2bdcadcb2 (cherry picked from commit 1118689e70ed49604ded6e1ae83a22bdc995b2fb) --- desktop/CppunitTest_desktop_lib.mk | 1 + desktop/qa/desktop_lib/test_desktop_lib.cxx | 46 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk index ca9d8db32c9f..bbedfdc8348e 100644 --- a/desktop/CppunitTest_desktop_lib.mk +++ b/desktop/CppunitTest_desktop_lib.mk @@ -67,6 +67,7 @@ $(eval $(call gb_CppunitTest_use_components,desktop_lib,\ xmloff/util/xo \ i18npool/source/search/i18nsearch \ filter/source/graphic/graphicfilter \ + linguistic/source/lng \ )) $(eval $(call gb_CppunitTest_use_configuration,desktop_lib)) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 7d94daea0fbc..930dd21ec081 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -10,6 +10,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -70,6 +74,7 @@ public: void testRowColumnHeaders(); void testCellCursor(); void testCommandResult(); + void testWriterComments(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testGetStyles); @@ -85,6 +90,7 @@ public: CPPUNIT_TEST(testRowColumnHeaders); CPPUNIT_TEST(testCellCursor); CPPUNIT_TEST(testCommandResult); + CPPUNIT_TEST(testWriterComments); CPPUNIT_TEST_SUITE_END(); uno::Reference mxComponent; @@ -491,6 +497,46 @@ void DesktopLOKTest::testCommandResult() CPPUNIT_ASSERT_EQUAL(aTree.get_child("success").get_value(), true); } +void DesktopLOKTest::testWriterComments() +{ + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); + uno::Reference xToolkit(com::sun::star::awt::Toolkit::create(comphelper::getProcessComponentContext()), uno::UNO_QUERY); + + // Insert a comment at the beginning of the document and wait till the main + // loop grabs the focus, so characters end up in the annotation window. + TimeValue aTimeValue = {2 , 0}; // 2 seconds max + m_aCommandResultCondition.reset(); + pDocument->pClass->postUnoCommand(pDocument, ".uno:InsertAnnotation", nullptr, true); + m_aCommandResultCondition.wait(aTimeValue); + CPPUNIT_ASSERT(!m_aCommandResult.isEmpty()); + xToolkit->reschedule(); + + // Test that we have a comment. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParagraphEnumerationAccess(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference xParagraphEnumeration = xParagraphEnumerationAccess->createEnumeration(); + uno::Reference xParagraph(xParagraphEnumeration->nextElement(), uno::UNO_QUERY); + uno::Reference xTextPortionEnumeration = xParagraph->createEnumeration(); + uno::Reference xTextPortion(xTextPortionEnumeration->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), xTextPortion->getPropertyValue("TextPortionType").get()); + + // Type "test" and finish editing. + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'e', 0); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 's', 0); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, com::sun::star::awt::Key::ESCAPE); + + // Test that the typed characters ended up in the right window. + auto xTextField = xTextPortion->getPropertyValue("TextField").get< uno::Reference >(); + // This was empty, typed characters ended up in the body text. + CPPUNIT_ASSERT_EQUAL(OUString("test"), xTextField->getPropertyValue("Content").get()); + + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- 2.12.0