/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. */ #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; class ScUiCalcTest : public test::BootstrapFixture, public unotest::MacrosTest { public: virtual void setUp() override; virtual void tearDown() override; ScModelObj* createDoc(const char* pName); void checkCurrentCell(SCCOL nCol, SCROW nRow); protected: uno::Reference mxComponent; }; void ScUiCalcTest::setUp() { test::BootstrapFixture::setUp(); mxDesktop.set(frame::Desktop::create(mxComponentContext)); } void ScUiCalcTest::tearDown() { if (mxComponent.is()) mxComponent->dispose(); test::BootstrapFixture::tearDown(); } void ScUiCalcTest::checkCurrentCell(SCCOL nCol, SCROW nRow) { CPPUNIT_ASSERT_EQUAL(sal_Int16(nCol), ScDocShell::GetViewData()->GetCurX()); CPPUNIT_ASSERT_EQUAL(sal_Int32(nRow), ScDocShell::GetViewData()->GetCurY()); } char const DATA_DIRECTORY[] = "/sc/qa/unit/uicalc/data/"; ScModelObj* ScUiCalcTest::createDoc(const char* pName) { if (mxComponent.is()) mxComponent->dispose(); mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + OUString::createFromAscii(pName), "com.sun.star.sheet.SpreadsheetDocument"); ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT(pModelObj); return pModelObj; } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf122232) { ScModelObj* pModelObj = createDoc("tdf122232.ods"); ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); //Start with from C6. Press tabulator to reach G6. checkCurrentCell(2, 5); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); Scheduler::ProcessEventsToIdle(); checkCurrentCell(6, 5); //without the fix, cursor would jump to C29 instead of C7. pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); checkCurrentCell(2, 6); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126904) { ScModelObj* pModelObj = createDoc("tdf126904.ods"); ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); checkCurrentCell(0, 4); dispatchCommand(mxComponent, ".uno:GoRight", {}); checkCurrentCell(1, 4); dispatchCommand(mxComponent, ".uno:GoRight", {}); checkCurrentCell(4, 4); dispatchCommand(mxComponent, ".uno:GoRight", {}); checkCurrentCell(5, 4); dispatchCommand(mxComponent, ".uno:GoRight", {}); checkCurrentCell(8, 4); dispatchCommand(mxComponent, ".uno:GoRight", {}); checkCurrentCell(9, 4); dispatchCommand(mxComponent, ".uno:GoRight", {}); checkCurrentCell(12, 4); //Cursor can't move forward to the right for (size_t i = 0; i < 5; ++i) { dispatchCommand(mxComponent, ".uno:GoRight", {}); checkCurrentCell(13, 4); } } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124816) { ScModelObj* pModelObj = createDoc("tdf124816.xlsx"); ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); // 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"); checkCurrentCell(3, 9); CPPUNIT_ASSERT_EQUAL(aExpectedResult, pDoc->GetString(ScAddress(3, 9, 0))); //Without the fix, it would crash dispatchCommand(mxComponent, ".uno:InsertRowsBefore", {}); CPPUNIT_ASSERT_EQUAL(OUString(""), pDoc->GetString(ScAddress(3, 9, 0))); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(aExpectedResult, pDoc->GetString(ScAddress(3, 9, 0))); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf124815) { ScModelObj* pModelObj = createDoc("tdf124815.ods"); ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); checkCurrentCell(0, 0); CPPUNIT_ASSERT_EQUAL(OUString("Rakennukset"), pDoc->GetString(ScAddress(2, 0, 0))); //Without the fix, it would crash dispatchCommand(mxComponent, ".uno:InsertColumnsBefore", {}); CPPUNIT_ASSERT_EQUAL(OUString("Rakennukset"), pDoc->GetString(ScAddress(3, 0, 0))); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(OUString("Rakennukset"), pDoc->GetString(ScAddress(2, 0, 0))); } CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf83901) { mxComponent = loadFromDesktop("private:factory/scalc"); ScModelObj* pModelObj = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT(pModelObj); ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); checkCurrentCell(0, 0); pDoc->SetString(ScAddress(0, 1, 0), "=ROW(A3)"); CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(0, 1, 0))); dispatchCommand(mxComponent, ".uno:GoDown", {}); dispatchCommand(mxComponent, ".uno:GoDown", {}); checkCurrentCell(0, 2); dispatchCommand(mxComponent, ".uno:SelectRow", {}); dispatchCommand(mxComponent, ".uno:InsertRowsBefore", {}); //Without the fix, it would be 3.0 CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(0, 1, 0))); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(0, 1, 0))); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */