desktop/qa/data/sheets.ods |binary desktop/qa/desktop_lib/test_desktop_lib.cxx | 34 ++++++++++++++++++++++++++++ sc/source/ui/view/tabvwshf.cxx | 20 +++++++++++++--- 3 files changed, 50 insertions(+), 4 deletions(-)
New commits: commit c42b529e8508d355e8d87b5b90f76f3b32ba36d5 Author: Jan Holesovsky <[email protected]> Date: Thu Jan 21 00:42:59 2016 +0100 sc lok: Implement unit test for .uno:{Insert,Name,Remove} for sheets. And fix indexing when at that - the inserting is 1-based, so let's be consistent in the .uno:Name and .uno:Remove too. Change-Id: Ib854e81551ae0a39d3ba7c68512e81ea227e9eb1 diff --git a/desktop/qa/data/sheets.ods b/desktop/qa/data/sheets.ods new file mode 100644 index 0000000..42226b2 Binary files /dev/null and b/desktop/qa/data/sheets.ods differ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 5e7a14d..0d39f93 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -86,6 +86,7 @@ public: void testRowColumnHeaders(); void testCommandResult(); void testWriterComments(); + void testSheetOperations(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testGetStyles); @@ -103,6 +104,7 @@ public: CPPUNIT_TEST(testRowColumnHeaders); CPPUNIT_TEST(testCommandResult); CPPUNIT_TEST(testWriterComments); + CPPUNIT_TEST(testSheetOperations); CPPUNIT_TEST_SUITE_END(); uno::Reference<lang::XComponent> mxComponent; @@ -587,6 +589,38 @@ void DesktopLOKTest::testWriterComments() comphelper::LibreOfficeKit::setActive(false); } +void DesktopLOKTest::testSheetOperations() +{ + comphelper::LibreOfficeKit::setActive(true); + LibLODocument_Impl* pDocument = loadDoc("sheets.ods"); + + // insert the last sheet + pDocument->pClass->postUnoCommand(pDocument, ".uno:Insert", + "{ \"Name\": { \"type\": \"string\", \"value\": \"LastSheet\" }, \"Index\": { \"type\": \"long\", \"value\": 0 } }", false); + + // insert the first sheet + pDocument->pClass->postUnoCommand(pDocument, ".uno:Insert", + "{ \"Name\": { \"type\": \"string\", \"value\": \"FirstSheet\" }, \"Index\": { \"type\": \"long\", \"value\": 1 } }", false); + + // rename the \"Sheet1\" (2nd now) to \"Renamed\" + pDocument->pClass->postUnoCommand(pDocument, ".uno:Name", + "{ \"Name\": { \"type\": \"string\", \"value\": \"Renamed\" }, \"Index\": { \"type\": \"long\", \"value\": 2 } }", false); + + // delete the \"Sheet2\" (3rd) + pDocument->pClass->postUnoCommand(pDocument, ".uno:Remove", + "{ \"Index\": { \"type\": \"long\", \"value\": 3 } }", false); + + CPPUNIT_ASSERT_EQUAL(pDocument->pClass->getParts(pDocument), 6); + + std::vector<OString> pExpected = { "FirstSheet", "Renamed", "Sheet3", "Sheet4", "Sheet5", "LastSheet" }; + for (int i = 0; i < 6; ++i) + { + CPPUNIT_ASSERT_EQUAL(pExpected[i], OString(pDocument->pClass->getPartName(pDocument, i))); + } + + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx index 53fd7c8..7502d21 100644 --- a/sc/source/ui/view/tabvwshf.cxx +++ b/sc/source/ui/view/tabvwshf.cxx @@ -333,8 +333,14 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) OUString aName; if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) ) + { nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + // inserting is 1-based, let's be consistent + if (nTabNr > 0) + --nTabNr; + } + if( pReqArgs->HasItem( nSlot, &pItem ) ) aName = static_cast<const SfxStringItem*>(pItem)->GetValue(); @@ -571,12 +577,18 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) bool bHasIndex = (pReqArgs != nullptr); // allow removing via the Index/FID_DELETE_TABLE parameter - SCTAB nIndexTab = nCurrentTab; + SCTAB nTabNr = nCurrentTab; if (bHasIndex) { const SfxPoolItem* pItem; if (pReqArgs->HasItem(FID_DELETE_TABLE, &pItem)) - nIndexTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + { + nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + + // inserting is 1-based, let's be consistent + if (nTabNr > 0) + --nTabNr; + } } bool bDoIt = bHasIndex; @@ -598,8 +610,8 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) if (bHasIndex) { // sheet no. provided by the parameter - TheTabs.push_back(nIndexTab); - if (nNewTab > nIndexTab && nNewTab > 0) + TheTabs.push_back(nTabNr); + if (nNewTab > nTabNr && nNewTab > 0) --nNewTab; } else _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
