From b61ca6f7bf4e5b5b1980ad03f2a5f2d01e8c22fe Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Wed, 16 Nov 2022 16:59:38 +0100 Subject: [PATCH] CppunitTest_sc_uicalc: inherit from ScModelTestBase so createScDoc handles the dispose of new documents saveAndClose can go now Change-Id: I7f88ef6ff9aaece72461489a31b0ef456ce5e170 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142781 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- include/test/unoapi_test.hxx | 1 - sc/CppunitTest_sc_uicalc.mk | 2 + sc/qa/unit/uicalc/uicalc.cxx | 967 +++++++++++++++-------------------- test/source/unoapi_test.cxx | 8 - 4 files changed, 409 insertions(+), 569 deletions(-) diff --git a/include/test/unoapi_test.hxx b/include/test/unoapi_test.hxx index 461b52dcad93..ece36abdb149 100644 --- a/include/test/unoapi_test.hxx +++ b/include/test/unoapi_test.hxx @@ -42,7 +42,6 @@ public: const css::uno::Sequence& rParams = {}); void save(const OUString& rFilter, const char* pPassword = nullptr); - void saveAndClose(const OUString& rFilter); void saveAndReload(const OUString& rFilter, const char* pPassword = nullptr); std::unique_ptr parsePDFExport(const OString& rPassword = OString()); diff --git a/sc/CppunitTest_sc_uicalc.mk b/sc/CppunitTest_sc_uicalc.mk index af23c8b38966..97a8291ff66c 100644 --- a/sc/CppunitTest_sc_uicalc.mk +++ b/sc/CppunitTest_sc_uicalc.mk @@ -12,6 +12,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sc_uicalc)) $(eval $(call gb_CppunitTest_use_externals,sc_uicalc, \ boost_headers \ mdds_headers \ + libxml2 \ )) $(eval $(call gb_CppunitTest_add_exception_objects,sc_uicalc, \ @@ -25,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_uicalc, \ i18nlangtag \ sal \ sc \ + scqahelper \ sfx \ subsequenttest \ svl \ diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 3dd1d13c4b69..518a219e3a92 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include +#include "../helper/qahelper.hxx" #include #include #include @@ -36,50 +36,45 @@ using namespace ::com::sun::star; -class ScUiCalcTest : public UnoApiTest +class ScUiCalcTest : public ScModelTestBase { public: ScUiCalcTest(); - ScModelObj* createDoc(const char* pName = nullptr); void goToCell(const OUString& rCell); - void typeString(ScModelObj& rModelObj, const std::u16string_view& rStr); - void insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, - const std::u16string_view& rStr); - void insertArrayToCell(ScModelObj& rModelObj, const OUString& rCell, - const std::u16string_view& rStr); + void typeString(const std::u16string_view& rStr); + void insertStringToCell(const OUString& rCell, const std::u16string_view& rStr); + void insertArrayToCell(const OUString& rCell, const std::u16string_view& rStr); void insertNewSheet(ScDocument& rDoc); }; ScUiCalcTest::ScUiCalcTest() - : UnoApiTest("sc/qa/unit/uicalc/data") + : ScModelTestBase("sc/qa/unit/uicalc/data") { } -static void lcl_AssertCurrentCursorPosition(const ScDocument& rDoc, std::u16string_view rStr) +static void lcl_AssertCurrentCursorPosition(ScDocShell& rDocSh, std::u16string_view rStr) { ScAddress aAddr; sal_Int32 nOffset = 0; - ScRangeStringConverter::GetAddressFromString(aAddr, rStr, rDoc, + ScRangeStringConverter::GetAddressFromString(aAddr, rStr, rDocSh.GetDocument(), formula::FormulaGrammar::CONV_OOO, nOffset); + ScTabViewShell* pViewShell = rDocSh.GetBestViewShell(false); CPPUNIT_ASSERT_EQUAL_MESSAGE( OUString(OUString::Concat("Incorrect Column in position ") + rStr).toUtf8().getStr(), - aAddr.Col(), ScDocShell::GetViewData()->GetCurX()); + aAddr.Col(), pViewShell->GetViewData().GetCurX()); CPPUNIT_ASSERT_EQUAL_MESSAGE( OUString(OUString::Concat("Incorrect Row in position ") + rStr).toUtf8().getStr(), - aAddr.Row(), ScDocShell::GetViewData()->GetCurY()); + aAddr.Row(), pViewShell->GetViewData().GetCurY()); } -static void lcl_SelectObjectByName(std::u16string_view rObjName) +static void lcl_SelectObjectByName(ScTabViewShell& rViewShell, std::u16string_view rObjName) { - ScTabViewShell* pViewShell = ScDocShell::GetViewData()->GetViewShell(); - CPPUNIT_ASSERT(pViewShell); - - bool bFound = pViewShell->SelectObject(rObjName); + bool bFound = rViewShell.SelectObject(rObjName); CPPUNIT_ASSERT_MESSAGE( OString(OUStringToOString(rObjName, RTL_TEXTENCODING_UTF8) + " not found.").getStr(), bFound); - CPPUNIT_ASSERT(ScDocShell::GetViewData()->GetScDrawView()->AreObjectsMarked()); + CPPUNIT_ASSERT(rViewShell.GetViewData().GetScDrawView()->AreObjectsMarked()); } void ScUiCalcTest::goToCell(const OUString& rCell) @@ -89,37 +84,38 @@ void ScUiCalcTest::goToCell(const OUString& rCell) dispatchCommand(mxComponent, ".uno:GoToCell", aArgs); } -void ScUiCalcTest::typeString(ScModelObj& rModelObj, const std::u16string_view& rStr) +void ScUiCalcTest::typeString(const std::u16string_view& rStr) { + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); for (const char16_t c : rStr) { - rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0); - rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0); Scheduler::ProcessEventsToIdle(); } } -void ScUiCalcTest::insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, - const std::u16string_view& rStr) +void ScUiCalcTest::insertStringToCell(const OUString& rCell, const std::u16string_view& rStr) { goToCell(rCell); - typeString(rModelObj, rStr); + typeString(rStr); - rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); - rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); } -void ScUiCalcTest::insertArrayToCell(ScModelObj& rModelObj, const OUString& rCell, - const std::u16string_view& rStr) +void ScUiCalcTest::insertArrayToCell(const OUString& rCell, const std::u16string_view& rStr) { goToCell(rCell); - typeString(rModelObj, rStr); + typeString(rStr); - rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | KEY_SHIFT | awt::Key::RETURN); - rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | KEY_SHIFT | awt::Key::RETURN); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | KEY_SHIFT | awt::Key::RETURN); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | KEY_SHIFT | awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); } @@ -134,84 +130,61 @@ void ScUiCalcTest::insertNewSheet(ScDocument& rDoc) CPPUNIT_ASSERT_EQUAL(static_cast(nTabs + 1), rDoc.GetTableCount()); } -ScModelObj* ScUiCalcTest::createDoc(const char* pName) -{ - if (!pName) - mxComponent = loadFromDesktop("private:factory/scalc"); - else - loadFromURL(OUString::createFromAscii(pName)); - - ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - return pModelObj; -} - CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf100847) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); // Save the document - saveAndClose("calc8"); + save("calc8"); // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + getScDoc(); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf142854_GridVisibilityImportXlsxInHeadlessMode) { // Tests are running in Headless mode // Import an ods file with 'Hide' global grid visibility setting. - ScModelObj* pModelObj = createDoc("tdf126541_GridOffGlobally.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf126541_GridOffGlobally.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT(!pDoc->GetViewOptions().GetOption(VOPT_GRID)); // To avoid regression, in headless mode leave the bug tdf126541 // It means Sheet based grid line visibility setting will overwrite the global setting. // If there is only 1 sheet in the document, it will not result visible problems. - pModelObj = createDoc("tdf126541_GridOff.xlsx"); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf126541_GridOff.xlsx"); + pDoc = getScDoc(); CPPUNIT_ASSERT(!pDoc->GetViewOptions().GetOption(VOPT_GRID)); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"2015"); - insertStringToCell(*pModelObj, "A2", u"2015"); - insertStringToCell(*pModelObj, "A3", u"2015"); + insertStringToCell("A1", u"2015"); + insertStringToCell("A2", u"2015"); + insertStringToCell("A3", u"2015"); - insertStringToCell(*pModelObj, "B1", u"1"); - insertStringToCell(*pModelObj, "B2", u"1"); - insertStringToCell(*pModelObj, "B3", u"2"); + insertStringToCell("B1", u"1"); + insertStringToCell("B2", u"1"); + insertStringToCell("B3", u"2"); - insertStringToCell(*pModelObj, "C1", u"10"); - insertStringToCell(*pModelObj, "C2", u"20"); - insertStringToCell(*pModelObj, "C3", u"5"); + insertStringToCell("C1", u"10"); + insertStringToCell("C2", u"20"); + insertStringToCell("C3", u"5"); - insertStringToCell(*pModelObj, "D1", u"BIG FISH"); - insertStringToCell(*pModelObj, "D2", u"FISHFISH"); - insertStringToCell(*pModelObj, "D3", u"FISHY"); + insertStringToCell("D1", u"BIG FISH"); + insertStringToCell("D2", u"FISHFISH"); + insertStringToCell("D3", u"FISHY"); // Save the document - saveAndClose("calc8"); + save("calc8"); // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + pDoc = getScDoc(); // Insert the references to the external document { @@ -219,7 +192,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) OUString aFormula = "=SUMIFS('" + maTempFile.GetURL() + "'#$Sheet1.C1:C3,'" + maTempFile.GetURL() + "'#$Sheet1.B1:B3,1,'" + maTempFile.GetURL() + "'#$Sheet1.A1:A3,2015)"; - insertStringToCell(*pModelObj, "A1", aFormula); + insertStringToCell("A1", aFormula); // tdf#115162: Without the fix in place, this test would have failed with // - Expected: 30 @@ -231,7 +204,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) // tdf#114820 OUString aFormula = "=VLOOKUP('" + maTempFile.GetURL() + "'#$Sheet1.A1;'" + maTempFile.GetURL() + "'#$Sheet1.A1:B3,2,0)"; - insertStringToCell(*pModelObj, "A1", aFormula); + insertStringToCell("A1", aFormula); // Without the fix in place, this test would have failed with // - Expected: 1 @@ -243,7 +216,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) // tdf#116149 OUString aFormula = "=VAR('" + maTempFile.GetURL() + "'#$Sheet1.C1;'" + maTempFile.GetURL() + "'#$Sheet1.C2)"; - insertStringToCell(*pModelObj, "A1", aFormula); + insertStringToCell("A1", aFormula); // Without the fix in place, this test would have failed with // - Expected: 50 @@ -255,13 +228,13 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) // tdf#100847 // Use an empty cell OUString aFormula = "=+'" + maTempFile.GetURL() + "'#$Sheet1.A1000"; - insertStringToCell(*pModelObj, "A1", aFormula); + insertStringToCell("A1", aFormula); aFormula = "=+'" + maTempFile.GetURL() + "'#$Sheet1.A1000*1"; - insertStringToCell(*pModelObj, "B1", aFormula); + insertStringToCell("B1", aFormula); aFormula = "=+N('" + maTempFile.GetURL() + "'#$Sheet1.A1000)*1"; - insertStringToCell(*pModelObj, "C1", aFormula); + insertStringToCell("C1", aFormula); CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(0, 0, 0))); @@ -275,10 +248,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) { //tdf#36387 OUString aAndFormula = "=AND('" + maTempFile.GetURL() + "'#$Sheet1.A1:C1)"; - insertStringToCell(*pModelObj, "A1", aAndFormula); + insertStringToCell("A1", aAndFormula); OUString aOrFormula = "=OR('" + maTempFile.GetURL() + "'#$Sheet1.A1:C1)"; - insertStringToCell(*pModelObj, "B1", aOrFormula); + insertStringToCell("B1", aOrFormula); // Without the fix in place, this test would have failed with // - Expected: TRUE @@ -291,7 +264,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) //tdf#113898 OUString aAndFormula = "=SUMPRODUCT(NOT(ISERROR(FIND(\"FISH\";'" + maTempFile.GetURL() + "'#$Sheet1.D1:D3))))"; - insertStringToCell(*pModelObj, "A1", aAndFormula); + insertStringToCell("A1", aAndFormula); // Without the fix in place, this test would have failed with // - Expected: 3 @@ -302,26 +275,22 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testExternalReferences) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf103994) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"1"); - insertStringToCell(*pModelObj, "B1", u"2"); + insertStringToCell("A1", u"1"); + insertStringToCell("B1", u"2"); // Save the document - saveAndClose("calc8"); + save("calc8"); // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + pDoc = getScDoc(); // Insert the reference to the external document OUString aFormula = "='" + maTempFile.GetURL() + "'#$Sheet1.A1"; - insertStringToCell(*pModelObj, "A1", aFormula); + insertStringToCell("A1", aFormula); CPPUNIT_ASSERT_EQUAL(aFormula, pDoc->GetFormula(0, 0, 0)); CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(ScAddress(0, 0, 0))); @@ -345,28 +314,24 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf103994) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf113541) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"50"); + insertStringToCell("A1", u"50"); // Save the document - saveAndClose("calc8"); + save("calc8"); // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + pDoc = getScDoc(); // Change grammar to Excel A1 pDoc->SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_A1); // Insert the reference to the external document OUString aFormula = "=['" + maTempFile.GetURL() + "']Sheet1!A1"; - insertStringToCell(*pModelObj, "A1", aFormula); + insertStringToCell("A1", aFormula); // Without the fix in place, this test would have failed with // - Expected: 50 @@ -379,9 +344,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf113541) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126577) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); goToCell("A1:A20"); @@ -412,12 +376,11 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126577) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf107869) { // Without the fix in place, this test would have crashed - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"A"); - insertStringToCell(*pModelObj, "A2", u"B"); + insertStringToCell("A1", u"A"); + insertStringToCell("A2", u"B"); // Add a new comment to A1 and A2 uno::Sequence aArgs @@ -493,11 +456,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf107869) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf63805) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"2012-10-31"); + insertStringToCell("A1", u"2012-10-31"); goToCell("A1:A20"); @@ -543,9 +505,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf63805) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf147894) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); //Select the first row goToCell("1:1"); @@ -566,18 +527,17 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf147894) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf94208) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"=COUNTA(B:B)"); - insertStringToCell(*pModelObj, "A3", u"Range"); - insertStringToCell(*pModelObj, "A4", u"Range"); - insertStringToCell(*pModelObj, "A5", u"Range"); - insertStringToCell(*pModelObj, "A6", u"Range"); - insertStringToCell(*pModelObj, "A7", u"Range"); - insertStringToCell(*pModelObj, "A8", u"Range"); - insertStringToCell(*pModelObj, "B6", u"Test"); + insertStringToCell("A1", u"=COUNTA(B:B)"); + insertStringToCell("A3", u"Range"); + insertStringToCell("A4", u"Range"); + insertStringToCell("A5", u"Range"); + insertStringToCell("A6", u"Range"); + insertStringToCell("A7", u"Range"); + insertStringToCell("A8", u"Range"); + insertStringToCell("B6", u"Test"); CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(ScAddress(0, 0, 0))); @@ -610,15 +570,14 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf94208) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf37623) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); goToCell("A3:A4"); dispatchCommand(mxComponent, ".uno:HideRow", {}); - insertStringToCell(*pModelObj, "A2", u"1"); + insertStringToCell("A2", u"1"); goToCell("A2:A6"); @@ -638,9 +597,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf37623) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144308) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); css::uno::Reference xGlobalSheetSettings = css::sheet::GlobalSheetSettings::create(::comphelper::getProcessComponentContext()); @@ -648,15 +606,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144308) xGlobalSheetSettings->setDoAutoComplete(true); - insertStringToCell(*pModelObj, "A1", u"ABC"); + insertStringToCell("A1", u"ABC"); - insertStringToCell(*pModelObj, "A2", u"A"); + insertStringToCell("A2", u"A"); CPPUNIT_ASSERT_EQUAL(OUString("ABC"), pDoc->GetString(ScAddress(0, 1, 0))); xGlobalSheetSettings->setDoAutoComplete(false); - insertStringToCell(*pModelObj, "A3", u"A"); + insertStringToCell("A3", u"A"); // Without the fix in place, this test would have failed with // - Expected: A @@ -669,20 +627,20 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144308) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf56036) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); goToCell("A1"); - typeString(*pModelObj, u"=SUM( 1 + 2 "); + typeString(u"=SUM( 1 + 2 "); // Insert Newline + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); - typeString(*pModelObj, u"+ 3)"); + typeString(u"+ 3)"); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); @@ -696,15 +654,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf56036) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119162) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); goToCell("A1"); - typeString(*pModelObj, u"Test"); + typeString(u"Test"); // Insert Newline + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); @@ -734,16 +692,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119162) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf90579) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"2300"); - insertStringToCell(*pModelObj, "A2", u"Libre"); - insertStringToCell(*pModelObj, "B1", u"10"); - insertStringToCell(*pModelObj, "B2", u"Office"); - insertStringToCell(*pModelObj, "C1", u"=SUM(A1:B1)"); - insertStringToCell(*pModelObj, "C2", u"=A2&B2"); + insertStringToCell("A1", u"2300"); + insertStringToCell("A2", u"Libre"); + insertStringToCell("B1", u"10"); + insertStringToCell("B2", u"Office"); + insertStringToCell("C1", u"=SUM(A1:B1)"); + insertStringToCell("C2", u"=A2&B2"); CPPUNIT_ASSERT_EQUAL(OUString("2310"), pDoc->GetString(ScAddress(2, 0, 0))); CPPUNIT_ASSERT_EQUAL(OUString("LibreOffice"), pDoc->GetString(ScAddress(2, 1, 0))); @@ -769,9 +726,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf90579) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124820) { - ScModelObj* pModelObj = createDoc("tdf124820.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf124820.xlsx"); + ScDocument* pDoc = getScDoc(); goToCell("B2"); @@ -779,10 +735,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124820) Scheduler::ProcessEventsToIdle(); saveAndReload("Calc Office Open XML"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + pDoc = getScDoc(); vcl::Font aFont; const ScPatternAttr* pPattern = pDoc->GetPattern(1, 1, 0); @@ -795,9 +748,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124820) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119155) { - ScModelObj* pModelObj = createDoc("tdf119155.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf119155.xlsx"); + ScDocument* pDoc = getScDoc(); goToCell("C2:C14"); @@ -813,9 +765,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119155) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf146795) { - ScModelObj* pModelObj = createDoc("tdf146795.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf146795.ods"); + ScDocument* pDoc = getScDoc(); // Disable replace cell warning ScModule* pMod = SC_MOD(); @@ -830,6 +781,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf146795) Scheduler::ProcessEventsToIdle(); // Move to B3 + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); Scheduler::ProcessEventsToIdle(); @@ -859,9 +811,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf146795) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf147744) { - ScModelObj* pModelObj = createDoc("tdf147744.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf147744.ods"); + ScDocument* pDoc = getScDoc(); // Disable replace cell warning ScModule* pMod = SC_MOD(); @@ -876,6 +827,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf147744) Scheduler::ProcessEventsToIdle(); // Move to A3 + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); Scheduler::ProcessEventsToIdle(); @@ -901,9 +853,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf147744) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138432) { - ScModelObj* pModelObj = createDoc("tdf138432.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf138432.ods"); + ScDocument* pDoc = getScDoc(); // Set the system locale to Hungarian SvtSysLocaleOptions aOptions; @@ -925,11 +876,12 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138432) goToCell("A2"); - typeString(*pModelObj, u"="); + typeString(u"="); dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); @@ -942,19 +894,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138432) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf143896) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A2000", u"Test"); + insertStringToCell("A2000", u"Test"); CPPUNIT_ASSERT_EQUAL(OUString("Test"), pDoc->GetString(ScAddress(0, 1999, 0))); saveAndReload("Calc Office Open XML"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + pDoc = getScDoc(); // Without the fix in place, this test would have failed with // - Expected: Test @@ -964,11 +912,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf143896) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf145085) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertArrayToCell(*pModelObj, "A1", u"=HYPERLINK(\"a\";\"b\")"); + insertArrayToCell("A1", u"=HYPERLINK(\"a\";\"b\")"); CPPUNIT_ASSERT_EQUAL(OUString("b"), pDoc->GetString(ScAddress(0, 0, 0))); @@ -980,11 +927,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf145085) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf148863) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertArrayToCell(*pModelObj, "A1", u"=TRANSPOSE(IF({0|0|0}=0;RANDBETWEEN.NV(1;1000000)))"); + insertArrayToCell("A1", u"=TRANSPOSE(IF({0|0|0}=0;RANDBETWEEN.NV(1;1000000)))"); double nA1 = pDoc->GetValue(ScAddress(0, 0, 0)); double nB1 = pDoc->GetValue(ScAddress(1, 0, 0)); @@ -998,10 +944,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf148863) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144244) { - ScModelObj* pModelObj = createDoc("tdf144244.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf144244.ods"); + ScDocument* pDoc = getScDoc(); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); uno::Reference xPage(pModelObj->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL(static_cast(2), xPage->getCount()); @@ -1020,9 +966,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144244) // Without the fix in place, this test would have crashed saveAndReload("calc8"); pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(OUString("x"), pDoc->GetString(ScAddress(0, 0, 0))); @@ -1032,9 +976,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144244) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf100582) { - ScModelObj* pModelObj = createDoc("tdf100582.xls"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf100582.xls"); + ScDocument* pDoc = getScDoc(); // Disable replace cell warning ScModule* pMod = SC_MOD(); @@ -1052,10 +995,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf100582) dispatchCommand(mxComponent, ".uno:Paste", {}); saveAndReload("MS Excel 97"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + pDoc = getScDoc(); OUString aFormula = pDoc->GetFormula(3, 10, 0); @@ -1079,9 +1019,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf100582) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf145640) { - ScModelObj* pModelObj = createDoc("tdf145640.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf145640.ods"); + ScDocument* pDoc = getScDoc(); // Enable sorting with update reference ScModule* pMod = SC_MOD(); @@ -1115,9 +1054,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf145640) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf97215) { - ScModelObj* pModelObj = createDoc("tdf97215.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf97215.ods"); + ScDocument* pDoc = getScDoc(); // Enable sorting with update reference ScModule* pMod = SC_MOD(); @@ -1148,9 +1086,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf97215) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf92963) { - ScModelObj* pModelObj = createDoc("tdf92963.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf92963.ods"); + ScDocument* pDoc = getScDoc(); // Disable replace cell warning ScModule* pMod = SC_MOD(); @@ -1180,89 +1117,89 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf92963) #if !defined(MACOSX) && !defined(_WIN32) //FIXME CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf140151) { - ScModelObj* pModelObj = createDoc("tdf140151.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf140151.ods"); + ScDocShell* pDocSh = getScDocShell(); // Focus is already on the button + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); // Without the fix in place, the current cursor position wouldn't have changed - lcl_AssertCurrentCursorPosition(*pDoc, u"B111"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"B111"); } #endif CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf68290) { - ScModelObj* pModelObj = createDoc("tdf68290.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf68290.ods"); + ScDocShell* pDocSh = getScDocShell(); const std::vector aExpectedAddresses{ "L3", "L6", "L9", "L10", "L11", "L13", "L15" }; + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); for (const auto& rAddress : aExpectedAddresses) { - lcl_AssertCurrentCursorPosition(*pDoc, rAddress); + lcl_AssertCurrentCursorPosition(*pDocSh, rAddress); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); } - lcl_AssertCurrentCursorPosition(*pDoc, u"M3"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"M3"); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf132057) { - ScModelObj* pModelObj = createDoc("tdf132057.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf132057.ods"); + ScDocShell* pDocSh = getScDocShell(); - lcl_AssertCurrentCursorPosition(*pDoc, u"AU43"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"AU43"); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); Scheduler::ProcessEventsToIdle(); // Without the fix in place, the cursor would have jumped to cell BM1 - lcl_AssertCurrentCursorPosition(*pDoc, u"G39"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"G39"); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf122232) { - ScModelObj* pModelObj = createDoc("tdf122232.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf122232.ods"); + ScDocShell* pDocSh = getScDocShell(); //Start with from C6. Press tabulator to reach G6. - lcl_AssertCurrentCursorPosition(*pDoc, u"C6"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"C6"); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"G6"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"G6"); //without the fix, cursor would jump to C29 instead of C7. pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"C7"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"C7"); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf123052) { - ScModelObj* pModelObj = createDoc("tdf123052.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf123052.ods"); + ScDocShell* pDocSh = getScDocShell(); std::vector aExpectedAddresses{ "F3", "D5", "E5", "F6", "A8", "E9" }; + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); for (const auto& rAddress : aExpectedAddresses) { pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::TAB); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::TAB); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, rAddress); + lcl_AssertCurrentCursorPosition(*pDocSh, rAddress); } aExpectedAddresses.pop_back(); @@ -1275,15 +1212,14 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf123052) Scheduler::ProcessEventsToIdle(); // Without the fix in place, this test would have failed here - lcl_AssertCurrentCursorPosition(*pDoc, *it); + lcl_AssertCurrentCursorPosition(*pDocSh, *it); } } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf120660) { - ScModelObj* pModelObj = createDoc("tdf120660.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf120660.ods"); + ScDocument* pDoc = getScDoc(); // Disable replace cell warning ScModule* pMod = SC_MOD(); @@ -1335,28 +1271,29 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf120660) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf146994) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocShell* pDocSh = getScDocShell(); goToCell("B3"); - lcl_AssertCurrentCursorPosition(*pDoc, u"B3"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"B3"); dispatchCommand(mxComponent, ".uno:Copy", {}); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"D3"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"D3"); dispatchCommand(mxComponent, ".uno:Paste", {}); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_SHIFT | KEY_DOWN); Scheduler::ProcessEventsToIdle(); - ScRangeList aMarkedArea = ScDocShell::GetViewData()->GetMarkData().GetMarkedRanges(); + ScRangeList aMarkedArea = getViewShell()->GetViewData().GetMarkData().GetMarkedRanges(); OUString aMarkedAreaString; + ScDocument* pDoc = getScDoc(); ScRangeStringConverter::GetStringFromRangeList(aMarkedAreaString, &aMarkedArea, pDoc, formula::FormulaGrammar::CONV_OOO); @@ -1368,9 +1305,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf146994) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf45020) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); goToCell("A2:A3"); @@ -1378,10 +1314,11 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf45020) goToCell("A1"); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_SHIFT | KEY_DOWN); Scheduler::ProcessEventsToIdle(); - ScRangeList aMarkedArea = ScDocShell::GetViewData()->GetMarkData().GetMarkedRanges(); + ScRangeList aMarkedArea = getViewShell()->GetViewData().GetMarkData().GetMarkedRanges(); OUString aMarkedAreaString; ScRangeStringConverter::GetStringFromRangeList(aMarkedAreaString, &aMarkedArea, pDoc, formula::FormulaGrammar::CONV_OOO); @@ -1394,12 +1331,11 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf45020) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117706) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocShell* pDocSh = getScDocShell(); - insertStringToCell(*pModelObj, "A1", u"A1"); - insertStringToCell(*pModelObj, "A3", u"A3"); + insertStringToCell("A1", u"A1"); + insertStringToCell("A3", u"A3"); // Use Adding Selection dispatchCommand(mxComponent, ".uno:StatusSelectionModeExp", {}); @@ -1411,22 +1347,16 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117706) dispatchCommand(mxComponent, ".uno:GoDown", {}); dispatchCommand(mxComponent, ".uno:GoDown", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"A3"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A3"); dispatchCommand(mxComponent, ".uno:SelectRow", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Copy", {}); - mxComponent->dispose(); - mxComponent.clear(); - // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:Paste", {}); @@ -1440,9 +1370,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117706) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf86166) { - ScModelObj* pModelObj = createDoc("tdf86166.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf86166.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(static_cast(2), pDoc->GetTableCount()); @@ -1457,9 +1386,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf86166) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf149502_HangOnDeletingSheet1) { - ScModelObj* pModelObj = createDoc("tdf149502_HangOnDeletingSheet1.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf149502_HangOnDeletingSheet1.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(static_cast(4), pDoc->GetTableCount()); @@ -1474,9 +1402,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf149502_HangOnDeletingSheet1) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf149503) { - ScModelObj* pModelObj = createDoc("tdf149503.xls"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf149503.xls"); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); @@ -1494,9 +1421,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf149503) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf108292) { - ScModelObj* pModelObj = createDoc("tdf108292.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf108292.ods"); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); @@ -1504,15 +1430,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf108292) dispatchCommand(mxComponent, ".uno:Copy", {}); Scheduler::ProcessEventsToIdle(); - mxComponent->dispose(); - mxComponent.clear(); - // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + pDoc = getScDoc(); // Without the fix in place, this test would have crashed dispatchCommand(mxComponent, ".uno:Paste", {}); @@ -1524,12 +1444,11 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf108292) // Inspired from testTdf117706, test columns instead of rows CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testMultiRangeCol) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocShell* pDocSh = getScDocShell(); - insertStringToCell(*pModelObj, "A1", u"A1"); - insertStringToCell(*pModelObj, "C1", u"C1"); + insertStringToCell("A1", u"A1"); + insertStringToCell("C1", u"C1"); // Use Adding Selection dispatchCommand(mxComponent, ".uno:StatusSelectionModeExp", {}); @@ -1541,22 +1460,16 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testMultiRangeCol) dispatchCommand(mxComponent, ".uno:GoRight", {}); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"C1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"C1"); dispatchCommand(mxComponent, ".uno:SelectColumn", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Copy", {}); - mxComponent->dispose(); - mxComponent.clear(); - // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:Paste", {}); @@ -1569,13 +1482,12 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testMultiRangeCol) // Note: the transpose functionality is tested in ucalc CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteTransposed) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"1"); - insertStringToCell(*pModelObj, "A2", u"a"); - insertStringToCell(*pModelObj, "A3", u"=A1"); + insertStringToCell("A1", u"1"); + insertStringToCell("A2", u"a"); + insertStringToCell("A3", u"=A1"); // Add a note to A1 goToCell("A1"); @@ -1598,15 +1510,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteTransposed) dispatchCommand(mxComponent, ".uno:Copy", {}); - mxComponent->dispose(); - mxComponent.clear(); - // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:PasteTransposed", {}); @@ -1631,13 +1537,12 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteTransposed) // Note: the paste as link functionality is tested in ucalc CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteAsLink) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"1"); - insertStringToCell(*pModelObj, "A2", u"a"); - insertStringToCell(*pModelObj, "A3", u"=A1"); + insertStringToCell("A1", u"1"); + insertStringToCell("A2", u"a"); + insertStringToCell("A3", u"=A1"); // Add a note to A1 goToCell("A1"); @@ -1683,11 +1588,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteAsLink) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131442) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertArrayToCell(*pModelObj, "A1:A5", u"={6;4;2;5;3}"); + insertArrayToCell("A1:A5", u"={6;4;2;5;3}"); CPPUNIT_ASSERT_EQUAL(OUString("6"), pDoc->GetString(ScAddress(0, 0, 0))); CPPUNIT_ASSERT_EQUAL(OUString("4"), pDoc->GetString(ScAddress(0, 1, 0))); @@ -1717,23 +1621,23 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131442) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117458) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocShell* pDocSh = getScDocShell(); ScModule* pMod = SC_MOD(); ScInputOptions aInputOption = pMod->GetInputOptions(); sal_uInt16 bOldStatus = aInputOption.GetMoveDir(); - lcl_AssertCurrentCursorPosition(*pDoc, u"A1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A1"); aInputOption.SetMoveDir(DIR_BOTTOM); pMod->SetInputOptions(aInputOption); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"A2"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A2"); aInputOption.SetMoveDir(DIR_TOP); pMod->SetInputOptions(aInputOption); @@ -1741,7 +1645,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117458) pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"A1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A1"); aInputOption.SetMoveDir(DIR_RIGHT); pMod->SetInputOptions(aInputOption); @@ -1749,7 +1653,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117458) pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"B1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"B1"); aInputOption.SetMoveDir(DIR_LEFT); pMod->SetInputOptions(aInputOption); @@ -1757,7 +1661,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117458) pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"A1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A1"); // Restore previous status aInputOption.SetMoveDir(bOldStatus); @@ -1766,9 +1670,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117458) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf90694) { - ScModelObj* pModelObj = createDoc("tdf90694.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf90694.ods"); + ScDocument* pDoc = getScDoc(); // Select row 30 to 60 goToCell("30:60"); @@ -1787,9 +1690,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf90694) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138710) { - ScModelObj* pModelObj = createDoc("tdf138710.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf138710.ods"); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); @@ -1813,9 +1715,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138710) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf128914) { - ScModelObj* pModelObj = createDoc("tdf128914.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf128914.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(6.0, pDoc->GetValue(ScAddress(3, 1, 0))); @@ -1853,9 +1754,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf128914) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf108654) { - ScModelObj* pModelObj = createDoc("tdf108654.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf108654.ods"); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); @@ -1883,13 +1783,12 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf108654) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf150219) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); insertNewSheet(*pDoc); - insertStringToCell(*pModelObj, "A1", u"=$Sheet1.A1"); + insertStringToCell("A1", u"=$Sheet1.A1"); goToCell("A1"); CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(0, 0, 1))); @@ -1904,9 +1803,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf150219) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf150499) { - ScModelObj* pModelObj = createDoc("tdf150499.xls"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf150499.xls"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(static_cast(2), pDoc->GetTableCount()); @@ -1921,9 +1819,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf150499) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf133326) { - ScModelObj* pModelObj = createDoc("tdf133326.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf133326.ods"); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); @@ -1970,10 +1867,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf133326) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126685) { - ScModelObj* pModelObj = createDoc("tdf126685.ods"); + createScDoc("tdf126685.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + ScDocument* pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); // test should crash here without the fix Scheduler::ProcessEventsToIdle(); @@ -1988,8 +1884,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126685) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119793) { - ScModelObj* pModelObj = createDoc("tdf119793.ods"); + createScDoc("tdf119793.ods"); + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); uno::Reference xPage(pModelObj->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW); uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); @@ -1998,7 +1895,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119793) CPPUNIT_ASSERT_EQUAL(static_cast(1381), xShape->getPosition().Y); // Move the shape to the right - lcl_SelectObjectByName(u"Shape 1"); + lcl_SelectObjectByName(*getViewShell(), u"Shape 1"); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT); Scheduler::ProcessEventsToIdle(); @@ -2007,7 +1904,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119793) CPPUNIT_ASSERT_EQUAL(static_cast(1381), xShape->getPosition().Y); // Type into the shape - typeString(*pModelObj, u"x"); + typeString(u"x"); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_ESCAPE); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_ESCAPE); Scheduler::ProcessEventsToIdle(); @@ -2039,37 +1936,36 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131455) { // Note that tdf#131455 and tdf#126904 were actually incorrect, // but keep the test with a fixed version of the document. - ScModelObj* pModelObj = createDoc("tdf131455-fixed.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf131455-fixed.ods"); + ScDocShell* pDocSh = getScDocShell(); - lcl_AssertCurrentCursorPosition(*pDoc, u"A5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A5"); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"B5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"B5"); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"E5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"E5"); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"F5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"F5"); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"I5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"I5"); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"J5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"J5"); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"M5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"M5"); //Cursor can't move forward to the right for (size_t i = 0; i < 5; ++i) { dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"N5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"N5"); } - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), ScDocShell::GetViewData()->GetTabNo()); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getViewShell()->GetViewData().GetTabNo()); dispatchCommand(mxComponent, ".uno:JumpToNextTable", {}); - CPPUNIT_ASSERT_EQUAL(sal_Int16(1), ScDocShell::GetViewData()->GetTabNo()); - lcl_AssertCurrentCursorPosition(*pDoc, u"A4"); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getViewShell()->GetViewData().GetTabNo()); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A4"); // Go to row 9 for (size_t i = 0; i < 6; ++i) @@ -2077,35 +1973,34 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131455) dispatchCommand(mxComponent, ".uno:GoDown", {}); } - lcl_AssertCurrentCursorPosition(*pDoc, u"A10"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A10"); dispatchCommand(mxComponent, ".uno:SelectRow", {}); dispatchCommand(mxComponent, ".uno:DeleteRows", {}); dispatchCommand(mxComponent, ".uno:JumpToPrevTable", {}); - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), ScDocShell::GetViewData()->GetTabNo()); - lcl_AssertCurrentCursorPosition(*pDoc, u"N5"); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getViewShell()->GetViewData().GetTabNo()); + lcl_AssertCurrentCursorPosition(*pDocSh, u"N5"); //Cursor can't move forward to the right for (size_t i = 0; i < 5; ++i) { dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"N5"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"N5"); } } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124818) { - ScModelObj* pModelObj = createDoc("tdf124818.xls"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf124818.xls"); + ScDocument* pDoc = getScDoc(); - CPPUNIT_ASSERT_EQUAL(sal_Int16(2), ScDocShell::GetViewData()->GetTabNo()); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2), getViewShell()->GetViewData().GetTabNo()); dispatchCommand(mxComponent, ".uno:JumpToPrevTable", {}); - CPPUNIT_ASSERT_EQUAL(sal_Int16(1), ScDocShell::GetViewData()->GetTabNo()); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getViewShell()->GetViewData().GetTabNo()); ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); SdrPage* pPage = pDrawLayer->GetPage(1); @@ -2127,15 +2022,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124818) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124816) { - ScModelObj* pModelObj = createDoc("tdf124816.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf124816.xlsx"); + ScDocShell* pDocSh = getScDocShell(); + ScDocument* pDoc = getScDoc(); // The actual result is completely unrelated to this test and behaviour of // OFFSET() was changed as of tdf#85551 and here result of that test // document is now Err:502 instead of 0. const OUString aExpectedResult("Err:502"); - lcl_AssertCurrentCursorPosition(*pDoc, u"D10"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"D10"); CPPUNIT_ASSERT_EQUAL(aExpectedResult, pDoc->GetString(ScAddress(3, 9, 0))); //Without the fix, it would crash @@ -2147,11 +2042,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124816) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124815) { - ScModelObj* pModelObj = createDoc("tdf124815.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf124815.ods"); - lcl_AssertCurrentCursorPosition(*pDoc, u"A1"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(OUString("Rakennukset"), pDoc->GetString(ScAddress(2, 0, 0))); //Without the fix, it would crash @@ -2163,9 +2056,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124815) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf142010) { - ScModelObj* pModelObj = createDoc("tdf142010.xls"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf142010.xls"); + ScDocument* pDoc = getScDoc(); goToCell("A1"); @@ -2192,9 +2084,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf142010) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf132431) { - ScModelObj* pModelObj = createDoc("tdf132431.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf132431.ods"); + ScDocument* pDoc = getScDoc(); OUString aFormula = pDoc->GetFormula(7, 219, 0); CPPUNIT_ASSERT_EQUAL(OUString("=SUMIFS($H$2:$H$198,B$2:B$198,G220)"), aFormula); @@ -2203,7 +2094,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf132431) // Without the fix in place, it would crash here with // uncaught exception of type std::exception (or derived). // - vector::_M_fill_insert - insertStringToCell(*pModelObj, "H220", u"=SUMIFS($H$2:$DB$198,B$2:B$198,G220)"); + insertStringToCell("H220", u"=SUMIFS($H$2:$DB$198,B$2:B$198,G220)"); aFormula = pDoc->GetFormula(7, 219, 0); CPPUNIT_ASSERT_EQUAL(OUString("=SUMIFS($H$2:$DB$198,B$2:B$198,G220)"), aFormula); @@ -2213,9 +2104,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf132431) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131073) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); for (SCCOLROW nColRow = 0; nColRow < 3; nColRow++) { @@ -2260,15 +2150,14 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131073) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf83901) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocShell* pDocSh = getScDocShell(); - lcl_AssertCurrentCursorPosition(*pDoc, u"A1"); - insertStringToCell(*pModelObj, "A2", u"=ROW(A3)"); + insertStringToCell("A2", u"=ROW(A3)"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(0, 1, 0))); - lcl_AssertCurrentCursorPosition(*pDoc, u"A3"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"A3"); dispatchCommand(mxComponent, ".uno:SelectRow", {}); dispatchCommand(mxComponent, ".uno:InsertRowsBefore", {}); @@ -2281,10 +2170,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf83901) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124822) { - ScModelObj* pModelObj = createDoc("tdf124822.xls"); + createScDoc("tdf124822.xls"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(OUString("X"), pDoc->GetString(ScAddress(0, 0, 2))); @@ -2303,25 +2191,18 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124822) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf118189) { - ScModelObj* pModelObj = createDoc("tdf118189.xlsx"); + createScDoc("tdf118189.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + ScDocument* pDoc = getScDoc(); // Select column A goToCell("A:A"); dispatchCommand(mxComponent, ".uno:Copy", {}); - mxComponent->dispose(); - mxComponent.clear(); - // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + pDoc = getScDoc(); dispatchCommand(mxComponent, ".uno:Paste", {}); @@ -2343,10 +2224,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf118189) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf118207) { - ScModelObj* pModelObj = createDoc("tdf118189.xlsx"); + createScDoc("tdf118189.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + ScDocument* pDoc = getScDoc(); // Disable replace cell warning ScModule* pMod = SC_MOD(); @@ -2407,19 +2287,17 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf118207) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf148669) { // Without the fix in place, this test would have failed with an assert - ScModelObj* pModelObj = createDoc("tdf148669.xlsx"); + createScDoc("tdf148669.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_MESSAGE("There should be a note", pDoc->HasNote(ScAddress(701, 0, 0))); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124778) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); // Add a new comment uno::Sequence aArgs @@ -2443,11 +2321,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124778) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138428) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); - - lcl_AssertCurrentCursorPosition(*pDoc, u"A1"); + createScDoc(); + ScDocShell* pDocSh = getScDocShell(); // Add a new comment uno::Sequence aArgs @@ -2455,13 +2330,14 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138428) dispatchCommand(mxComponent, ".uno:InsertAnnotation", aArgs); Scheduler::ProcessEventsToIdle(); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_MESSAGE("There should be a note on A1", pDoc->HasNote(ScAddress(0, 0, 0))); CPPUNIT_ASSERT_MESSAGE("There shouldn't be a note on B1", !pDoc->HasNote(ScAddress(1, 0, 0))); dispatchCommand(mxComponent, ".uno:Copy", {}); dispatchCommand(mxComponent, ".uno:GoRight", {}); - lcl_AssertCurrentCursorPosition(*pDoc, u"B1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"B1"); dispatchCommand(mxComponent, ".uno:Paste", {}); @@ -2496,9 +2372,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138428) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf136113) { - ScModelObj* pModelObj = createDoc("tdf136113.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf136113.xlsx"); + ScDocument* pDoc = getScDoc(); ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); SdrPage* pPage = pDrawLayer->GetPage(0); @@ -2507,9 +2382,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf136113) CPPUNIT_ASSERT_EQUAL(tools::Long(18142), pObj->GetSnapRect().Left()); CPPUNIT_ASSERT_EQUAL(tools::Long(1709), pObj->GetSnapRect().Top()); - lcl_SelectObjectByName(u"Arrow"); + lcl_SelectObjectByName(*getViewShell(), u"Arrow"); // Move the shape up + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::UP); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::UP); Scheduler::ProcessEventsToIdle(); @@ -2518,30 +2394,23 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf136113) CPPUNIT_ASSERT_EQUAL(tools::Long(1609), pObj->GetSnapRect().Top()); // Without the fix in place, this test would have failed here - ScDocShell* pDocSh = ScDocShell::GetViewData()->GetDocShell(); + ScDocShell* pDocSh = getScDocShell(); CPPUNIT_ASSERT(pDocSh->IsModified()); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf130614) { - ScModelObj* pModelObj = createDoc("tdf130614.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf130614.ods"); + ScDocument* pDoc = getScDoc(); - lcl_SelectObjectByName(u"Object 1"); + lcl_SelectObjectByName(*getViewShell(), u"Object 1"); dispatchCommand(mxComponent, ".uno:Copy", {}); Scheduler::ProcessEventsToIdle(); - mxComponent->dispose(); - mxComponent.clear(); - // Open a new document - mxComponent = loadFromDesktop("private:factory/scalc"); - pModelObj = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pModelObj); - pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + pDoc = getScDoc(); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Paste", {}); @@ -2554,9 +2423,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf130614) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf112735) { - ScModelObj* pModelObj = createDoc("tdf112735.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf112735.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(OUString("(empty)"), pDoc->GetString(ScAddress(1, 0, 0))); @@ -2572,9 +2440,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf112735) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf112884) { - ScModelObj* pModelObj = createDoc("tdf112884.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf112884.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(OUString("0.5"), pDoc->GetString(ScAddress(6, 2, 0))); CPPUNIT_ASSERT_EQUAL(OUString("0.666666666666667"), pDoc->GetString(ScAddress(6, 3, 0))); @@ -2596,9 +2463,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf112884) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf133342) { - ScModelObj* pModelObj = createDoc("tdf133342.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf133342.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(OUString("12,35 %"), pDoc->GetString(ScAddress(0, 0, 0))); //Add decimals @@ -2620,12 +2486,11 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf133342) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf71339) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A2", u"1"); - insertStringToCell(*pModelObj, "A3", u"1"); + insertStringToCell("A2", u"1"); + insertStringToCell("A3", u"1"); goToCell("A1:A3"); @@ -2643,19 +2508,19 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf71339) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf116421) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"1"); - insertStringToCell(*pModelObj, "A2", u"1"); - insertStringToCell(*pModelObj, "A3", u"1"); + insertStringToCell("A1", u"1"); + insertStringToCell("A2", u"1"); + insertStringToCell("A3", u"1"); goToCell("A4"); dispatchCommand(mxComponent, ".uno:AutoSum", {}); // Use RETURN key to exit autosum edit view + ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); @@ -2672,16 +2537,14 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf116421) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf86305) { - ScModelObj* pModelObj = createDoc("tdf86305.ods"); - CPPUNIT_ASSERT(pModelObj); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf86305.ods"); + ScDocument* pDoc = getScDoc(); OUString aFormula = pDoc->GetFormula(1, 6, 0); CPPUNIT_ASSERT_EQUAL(OUString("{=IF(SUM(B2:B4) > 0, SUM(B2:B4*D2:D4/C2:C4), 0)}"), aFormula); CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(ScAddress(1, 6, 0))); - insertStringToCell(*pModelObj, "B3", u"50"); + insertStringToCell("B3", u"50"); CPPUNIT_ASSERT_EQUAL(50.0, pDoc->GetValue(ScAddress(1, 2, 0))); aFormula = pDoc->GetFormula(1, 6, 0); @@ -2695,10 +2558,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf86305) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf81351) { - ScModelObj* pModelObj = createDoc("tdf81351.ods"); - CPPUNIT_ASSERT(pModelObj); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf81351.ods"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(OUString(".uno:Paste"), pDoc->GetString(ScAddress(0, 1, 0))); CPPUNIT_ASSERT_EQUAL(OUString(".uno:Bold"), pDoc->GetString(ScAddress(0, 2, 0))); @@ -2765,14 +2626,13 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf81351) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf123202) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, u"A1", u"1"); - insertStringToCell(*pModelObj, u"A2", u"2"); - insertStringToCell(*pModelObj, u"A3", u"3"); - insertStringToCell(*pModelObj, u"A4", u"4"); + insertStringToCell(u"A1", u"1"); + insertStringToCell(u"A2", u"2"); + insertStringToCell(u"A3", u"3"); + insertStringToCell(u"A4", u"4"); goToCell("A3"); @@ -2804,10 +2664,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf123202) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf134675) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); - insertStringToCell(*pModelObj, "A1", u"A"); + createScDoc(); + ScDocument* pDoc = getScDoc(); + insertStringToCell("A1", u"A"); // Select column A goToCell("A:A"); @@ -2832,13 +2691,12 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf134675) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf116215) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); - insertStringToCell(*pModelObj, "A1", u"1"); - insertStringToCell(*pModelObj, "A2", u"1"); - insertStringToCell(*pModelObj, "B1", u"1"); - insertStringToCell(*pModelObj, "B2", u"1"); + createScDoc(); + ScDocument* pDoc = getScDoc(); + insertStringToCell("A1", u"1"); + insertStringToCell("A2", u"1"); + insertStringToCell("B1", u"1"); + insertStringToCell("B2", u"1"); goToCell("A1:C3"); dispatchCommand(mxComponent, ".uno:AutoSum", {}); @@ -2864,21 +2722,18 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf116215) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf99913) { - ScModelObj* pModelObj = createDoc("tdf99913.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf99913.xlsx"); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT(pDoc->RowFiltered(2, 0)); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126540_GridToggleModifiesTheDocument) { - ScModelObj* pModelObj = createDoc("tdf99913.xlsx"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf99913.xlsx"); // Toggling the grid of a sheet, must set the document modified state - ScDocShell* pDocSh = ScDocShell::GetViewData()->GetDocShell(); + ScDocShell* pDocSh = getScDocShell(); CPPUNIT_ASSERT(!pDocSh->IsModified()); dispatchCommand(mxComponent, ".uno:ToggleSheetGrid", {}); CPPUNIT_ASSERT(pDocSh->IsModified()); @@ -2886,9 +2741,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126540_GridToggleModifiesTheDocument) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf118983) { - ScModelObj* pModelObj = createDoc("tdf118983.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf118983.ods"); + ScDocument* pDoc = getScDoc(); css::uno::Reference xGlobalSheetSettings = css::sheet::GlobalSheetSettings::create(::comphelper::getProcessComponentContext()); @@ -2915,11 +2769,10 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf118983) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf107952) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocShell* pDocSh = getScDocShell(); - insertStringToCell(*pModelObj, "B1", u"=SUM(A1:A2)"); + insertStringToCell("B1", u"=SUM(A1:A2)"); goToCell("D10"); @@ -2930,27 +2783,26 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf107952) // - Expected: 1 // - Actual : 3 // - Incorrect Column in position B1 - lcl_AssertCurrentCursorPosition(*pDoc, u"B1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"B1"); goToCell("D10"); dispatchCommand(mxComponent, ".uno:Redo", {}); Scheduler::ProcessEventsToIdle(); - lcl_AssertCurrentCursorPosition(*pDoc, u"B1"); + lcl_AssertCurrentCursorPosition(*pDocSh, u"B1"); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf150766) { - ScModelObj* pModelObj = createDoc("tdf150766.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf150766.ods"); + ScDocument* pDoc = getScDoc(); goToCell("A3:C6"); dispatchCommand(mxComponent, ".uno:SortDescending", {}); - insertStringToCell(*pModelObj, "B3", u"10"); + insertStringToCell("B3", u"10"); CPPUNIT_ASSERT_EQUAL(12.0, pDoc->GetValue(ScAddress(2, 2, 0))); CPPUNIT_ASSERT_EQUAL(13.0, pDoc->GetValue(ScAddress(2, 3, 0))); @@ -2967,9 +2819,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf150766) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144022) { - ScModelObj* pModelObj = createDoc("tdf144022.ods"); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc("tdf144022.ods"); + ScDocument* pDoc = getScDoc(); goToCell("A5:B79"); @@ -2991,12 +2842,11 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144022) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf99386) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "B1", u"This"); - insertStringToCell(*pModelObj, "B2", u"=B1"); + insertStringToCell("B1", u"This"); + insertStringToCell("B2", u"=B1"); goToCell("A1:B1"); @@ -3018,52 +2868,50 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf99386) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf149378) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"=MINVERSE(A1:C3)"); + insertStringToCell("A1", u"=MINVERSE(A1:C3)"); // Without the fix in place, this test would have failed with // - Expected: {=MINVERSE(A1:C3)} // - Actual : =MINVERSE(A1:C3) CPPUNIT_ASSERT_EQUAL(OUString("{=MINVERSE(A1:C3)}"), pDoc->GetFormula(0, 0, 0)); - insertStringToCell(*pModelObj, "B1", u"={1;2}"); + insertStringToCell("B1", u"={1;2}"); CPPUNIT_ASSERT_EQUAL(OUString("{={1;2}}"), pDoc->GetFormula(1, 0, 0)); - insertStringToCell(*pModelObj, "C1", u"={1;2}+3"); + insertStringToCell("C1", u"={1;2}+3"); CPPUNIT_ASSERT_EQUAL(OUString("{={1;2}+3}"), pDoc->GetFormula(2, 0, 0)); - insertStringToCell(*pModelObj, "D1", u"={1;2}+{3;4}"); + insertStringToCell("D1", u"={1;2}+{3;4}"); CPPUNIT_ASSERT_EQUAL(OUString("{={1;2}+{3;4}}"), pDoc->GetFormula(3, 0, 0)); - insertStringToCell(*pModelObj, "E1", u"={1;2}+A1"); + insertStringToCell("E1", u"={1;2}+A1"); CPPUNIT_ASSERT_EQUAL(OUString("{={1;2}+A1}"), pDoc->GetFormula(4, 0, 0)); - insertStringToCell(*pModelObj, "F1", u"={1;2}+A1:A2"); + insertStringToCell("F1", u"={1;2}+A1:A2"); CPPUNIT_ASSERT_EQUAL(OUString("={1;2}+A1:A2"), pDoc->GetFormula(5, 0, 0)); - insertStringToCell(*pModelObj, "G1", u"=SUM(MUNIT(3))"); + insertStringToCell("G1", u"=SUM(MUNIT(3))"); CPPUNIT_ASSERT_EQUAL(OUString("=SUM(MUNIT(3))"), pDoc->GetFormula(6, 0, 0)); - insertStringToCell(*pModelObj, "H1", u"=SUM({1;2})"); + insertStringToCell("H1", u"=SUM({1;2})"); CPPUNIT_ASSERT_EQUAL(OUString("=SUM({1;2})"), pDoc->GetFormula(7, 0, 0)); - insertStringToCell(*pModelObj, "I1", u"=ABS({-1;-2})"); + insertStringToCell("I1", u"=ABS({-1;-2})"); CPPUNIT_ASSERT_EQUAL(OUString("{=ABS({-1;-2})}"), pDoc->GetFormula(8, 0, 0)); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126926) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); - insertStringToCell(*pModelObj, "A1", u"1"); - insertStringToCell(*pModelObj, "A2", u"2"); - insertStringToCell(*pModelObj, "B1", u"3"); - insertStringToCell(*pModelObj, "B2", u"4"); + insertStringToCell("A1", u"1"); + insertStringToCell("A2", u"2"); + insertStringToCell("B1", u"3"); + insertStringToCell("B2", u"4"); ScDBData* pDBData = new ScDBData("testDB", 0, 0, 0, 1, 1); bool bInserted @@ -3080,9 +2928,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126926) CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testUnallocatedColumnsAttributes) { - ScModelObj* pModelObj = createDoc(); - ScDocument* pDoc = pModelObj->GetDocument(); - CPPUNIT_ASSERT(pDoc); + createScDoc(); + ScDocument* pDoc = getScDoc(); CPPUNIT_ASSERT_EQUAL(INITIALCOLCOUNT, pDoc->GetAllocatedColumnsCount(0)); diff --git a/test/source/unoapi_test.cxx b/test/source/unoapi_test.cxx index 12e0aab043b5..a1c0580cfd61 100644 --- a/test/source/unoapi_test.cxx +++ b/test/source/unoapi_test.cxx @@ -190,14 +190,6 @@ void UnoApiTest::save(const OUString& rFilter, const char* pPassword) } } -void UnoApiTest::saveAndClose(const OUString& rFilter) -{ - save(rFilter, nullptr); - - mxComponent->dispose(); - mxComponent.clear(); -} - void UnoApiTest::saveAndReload(const OUString& rFilter, const char* pPassword) { save(rFilter, pPassword);