diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-08-22 09:15:15 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2019-08-29 11:32:07 +0200 |
commit | 629a0173ea46bc9b8115e47a5138b19d07cdf52e (patch) | |
tree | 66dd62d58e5f236264f200a941e679df3704e4e9 /desktop/qa/desktop_lib/test_desktop_lib.cxx | |
parent | bcd9acfedc6f303398df125830739154ddf1c664 (diff) |
sc: LOK: commit cell edits before saveascd-6.0-29-20190828
Users typically don't recognize that changes
done to a cell need to be committed (typically
by hitting RETURN) before they are saved to file.
This is especially true on the web.
This patch commits any in-flight changes before
SaveAs. This is currently done only for LOK and
unconditionally at that. This can be controlled
via a flag, if there is such a use-case.
Change-Id: I2a88b2f1df47be764058f4505561b22830d9d67a
Reviewed-on: https://gerrit.libreoffice.org/78012
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
(cherry picked from commit cc7eb4d345e3fede698a3f255c1938d275305c14)
Reviewed-on: https://gerrit.libreoffice.org/78149
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'desktop/qa/desktop_lib/test_desktop_lib.cxx')
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index bc44c5a274eb..46b2dcb431fc 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -80,6 +80,7 @@ public: UnoApiTest::tearDown(); }; + LibLODocument_Impl* loadDocUrl(const OUString& rFileURL, LibreOfficeKitDocumentType eType); LibLODocument_Impl* loadDoc(const char* pName, LibreOfficeKitDocumentType eType = LOK_DOCTYPE_TEXT); void closeDoc(); static void callback(int nType, const char* pPayload, void* pData); @@ -133,6 +134,7 @@ public: void testSignDocument_PEM_PDF(); void testTextSelectionHandles(); void testDialogPaste(); + void testCalcSaveAs(); void testABI(); CPPUNIT_TEST_SUITE(DesktopLOKTest); @@ -186,6 +188,7 @@ public: #endif CPPUNIT_TEST(testTextSelectionHandles); CPPUNIT_TEST(testDialogPaste); + CPPUNIT_TEST(testCalcSaveAs); CPPUNIT_TEST(testABI); CPPUNIT_TEST_SUITE_END(); @@ -230,10 +233,8 @@ static Control* GetFocusControl(vcl::Window const * pParent) return nullptr; } -LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) +LibLODocument_Impl* DesktopLOKTest::loadDocUrl(const OUString& rFileURL, LibreOfficeKitDocumentType eType) { - OUString aFileURL; - createFileURL(OUString::createFromAscii(pName), aFileURL); OUString aService; switch (eType) { @@ -250,7 +251,7 @@ LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDoc CPPUNIT_ASSERT(false); break; } - mxComponent = loadFromDesktop(aFileURL, aService); + mxComponent = loadFromDesktop(rFileURL, aService); if (!mxComponent.is()) { CPPUNIT_ASSERT(false); @@ -258,6 +259,13 @@ LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDoc return new LibLODocument_Impl(mxComponent); } +LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) +{ + OUString aFileURL; + createFileURL(OUString::createFromAscii(pName), aFileURL); + return loadDocUrl(aFileURL, eType); +} + void DesktopLOKTest::closeDoc() { if (mxComponent.is()) @@ -1827,6 +1835,7 @@ void DesktopLOKTest::testRedlineCalc() class ViewCallback { public: + OString m_aCellFormula; bool m_bTilesInvalidated; tools::Rectangle m_aOwnCursor; boost::property_tree::ptree m_aCommentCallbackResult; @@ -1871,6 +1880,11 @@ public: m_aCommentCallbackResult = m_aCommentCallbackResult.get_child("comment"); } break; + case LOK_CALLBACK_CELL_FORMULA: + { + m_aCellFormula = aPayload; + } + break; } } }; @@ -2653,6 +2667,40 @@ void DesktopLOKTest::testDialogPaste() comphelper::LibreOfficeKit::setActive(false); } +void DesktopLOKTest::testCalcSaveAs() +{ + comphelper::LibreOfficeKit::setActive(); + + LibLODocument_Impl* pDocument = loadDoc("sheets.ods"); + CPPUNIT_ASSERT(pDocument); + + // Enter some text, but don't commit. + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'X', 0); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'X', 0); + Scheduler::ProcessEventsToIdle(); + + // Save as a new file. + OUString aNewFileUrl = "file:///tmp/saveas.ods"; + pDocument->pClass->saveAs(pDocument, aNewFileUrl.toUtf8().getStr(), nullptr, nullptr); + closeDoc(); + + // Load the new document and verify that the in-flight changes are saved. + pDocument = loadDocUrl(aNewFileUrl, LOK_DOCTYPE_SPREADSHEET); + CPPUNIT_ASSERT(pDocument); + + ViewCallback aView; + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView); + + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 0, KEY_RIGHT); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, KEY_LEFT); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 0, KEY_LEFT); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(OString("X"), aView.m_aCellFormula); +} + namespace { size_t documentClassOffset(int i) |