diff options
Diffstat (limited to 'sc/qa/extras')
203 files changed, 15432 insertions, 0 deletions
diff --git a/sc/qa/extras/accessibility/basics.cxx b/sc/qa/extras/accessibility/basics.cxx new file mode 100644 index 0000000000..06b6134ce1 --- /dev/null +++ b/sc/qa/extras/accessibility/basics.cxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <com/sun/star/accessibility/XAccessibleTable.hpp> +#include <com/sun/star/accessibility/XAccessibleText.hpp> +#include <com/sun/star/accessibility/XAccessibleValue.hpp> +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> + +#include <com/sun/star/awt/Key.hpp> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <vcl/scheduler.hxx> + +#include <tools/date.hxx> +#include <tools/time.hxx> + +#include <test/a11y/accessibletestbase.hxx> +#include <test/a11y/AccessibilityTools.hxx> + +using namespace css; + +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestCalcMenu) +{ + load(u"private:factory/scalc"_ustr); + + const Date beforeDate(Date::SYSTEM); + const double beforeTime = tools::Time(tools::Time::SYSTEM).GetTimeInDays(); + + // in cell A1, insert the date + CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Date")); + // move down to A2 + documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, css::awt::Key::DOWN); + // in cell A2, insert the time + CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Time")); + + uno::Reference<accessibility::XAccessibleTable> sheet( + getDocumentAccessibleContext()->getAccessibleChild(0)->getAccessibleContext(), // sheet 1 + uno::UNO_QUERY_THROW); + + /* As it's very tricky to check the dates and times are correct in text format (imagine running + * on 1970-12-31 23:59:59.99, it's gonna shift *everything* in a 100th of a second) because + * clock can have changed between generating the two values to compare. So instead we just + * check the text is not empty, and the underlying value (representing the date or time) is + * between the time it was before and after the call. */ + + // cell A1 contains a date + auto xCell = sheet->getAccessibleCellAt(0, 0)->getAccessibleContext(); + uno::Reference<accessibility::XAccessibleText> xText(xCell, uno::UNO_QUERY_THROW); + std::cout << "A1 (text): " << xText->getText() << std::endl; + CPPUNIT_ASSERT(!xText->getText().isEmpty()); + uno::Reference<accessibility::XAccessibleValue> xValue(xCell, uno::UNO_QUERY_THROW); + double value; + CPPUNIT_ASSERT(xValue->getCurrentValue() >>= value); + std::cout << "A1 (value): " << value << std::endl; + uno::Reference<util::XNumberFormatsSupplier> xSupplier(mxDocument, uno::UNO_QUERY_THROW); + util::Date nullDate; + CPPUNIT_ASSERT(xSupplier->getNumberFormatSettings()->getPropertyValue("NullDate") >>= nullDate); + const Date afterDate(Date::SYSTEM); + CPPUNIT_ASSERT_GREATEREQUAL(double(beforeDate - nullDate), value); + CPPUNIT_ASSERT_LESSEQUAL(double(afterDate - nullDate), value); + + // cell A2 contains time, no date, so we have to be careful passing midnight + xCell = sheet->getAccessibleCellAt(1, 0)->getAccessibleContext(); + xText.set(xCell, uno::UNO_QUERY_THROW); + std::cout << "A2 (text): " << xText->getText() << std::endl; + CPPUNIT_ASSERT(!xText->getText().isEmpty()); + xValue.set(xCell, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xValue->getCurrentValue() >>= value); + std::cout << "A2 (value): " << value << std::endl; + double afterTime = tools::Time(tools::Time::SYSTEM).GetTimeInDays(); + // in case day changed -- assuming no more than 24 hours passed + if (afterTime < beforeTime) + { + afterTime += 1; + if (value < beforeTime) + value += 1; + } + CPPUNIT_ASSERT_GREATEREQUAL(beforeTime, value); + CPPUNIT_ASSERT_LESSEQUAL(afterTime, value); +} + +// test that converting cell row/col number <-> child index works +// for the case where 32-bit a11y child indices don't suffice (tdf#150683) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, Test64BitChildIndices) +{ + load(u"private:factory/scalc"_ustr); + + const sal_Int32 nRow = 1048575; + const sal_Int32 nCol = 16383; + + uno::Reference<accessibility::XAccessibleTable> xTable( + getDocumentAccessibleContext()->getAccessibleChild(0)->getAccessibleContext(), // sheet 1 + uno::UNO_QUERY_THROW); + + uno::Reference<accessibility::XAccessible> xCell = xTable->getAccessibleCellAt(nRow, nCol); + const sal_Int64 nChildIndex = xCell->getAccessibleContext()->getAccessibleIndexInParent(); + // child index should be positive for all cells except the first one (A1) + CPPUNIT_ASSERT_GREATER(sal_Int64(0), nChildIndex); + + // test that retrieving the row and column number via the child index again works + CPPUNIT_ASSERT_EQUAL(nRow, xTable->getAccessibleRow(nChildIndex)); + CPPUNIT_ASSERT_EQUAL(nCol, xTable->getAccessibleColumn(nChildIndex)); +} + +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, tdf157568) +{ + load(u"private:factory/scalc"_ustr); + + uno::Reference<accessibility::XAccessibleTable> sheet( + getDocumentAccessibleContext()->getAccessibleChild(0)->getAccessibleContext(), // sheet 1 + uno::UNO_QUERY_THROW); + + uno::Reference<accessibility::XAccessible> xCell = sheet->getAccessibleCellAt(1, 1); + CPPUNIT_ASSERT(xCell); + uno::WeakReference<accessibility::XAccessible> xCellWeak(xCell); + xCell.clear(); + // Verify that there are no reference cycles and that the ScAccessibleCell object dies after we + // are done with it. + uno::Reference<accessibility::XAccessible> xCell2(xCellWeak); + CPPUNIT_ASSERT(!xCell2.is()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/htmlexporttest.cxx b/sc/qa/extras/htmlexporttest.cxx new file mode 100644 index 0000000000..4e83e51139 --- /dev/null +++ b/sc/qa/extras/htmlexporttest.cxx @@ -0,0 +1,81 @@ +/* -*- 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 <sal/config.h> + +#include <string_view> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/XComponent.hpp> + +#include <test/htmltesttools.hxx> +#include <test/unoapixml_test.hxx> +#include <comphelper/processfactory.hxx> + +using namespace css::uno; +using namespace css::lang; +using namespace css::frame; +using namespace utl; + +class ScHTMLExportTest : public UnoApiXmlTest, public HtmlTestTools +{ +public: + ScHTMLExportTest() + : UnoApiXmlTest("/sc/qa/extras/testdocuments/") + {} + + void testHtmlSkipImage() + { + loadFromFile(u"BaseForHTMLExport.ods"); + save("HTML (StarCalc)"); + htmlDocUniquePtr pDoc = parseHtml(maTempFile); + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/html/body"_ostr, 1); + assertXPath(pDoc, "/html/body/table/tr/td/img"_ostr, 1); + + setFilterOptions("SkipImages"); + save("HTML (StarCalc)"); + + pDoc = parseHtml(maTempFile); + CPPUNIT_ASSERT (pDoc); + assertXPath(pDoc, "/html/body"_ostr, 1); + assertXPath(pDoc, "/html/body/table/tr/td/img"_ostr, 0); + } + + void testTdf155244() + { + loadFromFile(u"default-styles.ods"); + save("XHTML Calc File"); + + xmlDocUniquePtr pXmlDoc = parseXml(maTempFile); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/xhtml:html"_ostr, 1); + // the problem was that there were 2 CSS styles named "Default" + assertXPath(pXmlDoc, "/xhtml:html/xhtml:body/xhtml:table/xhtml:tr/xhtml:td"_ostr, "class"_ostr, "cell-Default"); + OUString const styles = getXPathContent(pXmlDoc, "/xhtml:html/xhtml:head/xhtml:style"_ostr); + CPPUNIT_ASSERT(styles.indexOf(".graphic-Default{ background-color:#729fcf;") != -1); + CPPUNIT_ASSERT(styles.indexOf(".cell-Default{ font-size:10pt; font-family:'Liberation Sans'; }") != -1); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), styles.indexOf(".Default")); + } + + CPPUNIT_TEST_SUITE(ScHTMLExportTest); + CPPUNIT_TEST(testHtmlSkipImage); + CPPUNIT_TEST(testTdf155244); + CPPUNIT_TEST_SUITE_END(); + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ScHTMLExportTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx new file mode 100644 index 0000000000..4494f3f65b --- /dev/null +++ b/sc/qa/extras/macros-test.cxx @@ -0,0 +1,907 @@ +/* -*- 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 <sal/config.h> +#include <helper/qahelper.hxx> +#include <sal/log.hxx> +#include <unotools/tempfile.hxx> +#include <svx/svdpage.hxx> +#include <unotools/mediadescriptor.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> + +#include <conditio.hxx> +#include <docsh.hxx> +#include <document.hxx> +#include <scitems.hxx> + +#include <com/sun/star/sheet/XFunctionAccess.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +#include <com/sun/star/script/XLibraryContainerPassword.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <editeng/brushitem.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +/* Implementation of Macros test */ + +class ScMacrosTest : public ScModelTestBase +{ +public: + ScMacrosTest(); +}; + +// I suppose you could say this test doesn't really belong here, OTOH +// we need a full document to run the test ( it related originally to an +// imported Excel VBA macro ) It's convenient and fast to unit test +// this the problem this way. Perhaps in the future there will be some sort +// of slowcheck tests ( requiring a full document environment in the scripting +// module, we could move the test there then ) - relates to fdo#67547 +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testMSP) +{ + createScDoc("MasterScriptProviderProblem.ods"); + + Any aRet = executeMacro("vnd.sun.Star.script:Standard.Module1.TestMSP?language=Basic&location=document"); + OUString sResult; + aRet >>= sResult; + + SAL_INFO("sc.qa", "Result is " << sResult ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("TestMSP ( for fdo#67547) failed", OUString("OK"), sResult); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testPasswordProtectedStarBasic) +{ + createScDoc("testTypePassword.ods"); + ScDocument* pDoc = getScDoc(); + + // User defined types + executeMacro("vnd.sun.Star.script:Standard.Module1.LoadAndExecuteTest?language=Basic&location=document"); + + OUString aValue = pDoc->GetString(0,0,0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("User defined types script did not change the value of Sheet1.A1", OUString("success"), aValue); + + // Big Module + + executeMacro("vnd.sun.Star.script:MyLibrary.BigModule.bigMethod?language=Basic&location=document"); + + aValue = pDoc->GetString(1,0,0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Big module script did not change the value of Sheet1.B1", OUString("success"), aValue); + + // far big method tdf#94617 + + executeMacro("vnd.sun.Star.script:MyLibrary.BigModule.farBigMethod?language=Basic&location=document"); + + aValue = pDoc->GetString(2,0,0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Far Method script did not change the value of Sheet1.C1", OUString("success"), aValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf142391) +{ + createScDoc("tdf142391.ods"); + ScDocument* pDoc = getScDoc(); + + // User defined types + executeMacro( + "vnd.sun.Star.script:Standard.Module1.LoadAndExecuteTest?language=Basic&location=document"); + OUString aValue = pDoc->GetString(0, 0, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("User defined types script did not change the value of Sheet1.A1", + OUString("success"), aValue); + + // Big Module + executeMacro( + "vnd.sun.Star.script:MyLibrary.BigModule.bigMethod?language=Basic&location=document"); + aValue = pDoc->GetString(1, 0, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Big module script did not change the value of Sheet1.B1", + OUString("success"), aValue); + + // tdf#142391 - method exceeds 0xffff offset for methods + executeMacro( + "vnd.sun.Star.script:MyLibrary.BigModule.farBigMethod?language=Basic&location=document"); + aValue = pDoc->GetString(2, 0, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Far Method script did not change the value of Sheet1.C1", + OUString("success"), aValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testStarBasic) +{ + createScDoc("StarBasic.ods"); + ScDocument* pDoc = getScDoc(); + + executeMacro("vnd.sun.Star.script:Standard.Module1.Macro1?language=Basic&location=document"); + double aValue = pDoc->GetValue(0,0,0); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("script did not change the value of Sheet1.A1",2.0, aValue, 0.00001); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testRowColumn) +{ + createScDoc("StarBasic.ods"); + ScDocument* pDoc = getScDoc(); + + executeMacro("vnd.sun.Star.script:Standard.Module1.Macro_RowHeight?language=Basic&location=document"); + + sal_uInt16 nHeight = o3tl::convert(pDoc->GetRowHeight(0, 0), o3tl::Length::twip, o3tl::Length::mm100); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2000), nHeight); + + executeMacro("vnd.sun.Star.script:Standard.Module1.Macro_ColumnWidth?language=Basic&location=document"); + sal_uInt16 nWidth = o3tl::convert(pDoc->GetColWidth(0, 0), o3tl::Length::twip, o3tl::Length::mm100); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4001), nWidth); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf146742) +{ + createScDoc("tdf146742.ods"); + + // Export to ODS and reload the file + saveAndReload("calc8"); + ScDocument* pDoc = getScDoc(); + + CPPUNIT_ASSERT_EQUAL(OUString("1"), pDoc->GetString(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(OUString("2"), pDoc->GetString(ScAddress(0,1,0))); + + CPPUNIT_ASSERT_EQUAL(OUString("TRUE"), pDoc->GetString(ScAddress(1,0,0))); + // Without the fix in place, this test would have failed with + // - Expected: FALSE + // - Actual : TRUE + CPPUNIT_ASSERT_EQUAL(OUString("FALSE"), pDoc->GetString(ScAddress(1,1,0))); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testMacroButtonFormControlXlsxExport) +{ + // Given a button form control with an associated macro: + createScDoc("macro-button-form-control.xlsm"); + + // When exporting to XLSM: + save("Calc MS Excel 2007 VBA XML"); + + // Then make sure that the macro is associated with the control: + xmlDocUniquePtr pSheetDoc = parseExport("xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheetDoc); + // Without the fix in place, this test would have failed with: + // - XPath '//x:controlPr' no attribute 'macro' exist + // i.e. the macro was lost on export. + assertXPath(pSheetDoc, "//x:controlPr"_ostr, "macro"_ostr, "Module1.Button1_Click"); + + // Then also make sure that there is no defined name for the macro, which is only needed for + // XLS: + xmlDocUniquePtr pWorkbookDoc = parseExport("xl/workbook.xml"); + CPPUNIT_ASSERT(pWorkbookDoc); + assertXPath(pWorkbookDoc, "//x:workbook/definedNames"_ostr, 0); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf104902) +{ + createScDoc("tdf104902.ods"); + + executeMacro("vnd.sun.Star.script:Standard.Module1.display_bug?language=Basic&location=document"); + + // Export to ODS + saveAndReload("calc8"); + ScDocument* pDoc = getScDoc(); + + CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), pDoc->GetString(ScAddress(0, 0, 0))); + + // Without the fix in place, this test would have failed with + // - Expected: string with + // newlines + // - Actual : string withnewlines + CPPUNIT_ASSERT_EQUAL(OUString(u"string with" + OUStringChar(u'\xA') + u"newlines"), pDoc->GetString(ScAddress(0, 1, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf64639) +{ + createScDoc("tdf64639.ods"); + ScDocument* pDoc = getScDoc(); + + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + const SdrPage* pPage = pDrawLayer->GetPage(0); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount()); + + // Add and delete the chart a few times + // Without the fix in place, this test would have crashed here + for (size_t i = 0; i < 5; ++i) + { + executeMacro("vnd.sun.Star.script:Standard.Module1.DrawGraph?language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount()); + + executeMacro("vnd.sun.Star.script:Standard.Module1.DeleteGraph?language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount()); + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf142033) +{ + createScDoc("tdf142033.ods"); + + executeMacro("vnd.sun.Star.script:Standard.Module1.display_bug?language=Basic&location=document"); + + // Export to ODS + saveAndReload("calc8"); + ScDocument* pDoc = getScDoc(); + + CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), pDoc->GetString(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), pDoc->GetString(ScAddress(0,1,0))); + + // Without the fix in place, this test would have failed with + // - Expected: string with + // newlines + // - Actual : string withnewlines + CPPUNIT_ASSERT_EQUAL(OUString(u"string with" + OUStringChar(u'\xA') + u"newlines"), pDoc->GetString(ScAddress(1,0,0))); + CPPUNIT_ASSERT_EQUAL(OUString(u"string with" + OUStringChar(u'\xA') + u"newlines"), pDoc->GetString(ScAddress(1,1,0))); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf89920) +{ + createScDoc("tdf89920.ods"); + + executeMacro("vnd.sun.Star.script:Standard.Module1.SearchAndReplaceNewline?language=Basic&" + "location=document"); + + // Export to ODS + saveAndReload("calc8"); + + xmlDocUniquePtr pContentXml = parseExport("content.xml"); + CPPUNIT_ASSERT(pContentXml); + + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[1]/table:table-cell[1]/text:p[1]"_ostr, + "aa bb"); + + // Without the fix in place, this test would have failed here with + // - Expression: xmlXPathNodeSetGetLength(pXmlNodes) > 0 + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[1]/table:table-cell[1]/text:p[2]"_ostr, + "cc dd"); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testPasswordProtectedUnicodeString) +{ + const OUString sCorrectString(u"English Русский 中文"_ustr); + static constexpr OUString sMacroURL( + u"vnd.sun.Star.script:Protected.Module1.TestUnicodeString?language=Basic&location=document"_ustr); + static constexpr OUString sLibName(u"Protected"_ustr); + + createScDoc("tdf57113.ods"); + + // Check that loading password-protected macro image correctly loads Unicode strings + { + Any aRet = executeMacro(sMacroURL); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sCorrectString, aReturnValue); + } + + // Unlock and load the library, to regenerate the image on save + css::uno::Reference<css::document::XEmbeddedScripts> xES(mxComponent, UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainer> xLC(xES->getBasicLibraries(), + UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainerPassword> xPasswd(xLC, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xPasswd->isLibraryPasswordProtected(sLibName)); + CPPUNIT_ASSERT(!xPasswd->isLibraryPasswordVerified(sLibName)); + CPPUNIT_ASSERT(xPasswd->verifyLibraryPassword(sLibName, "password")); + xLC->loadLibrary(sLibName); + CPPUNIT_ASSERT(xLC->isLibraryLoaded(sLibName)); + + // Now check that saving stores Unicode data correctly in image's string pool + saveAndReload("calc8"); + + { + Any aRet = executeMacro(sMacroURL); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sCorrectString, aReturnValue); + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testPasswordProtectedArrayInUserType) +{ + static constexpr OUString sMacroURL( + u"vnd.sun.Star.script:Protected.Module1.TestMyType?language=Basic&location=document"_ustr); + static constexpr OUString sLibName(u"Protected"_ustr); + + createScDoc("ProtectedArrayInCustomType.ods"); + + // Check that loading password-protected macro image correctly loads array bounds + { + Any aRet = executeMacro(sMacroURL); + + sal_Int16 nReturnValue; + aRet >>= nReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nReturnValue); + } + + // Unlock and load the library, to regenerate the image on save + css::uno::Reference<css::document::XEmbeddedScripts> xES(mxComponent, UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainer> xLC(xES->getBasicLibraries(), + UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainerPassword> xPasswd(xLC, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xPasswd->isLibraryPasswordProtected(sLibName)); + CPPUNIT_ASSERT(!xPasswd->isLibraryPasswordVerified(sLibName)); + CPPUNIT_ASSERT(xPasswd->verifyLibraryPassword(sLibName, "password")); + xLC->loadLibrary(sLibName); + CPPUNIT_ASSERT(xLC->isLibraryLoaded(sLibName)); + + // Now check that saving stores array bounds correctly + saveAndReload("calc8"); + + { + Any aRet = executeMacro(sMacroURL); + + sal_Int16 nReturnValue; + aRet >>= nReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nReturnValue); + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf114427) +{ + createScDoc("tdf114427.ods"); + + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xDraws(xDrawPageSupplier->getDrawPage(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xDraws->getCount()); + + // Without the fix in place, it would have crashed here + executeMacro("vnd.sun.Star.script:Standard.Module1.DeletingFrame?language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), xDraws->getCount()); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf131296_legacy) +{ + // For legacy password-protected library images, we must correctly get the constants' values, + // and also - for Integer - the type. + const std::vector<std::pair<OUString, OUString>> aTests({ + { "TestIntConst", "Integer: 123" }, + { "TestLongConst", "Double: 123" }, + { "TestSingleConst", "Double: 123" }, + { "TestDoubleConst", "Double: 123" }, + }); + + createScDoc("tdf131296_legacy.ods"); + { + for (auto& [sTestName, sExpected] : aTests) + { + Any aRet = executeMacro("vnd.sun.Star.script:Protected.Module1." + sTestName + + "?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf131296_new) +{ + // For new password-protected library images, we must correctly get both the constants' values + // and their types. + const std::vector<std::pair<OUString, OUString>> aTests({ + { "TestIntConst", "Integer: 123" }, + { "TestLongConst", "Long: 123" }, + { "TestSingleConst", "Single: 123" }, + { "TestDoubleConst", "Double: 123" }, + { "TestCurrencyConst", "Currency: 123.0000" }, + }); + + createScDoc("tdf131296_new.ods"); + { + for (auto& [sTestName, sExpected] : aTests) + { + Any aRet = executeMacro("vnd.sun.Star.script:Protected.Module1." + sTestName + + "?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf46119) +{ + createScDoc("tdf46119.ods"); + ScDocument* pDoc = getScDoc(); + + executeMacro("vnd.sun.Star.script:Standard.Module1.Main?language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(OUString("0.074"), pDoc->GetString(ScAddress(2, 24, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.067"), pDoc->GetString(ScAddress(2, 25, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.273"), pDoc->GetString(ScAddress(2, 26, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.259"), pDoc->GetString(ScAddress(2, 27, 0))); + + CPPUNIT_ASSERT_EQUAL(OUString("0.097"), pDoc->GetString(ScAddress(3, 24, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.087"), pDoc->GetString(ScAddress(3, 25, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.311"), pDoc->GetString(ScAddress(3, 26, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.296"), pDoc->GetString(ScAddress(3, 27, 0))); + + CPPUNIT_ASSERT_EQUAL(OUString("0.149"), pDoc->GetString(ScAddress(4, 24, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.134"), pDoc->GetString(ScAddress(4, 25, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.386"), pDoc->GetString(ScAddress(4, 26, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.366"), pDoc->GetString(ScAddress(4, 27, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf128218) +{ + createScDoc("tdf128218.ods"); + + Any aRet = executeMacro("vnd.sun.Star.script:Standard.Module1.TestRAND?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + + // Without the fix in place, this test would have failed with + // - Expected: Double + // - Actual : Object() + + CPPUNIT_ASSERT_EQUAL(OUString("Double"), aReturnValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf71271) +{ + createScDoc(); + { + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW); + xProps->setPropertyValue("CodeName", uno::Any(OUString("NewCodeName"))); + } + + saveAndReload(""); + + { + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + OUString sCodeName; + uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW); + // Without the fix in place the codename would not have been saved + xProps->getPropertyValue("CodeName") >>= sCodeName; + CPPUNIT_ASSERT_EQUAL(OUString("NewCodeName"), sCodeName); + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf43003) +{ + createScDoc("tdf43003.ods"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, the values of the specified cells won't be changed + pDoc->SetValue(ScAddress(0, 0, 0), 2); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(1, 0, 0))); + CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(2, 0, 0))); +} + + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf75263) +{ + createScDoc("tdf75263.xlsm"); + + { + ScDocument* pDoc = getScDoc(); + pDoc->CalcAll(); + + // A1 contains formula with user-defined function, and the function is defined in VBA. + CPPUNIT_ASSERT_EQUAL(u"проба"_ustr, pDoc->GetString(ScAddress(0, 0, 0))); + } + + saveAndReload("Calc MS Excel 2007 VBA XML"); + + { + ScDocument* pDoc = getScDoc(); + pDoc->CalcAll(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: проба (sample) + // - Actual : ????? + CPPUNIT_ASSERT_EQUAL(u"проба"_ustr, pDoc->GetString(ScAddress(0, 0, 0))); + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf133887) +{ + createScDoc("tdf133887.ods"); + + css::uno::Any aRet; + css::uno::Sequence<sal_Int16> aOutParamIndex; + css::uno::Sequence<css::uno::Any> aOutParam; + css::uno::Sequence<css::uno::Any> aParams{ css::uno::Any(sal_Int16(0)) }; + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:Standard.Module1.TestInvoke?language=Basic&location=document", aParams, + aRet, aOutParamIndex, aOutParam); + + double aReturnValue; + aOutParam[0] >>= aReturnValue; + + // Without the fix in place, this test would have failed with + // - Expected: 6.75 + // - Actual : 7 + + CPPUNIT_ASSERT_EQUAL(6.75, aReturnValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf133889) +{ + createScDoc("tdf133889.ods"); + + css::uno::Any aRet; + css::uno::Sequence<sal_Int16> aOutParamIndex; + css::uno::Sequence<css::uno::Any> aOutParam; + css::uno::Sequence<css::uno::Any> aParams{ css::uno::Any(sal_Int32(0)) }; + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:Standard.Module1.TestInvoke?language=Basic&location=document", aParams, + aRet, aOutParamIndex, aOutParam); + + sal_Int32 aReturnValue; + aOutParam[0] >>= aReturnValue; + + // Without the fix in place, this test would have failed with + // - Expected: 100000 + // - Actual : 0 + + CPPUNIT_ASSERT_EQUAL(sal_Int32(100000), aReturnValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf143582) +{ + createScDoc("tdf143582.ods"); + + Any aRet = executeMacro("vnd.sun.Star.script:Standard.Module1.TestScriptInvoke?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + + // Without the fix in place, this test would have failed with + // - Expected: Test6 + // - Actual : TeTest8 + CPPUNIT_ASSERT_EQUAL(OUString("Test6"), aReturnValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf144085) +{ + createScDoc("tdf144085.ods"); + + Any aRet = executeMacro("vnd.sun.Star.script:Standard.Module1.TestScriptInvoke?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + + // Without the fix in place, this test would have failed with + // - Expected: $Sheet1.$B$5:$E$17 + // - Actual : $Sheet1.$B$5:$C$10 + CPPUNIT_ASSERT_EQUAL(OUString("$Sheet1.$B$5:$E$17"), aReturnValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf125800) +{ + createScDoc("tdf125800.ods"); + ScDocument* pDoc = getScDoc(); + + ScConditionalFormat* pFormat = pDoc->GetCondFormat(1, 2, 0); + CPPUNIT_ASSERT(!pFormat); + + // Without the fix in place, this test would have failed with + // - Expression: false + // - Unexpected dialog: Error: Inadmissible value or data type. Index out of defined range. + Any aRet = executeMacro("vnd.sun.Star.script:Standard.cf.doItForThisSheetindexThisRange?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + + pFormat = pDoc->GetCondFormat(1, 2, 0); + CPPUNIT_ASSERT(pFormat); + + const ScFormatEntry* pEntry = pFormat->GetEntry(0); + CPPUNIT_ASSERT(pEntry); + CPPUNIT_ASSERT_EQUAL(ScFormatEntry::Type::Condition, pEntry->GetType()); + + const ScCondFormatEntry* pCondition = static_cast<const ScCondFormatEntry*>(pEntry); + CPPUNIT_ASSERT_EQUAL(ScConditionMode::Direct, pCondition->GetOperation()); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf130307) +{ + createScDoc("tdf130307.ods"); + + Any aRet = executeMacro("vnd.sun.Star.script:Standard.Module1.ForEachSheets?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + + // Without the fix in place, this test would have crashed here + CPPUNIT_ASSERT_EQUAL(OUString("Sheet1Sheet2"), aReturnValue); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf144970) +{ + createScDoc("tdf144970.ods"); + ScDocument* pDoc = getScDoc(); + + formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_ENGLISH_XL_A1; + pDoc->SetGrammar(eGram); + + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + const SdrPage* pPage = pDrawLayer->GetPage(0); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount()); + + // Without the fix in place, this test would have failed with + // - Expression: false + // - Unexpected dialog: Error: BASIC runtime error. + // An exception occurred + // Type: com.sun.star.lang.IllegalArgumentException + executeMacro("vnd.sun.Star.script:Standard.Module1.Main?language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount()); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf138646) +{ + createScDoc("tdf138646.ods"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, changing the grammar from GRAM_NATIVE to either GRAM_NATIVE_XL_A1 + // or GRAM_NATIVE_XL_R1C1 would cause a Basic exception/error in the following script. + pDoc->SetGrammar(formula::FormulaGrammar::Grammar::GRAM_NATIVE_XL_R1C1); + + const std::vector<std::pair<OUString, OUString>> aTests({ + { "GlobalNamedCell", "GlobalNamedCell" }, + { "GlobalNamedCellSheet", "GlobalNamedCell" }, + { "LocalNamedCell", "LocalNamedCell" }, + { "LocalNamedCellAccessError", "Exception" } + }); + + { + for (auto& [sTestName, sExpected] : aTests) + { + Any aRet = executeMacro("vnd.sun.Star.script:Standard.Module1." + sTestName + + "?language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf105558) +{ + createScDoc("tdf105558.ods"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: 5.5 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(5.5, pDoc->GetValue(ScAddress(0, 0, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf107572) +{ + createScDoc(); + + // insert initial library + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any( + OUString("Function Main\n" + " thisComponent.Sheets(0).getCellRangeByName(\"A1:F14\").autoformat(\"Default\")\n" + "End Function\n"))); + + // Without the fix in place, this test would have crashed + executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.Main?language=Basic&location=document"); + + ScDocument* pDoc = getScDoc(); + + //Check the autoformat has been applied + for (SCCOL i = 0; i < 5; ++i) + { + const ScPatternAttr* pAttr = pDoc->GetPattern(i, 0, 0); + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); + const Color& rColor = rBackground.GetColor(); + + CPPUNIT_ASSERT_EQUAL(Color(0x0, 0x0, 0x80), rColor); + } + + for (SCROW i = 1; i < 13; ++i) + { + const ScPatternAttr* pAttr = pDoc->GetPattern(0, i, 0); + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); + const Color& rColor = rBackground.GetColor(); + + CPPUNIT_ASSERT_EQUAL(Color(0x4d, 0x4d, 0x4d), rColor); + + const ScPatternAttr* pAttr2 = pDoc->GetPattern(5, i, 0); + const SfxPoolItem& rItem2 = pAttr2->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground2 = static_cast<const SvxBrushItem&>(rItem2); + const Color& rColor2 = rBackground2.GetColor(); + + CPPUNIT_ASSERT_EQUAL(Color(0xcc, 0xcc, 0xcc), rColor2); + } +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testShapeLayerId) +{ + createScDoc(); + + // insert initial library + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any( + OUString("Function TestLayerID\n" + " xShape = thisComponent.createInstance(\"com.sun.star.drawing.TextShape\")\n" + " thisComponent.DrawPages(0).Add(xShape)\n" + " origID = xShape.LayerID\n" + " On Error Goto handler\n" + " xShape.LayerID = 257 ' 1 if wrongly converted to unsigned 8-bit type\n" + " TestLayerID = origID & \" \" & xShape.LayerID ' Should not happen\n" + " Exit Function\n" + "handler:\n" + " ' This is expected to happen\n" + " TestLayerID = origID & \" Expected runtime error happened\"\n" + "End Function\n"))); + + Any aRet = executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestLayerID?language=Basic&location=document"); + // Without the fix in place, this test would have failed in non-debug builds with + // - Expected : <Any: (string) 0 Expected runtime error happened> + // - Actual : <Any: (string) 0 1> + // In debug builds, it would crash on assertion inside strong_int ctor. + // The LayerID property of com.sun.star.drawing.Shape service has 'short' IDL type. + // The expected run-time error is because there are only 5 layers there. + CPPUNIT_ASSERT_EQUAL(Any(OUString("0 Expected runtime error happened")), aRet); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testFunctionAccessIndirect) +{ + OUString aFileName = loadFromFile(u"tdf120161.ods"); // just some document with known values in cells + + const OUString aReference = "'" + aFileName + "'#$Sheet1.A1"; + + css::uno::Reference<css::sheet::XFunctionAccess> xFunc( + comphelper::getProcessServiceFactory()->createInstance("com.sun.star.sheet.FunctionAccess"), + UNO_QUERY_THROW); + + // tdf#148040: without the fix in place, this would have failed with: + // An uncaught exception of type com.sun.star.lang.IllegalArgumentException + // because of disallowed external link update (needed to obtain the cell value). + css::uno::Any aResult = xFunc->callFunction("INDIRECT", {css::uno::Any(aReference)}); + CPPUNIT_ASSERT_EQUAL(css::uno::Any(OUString("a1")), aResult); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf147122) +{ + createScDoc(); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any( + OUString("Function TestMergedSelection\n" + // Insert test string into cell A1 + " oActiveSheet = ThisComponent.CurrentController.ActiveSheet\n" + " oActiveCell = oActiveSheet.getCellRangeByName(\"A1\")\n" + " oActiveCell.setString(\"This is a test\")\n" + // Merge A1:B2 cell range and return the content of the merged range + " oRange = oActiveSheet.getCellRangeByName(\"A1:B2\")\n" + " ThisComponent.getCurrentController.Select(oRange)\n" + " oActiveCell = ThisComponent.CurrentSelection\n" + " oActiveCell.Merge(True)\n" + " TestMergedSelection = ThisComponent.getCurrentSelection().getString()\n" + "End Function\n"))); + + Any aRet = executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestMergedSelection?" + "language=Basic&location=document"); + // Without the fix in place, this test would have failed with + // - Expression: false + // - Unexpected dialog: Error: BASIC runtime error. + // Property or method not found: getString. + CPPUNIT_ASSERT_EQUAL(Any(OUString("This is a test")), aRet); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf154803) +{ + createScDoc(); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any( + OUString("Function TestExtendedMergedSelection\n" + // Merge A1:B2 cell range + " oActiveSheet = ThisComponent.CurrentController.ActiveSheet\n" + " oRange = oActiveSheet.getCellRangeByName(\"A1:B2\")\n" + " ThisComponent.getCurrentController.Select(oRange)\n" + " oActiveCell = ThisComponent.CurrentSelection\n" + " oActiveCell.Merge(True)\n" + // Select A1:B3 range and check for its implementation name + " oRange = oActiveSheet.getCellRangeByName(\"A1:B3\")\n" + " ThisComponent.getCurrentController.Select(oRange)\n" + " TestExtendedMergedSelection = ThisComponent.CurrentSelection.ImplementationName\n" + "End Function\n"))); + + Any aRet = executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestExtendedMergedSelection?" + "language=Basic&location=document"); + // Without the fix in place, this test would have failed with + // - Expected : ScCellRangeObj + // - Actual : ScCellObj + // i.e. the selection was interpreted as a single cell instead of a range + CPPUNIT_ASSERT_EQUAL(Any(OUString("ScCellRangeObj")), aRet); +} + +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf116127) +{ + createScDoc(); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any(OUString( + "Function TestClearContents\n" + // Insert test string into cell A1 + " oActiveSheet = ThisComponent.CurrentController.ActiveSheet\n" + " oActiveCell = oActiveSheet.getCellRangeByName(\"A1\")\n" + " oActiveCell.setString(\"Italic Test\")\n" + // Create a text cursor and change the first letter to italic + " oCursor = oActiveCell.Text.createTextCursor()\n" + " oCursor.gotoStart(False)\n" + " oCursor.goRight(1, True)\n" + " oCursor.CharPosture = com.sun.star.awt.FontSlant.ITALIC\n" + // Clear contents using EDITATTR cell flag to clear the italic char posture + " oActiveCell.clearContents(com.sun.star.sheet.CellFlags.EDITATTR)\n" + // Check the char posture of the first letter + " oCursor.gotoStart(False)\n" + " oCursor.goRight(1, True)\n" + " TestClearContents = oCursor.CharPosture <> com.sun.star.awt.FontSlant.ITALIC\n" + "End Function\n"))); + + Any aRet = executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestClearContents?" + "language=Basic&location=document"); + // Without the fix in place, this test would have failed with + // - Expected : true + // - Actual : false + // i.e. the formatting within parts of the cell contents (EDITATTR) were not deleted + CPPUNIT_ASSERT_EQUAL(Any(true), aRet); +} + +ScMacrosTest::ScMacrosTest() + : ScModelTestBase("/sc/qa/extras/testdocuments") +{ +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/new_cond_format.cxx b/sc/qa/extras/new_cond_format.cxx new file mode 100644 index 0000000000..9749d639c6 --- /dev/null +++ b/sc/qa/extras/new_cond_format.cxx @@ -0,0 +1,447 @@ +/* -*- 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 <test/unoapi_test.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XConditionalFormats.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/DataBarAxis.hpp> +#include <com/sun/star/sheet/XDataBarEntry.hpp> +#include <com/sun/star/sheet/DataBarEntryType.hpp> +#include <com/sun/star/sheet/ColorScaleEntryType.hpp> +#include <com/sun/star/sheet/XColorScaleEntry.hpp> + +using namespace css; + +namespace sc_apitest { + +class ScConditionalFormatTest : public UnoApiTest +{ +public: + ScConditionalFormatTest(); + + virtual void setUp() override; + + uno::Reference< uno::XInterface > init(sal_Int32 nIndex = 0); + void testRequestCondFormatListFromSheet(); + void testCondFormatListProperties(); + void testCondFormatListFormats(); + void testCondFormatProperties(); + void testCondFormatXIndex(); + void testDataBarProperties(); + void testColorScaleProperties(); + + CPPUNIT_TEST_SUITE(ScConditionalFormatTest); + CPPUNIT_TEST(testRequestCondFormatListFromSheet); + CPPUNIT_TEST(testCondFormatListProperties); + CPPUNIT_TEST(testCondFormatListFormats); + CPPUNIT_TEST(testCondFormatProperties); + CPPUNIT_TEST(testCondFormatXIndex); + CPPUNIT_TEST(testDataBarProperties); + CPPUNIT_TEST(testColorScaleProperties); + CPPUNIT_TEST_SUITE_END(); +}; + +ScConditionalFormatTest::ScConditionalFormatTest() + : UnoApiTest("sc/qa/extras/testdocuments/") +{ +} + +uno::Reference< uno::XInterface > ScConditionalFormatTest::init(sal_Int32 nIndex) +{ + // get the first sheet + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(nIndex), uno::UNO_QUERY_THROW); + + return xSheet; +} + +void ScConditionalFormatTest::testRequestCondFormatListFromSheet() +{ + uno::Reference<sheet::XSpreadsheet> xSheet(init(), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW); + uno::Any aAny = xProps->getPropertyValue("ConditionalFormats"); + uno::Reference<sheet::XConditionalFormats> xCondFormats; + CPPUNIT_ASSERT(aAny >>= xCondFormats); + CPPUNIT_ASSERT(xCondFormats.is()); +} + +namespace { + +uno::Reference<sheet::XConditionalFormats> getConditionalFormatList(uno::Reference<uno::XInterface> const & xInterface) +{ + uno::Reference<sheet::XSpreadsheet> xSheet(xInterface, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW); + uno::Any aAny = xProps->getPropertyValue("ConditionalFormats"); + uno::Reference<sheet::XConditionalFormats> xCondFormats; + CPPUNIT_ASSERT(aAny >>= xCondFormats); + CPPUNIT_ASSERT(xCondFormats.is()); + + return xCondFormats; +} + +} + +void ScConditionalFormatTest::testCondFormatListProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormat = + getConditionalFormatList(init()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xCondFormat->getLength()); +} + +void ScConditionalFormatTest::testCondFormatListFormats() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init()); + + const uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xCondFormats.getLength()); + for (auto const & cf : xCondFormats) + { + CPPUNIT_ASSERT(cf.is()); + } +} + +void ScConditionalFormatTest::testCondFormatProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(1)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + uno::Reference<beans::XPropertySet> xPropSet(xCondFormat, uno::UNO_QUERY_THROW); + uno::Any aAny = xPropSet->getPropertyValue("Range"); + uno::Reference<sheet::XSheetCellRanges> xCellRanges; + CPPUNIT_ASSERT(aAny >>= xCellRanges); + CPPUNIT_ASSERT(xCellRanges.is()); + uno::Sequence<table::CellRangeAddress> aRanges = xCellRanges->getRangeAddresses(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength()); + table::CellRangeAddress aRange = aRanges[0]; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), aRange.Sheet); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange.StartColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aRange.StartRow); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aRange.EndColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aRange.EndRow); +} + +void ScConditionalFormatTest::testCondFormatXIndex() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(1)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + + uno::Type aType = xCondFormat->getElementType(); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.beans.XPropertySet"), aType.getTypeName()); + + CPPUNIT_ASSERT(xCondFormat->hasElements()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xCondFormat->getCount()); + + uno::Any aAny = xCondFormat->getByIndex(0); + CPPUNIT_ASSERT(aAny.hasValue()); +} + +namespace { + +void testAxisPosition(uno::Reference<beans::XPropertySet> const & xPropSet, sal_Int32 ePos) +{ + sal_Int32 eAxisPos; + uno::Any aAny = xPropSet->getPropertyValue("AxisPosition"); + CPPUNIT_ASSERT(aAny >>= eAxisPos); + CPPUNIT_ASSERT_EQUAL(ePos, eAxisPos); +} + +void testShowValue(uno::Reference<beans::XPropertySet> const & xPropSet, bool bShowVal) +{ + bool bShow; + uno::Any aAny = xPropSet->getPropertyValue("ShowValue"); + CPPUNIT_ASSERT(aAny >>= bShow); + CPPUNIT_ASSERT_EQUAL(bShowVal, bShow); +} + +void testUseGradient(uno::Reference<beans::XPropertySet> const & xPropSet, bool bUseGradient) +{ + bool bGradient; + uno::Any aAny = xPropSet->getPropertyValue("UseGradient"); + CPPUNIT_ASSERT(aAny >>= bGradient); + CPPUNIT_ASSERT_EQUAL(bUseGradient, bGradient); +} + +void testPositiveColor(uno::Reference<beans::XPropertySet> const & xPropSet, Color aColor) +{ + ::Color nColor; + uno::Any aAny = xPropSet->getPropertyValue("Color"); + CPPUNIT_ASSERT(aAny >>= nColor); + CPPUNIT_ASSERT_EQUAL(aColor, nColor); +} + +void testNegativeColor(uno::Reference<beans::XPropertySet> const & xPropSet, Color aColor) +{ + ::Color nColor; + uno::Any aAny = xPropSet->getPropertyValue("NegativeColor"); + CPPUNIT_ASSERT(aAny >>= nColor); + CPPUNIT_ASSERT_EQUAL(aColor, nColor); +} + +void testAxisColor(uno::Reference<beans::XPropertySet> const & xPropSet, Color aColor) +{ + ::Color nColor; + uno::Any aAny = xPropSet->getPropertyValue("AxisColor"); + CPPUNIT_ASSERT(aAny >>= nColor); + CPPUNIT_ASSERT_EQUAL(aColor, nColor); +} + +void testDataBarEntryValue(uno::Reference<sheet::XDataBarEntry> const & xEntry, + const OUString& rExpectedValue, sal_Int32 nType) +{ + switch (nType) + { + case sheet::DataBarEntryType::DATABAR_VALUE: + case sheet::DataBarEntryType::DATABAR_PERCENT: + case sheet::DataBarEntryType::DATABAR_PERCENTILE: + case sheet::DataBarEntryType::DATABAR_FORMULA: + { + OUString aString = xEntry->getFormula(); + CPPUNIT_ASSERT_EQUAL(rExpectedValue, aString); + } + break; + default: + break; + } +} + +void testDataBarEntries(uno::Reference<beans::XPropertySet> const & xPropSet, + const OUString& rExpectedMinString, sal_Int32 nExpectedMinType, + const OUString& rExpectedMaxString, sal_Int32 nExpectedMaxType) +{ + uno::Any aAny = xPropSet->getPropertyValue("DataBarEntries"); + uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries; + CPPUNIT_ASSERT(aAny >>= aEntries); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aEntries.getLength()); + + sal_Int32 nMinType = aEntries[0]->getType(); + CPPUNIT_ASSERT_EQUAL(nExpectedMinType, nMinType); + + sal_Int32 nMaxType = aEntries[1]->getType(); + CPPUNIT_ASSERT_EQUAL(nExpectedMaxType, nMaxType); + + testDataBarEntryValue(aEntries[0], rExpectedMinString, nMinType); + testDataBarEntryValue(aEntries[1], rExpectedMaxString, nMaxType); +} + +} + +void ScConditionalFormatTest::testDataBarProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(2)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + + uno::Type aType = xCondFormat->getElementType(); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.beans.XPropertySet"), aType.getTypeName()); + + CPPUNIT_ASSERT(xCondFormat->hasElements()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormat->getCount()); + + uno::Reference<beans::XPropertySet> xPropSet; + { + uno::Any aAny = xCondFormat->getByIndex(0); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + testDataBarEntries(xPropSet, "", sheet::DataBarEntryType::DATABAR_AUTO, + "", sheet::DataBarEntryType::DATABAR_MAX); + } + { + uno::Any aAny = xCondFormat->getByIndex(1); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + testDataBarEntries(xPropSet, "", sheet::DataBarEntryType::DATABAR_MIN, + "90", sheet::DataBarEntryType::DATABAR_PERCENTILE); + } + { + uno::Any aAny = xCondFormat->getByIndex(2); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + testDataBarEntries(xPropSet, "2", sheet::DataBarEntryType::DATABAR_VALUE, + "80", sheet::DataBarEntryType::DATABAR_PERCENT); + } + { + uno::Any aAny = xCondFormat->getByIndex(3); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + /* + * TODO: implement FORMULA + testDataBarEntries(xPropSet, "=A1", sheet::DataBarEntryType::DATABAR_FORMULA, + "", sheet::DataBarEntryType::DATABAR_AUTO); + */ + } + { + uno::Any aAny = xCondFormat->getByIndex(4); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_MIDDLE); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, false); + testPositiveColor(xPropSet, sal_uInt32(10092390)); + testNegativeColor(xPropSet, sal_uInt32(52428)); + testAxisColor(xPropSet, sal_uInt32(16777113)); + testDataBarEntries(xPropSet, "", sheet::DataBarEntryType::DATABAR_AUTO, + "", sheet::DataBarEntryType::DATABAR_AUTO); + } +} + +namespace { + +void testColorScaleEntry(uno::Reference<sheet::XColorScaleEntry> const & xEntry, + sal_Int32 nType, const OUString& rString, Color nColor) +{ + CPPUNIT_ASSERT_EQUAL(nType, xEntry->getType()); + CPPUNIT_ASSERT_EQUAL(nColor, Color(ColorTransparency, xEntry->getColor())); + switch (nType) + { + case sheet::ColorScaleEntryType::COLORSCALE_VALUE: + case sheet::ColorScaleEntryType::COLORSCALE_PERCENT: + case sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE: + // case sheet::ColorScaleEntryType::COLORSCALE_FORMULA: + { + CPPUNIT_ASSERT_EQUAL(rString, xEntry->getFormula()); + } + break; + default: + break; + } +} + +void testColorScaleEntries(uno::Reference<beans::XPropertySet> const & xPropSet, sal_Int32 nEntries, + sal_Int32 nMinType, const OUString& rMinString, Color nMinColor, + sal_Int32 nMediumType, const OUString& rMediumString, Color nMediumColor, + sal_Int32 nMaxType, const OUString& rMaxString, Color nMaxColor) +{ + uno::Any aAny = xPropSet->getPropertyValue("ColorScaleEntries"); + CPPUNIT_ASSERT(aAny.hasValue()); + uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries; + CPPUNIT_ASSERT(aAny >>= aEntries); + + CPPUNIT_ASSERT_EQUAL(nEntries, aEntries.getLength()); + testColorScaleEntry(aEntries[0], nMinType, rMinString, nMinColor); + size_t nMaxEntry = 1; + if (nEntries == 3) + { + nMaxEntry = 2; + testColorScaleEntry(aEntries[1], nMediumType, rMediumString, nMediumColor); + } + testColorScaleEntry(aEntries[nMaxEntry], nMaxType, rMaxString, nMaxColor); +} + +} + +void ScConditionalFormatTest::testColorScaleProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(3)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + + uno::Type aType = xCondFormat->getElementType(); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.beans.XPropertySet"), aType.getTypeName()); + + CPPUNIT_ASSERT(xCondFormat->hasElements()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xCondFormat->getCount()); + + uno::Reference<beans::XPropertySet> xPropSet; + { + uno::Any aAny = xCondFormat->getByIndex(0); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testColorScaleEntries(xPropSet, 3, sheet::ColorScaleEntryType::COLORSCALE_MIN, "", sal_uInt32(16777113), + sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE, "50", sal_uInt32(16737792), + sheet::ColorScaleEntryType::COLORSCALE_MAX, "", sal_uInt32(16724787)); + } + { + uno::Any aAny = xCondFormat->getByIndex(1); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testColorScaleEntries(xPropSet, 3, sheet::ColorScaleEntryType::COLORSCALE_VALUE, "0", sal_uInt32(16711680), + sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE, "50", sal_uInt32(10092390), + sheet::ColorScaleEntryType::COLORSCALE_PERCENT, "90", sal_uInt32(255)); + } + { + uno::Any aAny = xCondFormat->getByIndex(2); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testColorScaleEntries(xPropSet, 2, sheet::ColorScaleEntryType::COLORSCALE_FORMULA, "=A1", COL_WHITE, + sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE, "not used", sal_uInt32(1), + sheet::ColorScaleEntryType::COLORSCALE_VALUE, "10", COL_BLACK); + } +} + +void ScConditionalFormatTest::setUp() +{ + UnoApiTest::setUp(); + // get the test file + loadFromFile(u"new_cond_format_api.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScConditionalFormatTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scannotationobj.cxx b/sc/qa/extras/scannotationobj.cxx new file mode 100644 index 0000000000..fe092e0198 --- /dev/null +++ b/sc/qa/extras/scannotationobj.cxx @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xchild.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xsheetannotation.hxx> +#include <test/sheet/xsheetannotationshapesupplier.hxx> +#include <test/text/xsimpletext.hxx> +#include <test/text/xtextrange.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAnnontationObj : public UnoApiTest, + public apitest::XChild, + public apitest::XServiceInfo, + public apitest::XSheetAnnotation, + public apitest::XSheetAnnotationShapeSupplier, + public apitest::XSimpleText, + public apitest::XTextRange +{ +public: + ScAnnontationObj(); + + virtual void setUp() override; + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<sheet::XSheetAnnotation> getAnnotation(table::CellAddress&) override; + + CPPUNIT_TEST_SUITE(ScAnnontationObj); + + // XChild + CPPUNIT_TEST(testGetSetParent); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetAnnotation + CPPUNIT_TEST(testGetPosition); + CPPUNIT_TEST(testGetAuthor); + CPPUNIT_TEST(testGetDate); + CPPUNIT_TEST(testGetIsVisible); + CPPUNIT_TEST(testSetIsVisible); + + // XSheetAnnotationShapeSupplier + CPPUNIT_TEST(testGetAnnotationShape); + + // XSimpleText + CPPUNIT_TEST(testCreateTextCursor); + CPPUNIT_TEST(testCreateTextCursorByRange); + CPPUNIT_TEST(testInsertString); + CPPUNIT_TEST(testInsertControlCharacter); + + // XTextRange + CPPUNIT_TEST(testGetEnd); + CPPUNIT_TEST(testGetSetString); + CPPUNIT_TEST(testGetStart); + CPPUNIT_TEST(testGetText); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScAnnontationObj::ScAnnontationObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScAnnotationObj", "com.sun.star.sheet.CellAnnotation") +{ +} + +uno::Reference<sheet::XSheetAnnotation> +ScAnnontationObj::getAnnotation(table::CellAddress& xCellAddress) +{ + // get the sheet + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(xCellAddress.Sheet), + uno::UNO_QUERY_THROW); + + // get the cell + uno::Reference<table::XCell> xCell( + xSheet->getCellByPosition(xCellAddress.Column, xCellAddress.Row), uno::UNO_SET_THROW); + + // get the annotation from cell + uno::Reference<sheet::XSheetAnnotationAnchor> xAnnotationAnchor(xCell, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotation> xSheetAnnotation(xAnnotationAnchor->getAnnotation(), + uno::UNO_SET_THROW); + + return xSheetAnnotation; +} + +uno::Reference<uno::XInterface> ScAnnontationObj::init() +{ + // tested annotation is in sheet 0 cell C2 + table::CellAddress aCellAddress; + aCellAddress.Sheet = 0; + aCellAddress.Row = 1; + aCellAddress.Column = 2; + + return getAnnotation(aCellAddress); +} + +void ScAnnontationObj::setUp() +{ + UnoApiTest::setUp(); + + // get the test file + loadFromFile(u"ScAnnotationObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scannotationshapeobj.cxx b/sc/qa/extras/scannotationshapeobj.cxx new file mode 100644 index 0000000000..ceb37e89a4 --- /dev/null +++ b/sc/qa/extras/scannotationshapeobj.cxx @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/drawing/captionshape.hxx> +#include <test/drawing/xgluepointssupplier.hxx> +#include <test/drawing/xshape.hxx> +#include <test/drawing/xshapedescriptor.hxx> +#include <test/text/xsimpletext.hxx> +#include <test/text/xtext.hxx> +#include <test/text/xtextrange.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotation.hpp> +#include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp> +#include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAnnotationShapeObj : public UnoApiTest, + public apitest::CaptionShape, + public apitest::XGluePointsSupplier, + public apitest::XShape, + public apitest::XShapeDescriptor, + public apitest::XSimpleText, + public apitest::XText, + public apitest::XTextRange +{ +public: + ScAnnotationShapeObj(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<text::XTextContent> getTextContent() override; + + CPPUNIT_TEST_SUITE(ScAnnotationShapeObj); + + // CaptionShape + CPPUNIT_TEST(testCaptionShapeProperties); + + // XGluePointsSupplier + CPPUNIT_TEST(testGetGluePoints); + + // XShape + CPPUNIT_TEST(testGetSetSize); + CPPUNIT_TEST(testGetSetPosition); + + // XShapeDescriptor + CPPUNIT_TEST(testGetShapeType); + + // XSimpleText + CPPUNIT_TEST(testCreateTextCursor); + CPPUNIT_TEST(testCreateTextCursorByRange); + CPPUNIT_TEST(testInsertControlCharacter); + CPPUNIT_TEST(testInsertString); + + // XText + CPPUNIT_TEST(testInsertRemoveTextContent); + + // XTextRange + CPPUNIT_TEST(testGetEnd); + CPPUNIT_TEST(testGetSetString); + CPPUNIT_TEST(testGetStart); + CPPUNIT_TEST(testGetText); + + CPPUNIT_TEST_SUITE_END(); + +private: + static uno::Reference<text::XTextContent> m_xField; +}; + +uno::Reference<text::XTextContent> ScAnnotationShapeObj::m_xField; + +ScAnnotationShapeObj::ScAnnotationShapeObj() + : UnoApiTest("sc/qa/extras/testdocuments") + , XShapeDescriptor("com.sun.star.drawing.CaptionShape") +{ +} + +void ScAnnotationShapeObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAnnotationShapeObj::tearDown() +{ + m_xField.clear(); + UnoApiTest::tearDown(); +} + +uno::Reference<uno::XInterface> ScAnnotationShapeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + // Use cell A1 for this. + table::CellAddress aNotePos(0, 0, 0); + uno::Reference<sheet::XSheetAnnotationsSupplier> xAnnosSupp(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotations> xAnnos(xAnnosSupp->getAnnotations(), + uno::UNO_SET_THROW); + // non-empty string required by note implementation (real text will be added below) + xAnnos->insertNew(aNotePos, OUString(' ')); + + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); + uno::Reference<sheet::XSheetAnnotationAnchor> xAnchor(xCell, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotation> xAnnotation(xAnchor->getAnnotation(), + uno::UNO_SET_THROW); + uno::Reference<text::XSimpleText> xAnnoText(xAnnotation, uno::UNO_QUERY_THROW); + xAnnoText->setString("ScAnnotationShapeObj"); + + uno::Reference<sheet::XSheetAnnotationShapeSupplier> xShapeSupp(xAnnotation, + uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW); + + return xShape; +} + +uno::Reference<text::XTextContent> ScAnnotationShapeObj::getTextContent() +{ + if (!m_xField.is()) + { + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + m_xField.set(xSM->createInstance("com.sun.star.text.TextField.DateTime"), + uno::UNO_QUERY_THROW); + } + return m_xField; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnotationShapeObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scannotationsobj.cxx b/sc/qa/extras/scannotationsobj.cxx new file mode 100644 index 0000000000..b81107e057 --- /dev/null +++ b/sc/qa/extras/scannotationsobj.cxx @@ -0,0 +1,111 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/xsheetannotations.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotation.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScAnnontationsObj : public UnoApiTest, public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XSheetAnnotations +{ +public: + ScAnnontationsObj(); + + virtual void setUp() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< sheet::XSheetAnnotations > getAnnotations(tools::Long nIndex) override; + + CPPUNIT_TEST_SUITE(ScAnnontationsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XSheetAnnotations + CPPUNIT_TEST(testCount); + CPPUNIT_TEST(testIndex); + CPPUNIT_TEST(testInsertNew); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); +}; + + +ScAnnontationsObj::ScAnnontationsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSheetAnnotation>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference< sheet::XSheetAnnotations> ScAnnontationsObj::getAnnotations(tools::Long nIndex) +{ + // get the sheet + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(nIndex), UNO_QUERY_THROW); + + // get the annotations collection + uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnotationSupplier(xSheet, UNO_QUERY_THROW); + uno::Reference< sheet::XSheetAnnotations > xSheetAnnotations( xAnnotationSupplier->getAnnotations(), UNO_SET_THROW); + + return xSheetAnnotations; +} + +uno::Reference< uno::XInterface > ScAnnontationsObj::init() +{ + return getAnnotations(0); +} + +void ScAnnontationsObj::setUp() +{ + UnoApiTest::setUp(); + + // get the test file + loadFromFile(u"ScAnnotationObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationsObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scarealinkobj.cxx b/sc/qa/extras/scarealinkobj.cxx new file mode 100644 index 0000000000..05d5b92f81 --- /dev/null +++ b/sc/qa/extras/scarealinkobj.cxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/sheet/cellarealink.hxx> +#include <test/sheet/xarealink.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XAreaLink.hpp> +#include <com/sun/star/sheet/XAreaLinks.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAreaLinkObj : public UnoApiTest, + public apitest::CellAreaLink, + public apitest::XAreaLink, + public apitest::XPropertySet, + public apitest::XRefreshable +{ +public: + ScAreaLinkObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScAreaLinkObj); + + // CellAreaLink + CPPUNIT_TEST(testUrl); + CPPUNIT_TEST(testFilter); + CPPUNIT_TEST(testFilterOptions); + CPPUNIT_TEST(testRefreshDelay); + CPPUNIT_TEST(testRefreshPeriod); + + // XAreaLink + CPPUNIT_TEST(testGetDestArea); + CPPUNIT_TEST(testGetSourceArea); + CPPUNIT_TEST(testSetSourceArea); + CPPUNIT_TEST(testSetDestArea); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScAreaLinkObj::ScAreaLinkObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , CellAreaLink(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/scarealinkobj.ods")) +{ +} + +uno::Reference<uno::XInterface> ScAreaLinkObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XAreaLinks> xLinks(xPropSet->getPropertyValue("AreaLinks"), + uno::UNO_QUERY_THROW); + + table::CellAddress aCellAddress(1, 2, 3); + xLinks->insertAtPosition( + aCellAddress, m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/scarealinkobj.ods"), + "a2:b5", "", ""); + + uno::Reference<sheet::XAreaLink> xLink(xLinks->getByIndex(0), uno::UNO_QUERY_THROW); + return xLink; +} + +void ScAreaLinkObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAreaLinkObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scarealinksobj.cxx b/sc/qa/extras/scarealinksobj.cxx new file mode 100644 index 0000000000..86859da2dd --- /dev/null +++ b/sc/qa/extras/scarealinksobj.cxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/xarealinks.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XAreaLink.hpp> +#include <com/sun/star/sheet/XAreaLinks.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScAreaLinksObj : public UnoApiTest, + public apitest::XAreaLinks, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScAreaLinksObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScAreaLinksObj); + + // XAreaLinks + CPPUNIT_TEST(testInsertAtPosition); + CPPUNIT_TEST(testRemoveByIndex); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScAreaLinksObj::ScAreaLinksObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XAreaLink>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScAreaLinksObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XAreaLinks> xLinks(xPropSet->getPropertyValue("AreaLinks"), + uno::UNO_QUERY_THROW); + + xLinks->insertAtPosition(table::CellAddress(1, 2, 3), "ScAreaLinksObj.ods", "A2:B5", "", ""); + + return xLinks; +} + +void ScAreaLinksObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAreaLinksObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scautoformatobj.cxx b/sc/qa/extras/scautoformatobj.cxx new file mode 100644 index 0000000000..ba28fdf6c2 --- /dev/null +++ b/sc/qa/extras/scautoformatobj.cxx @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/tableautoformat.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAutoFormatObj : public UnoApiTest, + public apitest::TableAutoFormat, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScAutoFormatObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScAutoFormatObj); + + // TableAutoFormat + CPPUNIT_TEST(testTableAutoFormatProperties); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScAutoFormatObj::ScAutoFormatObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(16) + , XNamed("Default") + , XServiceInfo("ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat") +{ +} + +uno::Reference<uno::XInterface> ScAutoFormatObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xTableAutoFormat(xIA->getByIndex(xIA->getCount() - 1), + uno::UNO_QUERY_THROW); + return xTableAutoFormat; +} + +void ScAutoFormatObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAutoFormatObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scautoformatsobj.cxx b/sc/qa/extras/scautoformatsobj.cxx new file mode 100644 index 0000000000..90da32ea34 --- /dev/null +++ b/sc/qa/extras/scautoformatsobj.cxx @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/container/xnamereplace.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAutoFormatsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XNameReplace, + public apitest::XServiceInfo +{ +public: + ScAutoFormatsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScAutoFormatsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testInsertByNameDuplicate); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XNameReplace + CPPUNIT_TEST(testReplaceByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScAutoFormatsObj::ScAutoFormatsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNamed>::get()) + , XIndexAccess(2) + , XNameAccess("Default") + , XNameContainer("ScAutoFormatsObj") + , XNameReplace("ScAutoFormatsObj") + , XServiceInfo("stardiv.StarCalc.ScAutoFormatsObj", "com.sun.star.sheet.TableAutoFormats") +{ +} + +uno::Reference<uno::XInterface> ScAutoFormatsObj::init() +{ + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xTAF( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_SET_THROW); + + uno::Reference<container::XNameContainer> xNC(xTAF, uno::UNO_QUERY_THROW); + if (!xNC->hasByName("ScAutoFormatsObj")) + { + xNC->insertByName("ScAutoFormatsObj", + uno::Any(xMSF->createInstance("com.sun.star.sheet.TableAutoFormat"))); + } + // XNameContainer + XNameContainer::setElement( + uno::Any(xMSF->createInstance("com.sun.star.sheet.TableAutoFormat"))); + // XNameReplace + XNameReplace::setElement(uno::Any(xMSF->createInstance("com.sun.star.sheet.TableAutoFormat"))); + + return xTAF; +} + +void ScAutoFormatsObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAutoFormatsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellcursorobj.cxx b/sc/qa/extras/sccellcursorobj.cxx new file mode 100644 index 0000000000..c2b861ccd1 --- /dev/null +++ b/sc/qa/extras/sccellcursorobj.cxx @@ -0,0 +1,214 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/sheet/sheetcellrange.hxx> +#include <test/sheet/xarrayformularange.hxx> +#include <test/sheet/xcellformatrangessupplier.hxx> +#include <test/sheet/xcellrangeaddressable.hxx> +#include <test/sheet/xcellrangedata.hxx> +#include <test/sheet/xcellrangeformula.hxx> +#include <test/sheet/xcellseries.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xmultipleoperation.hxx> +#include <test/sheet/xsheetcellcursor.hxx> +#include <test/sheet/xsheetcellrange.hxx> +#include <test/sheet/xsheetfilterable.hxx> +#include <test/sheet/xsheetfilterableex.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/sheet/xsubtotalcalculatable.hxx> +#include <test/sheet/xuniquecellformatrangessupplier.hxx> +#include <test/sheet/xusedareacursor.hxx> +#include <test/table/xcellcursor.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/util/xindent.hxx> +#include <test/util/xmergeable.hxx> + +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XCellCursor.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScCellCursorObj : public UnoApiTest, public apitest::SheetCellRange, + public apitest::XArrayFormulaRange, + public apitest::XCellCursor, + public apitest::XCellFormatRangesSupplier, + public apitest::XCellRangeAddressable, + public apitest::XCellRangeData, + public apitest::XCellRangeFormula, + public apitest::XCellSeries, + public apitest::XColumnRowRange, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XMergeable, + public apitest::XMultipleOperation, + public apitest::XSheetCellCursor, + public apitest::XSheetCellRange, + public apitest::XSheetFilterable, + public apitest::XSheetFilterableEx, + public apitest::XSheetOperation, + public apitest::XSubTotalCalculatable, + public apitest::XUniqueCellFormatRangesSupplier, + public apitest::XUsedAreaCursor +{ +public: + ScCellCursorObj(); + + virtual void setUp() override; + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > getXCellRangeData() override; + virtual uno::Reference< uno::XInterface > getXSpreadsheet() override; + + CPPUNIT_TEST_SUITE(ScCellCursorObj); + + // SheetCellRange + CPPUNIT_TEST(testSheetCellRangeProperties); + + // XArrayFormulaRange + CPPUNIT_TEST(testGetSetArrayFormula); + + // XCellCursor + CPPUNIT_TEST(testGoToNext); + CPPUNIT_TEST(testGoToOffset); + CPPUNIT_TEST(testGoToPrevious); + CPPUNIT_TEST(testGoToStart); + CPPUNIT_TEST(testGoToEnd); + + // XCellFormatRangesSupplier + CPPUNIT_TEST(testGetCellFormatRanges); + + // XCellRangeAddressable + CPPUNIT_TEST(testGetRangeAddress); + + // XCellRangeData + CPPUNIT_TEST(testGetDataArray); + CPPUNIT_TEST(testSetDataArray); + + // XCellRangeFormula + CPPUNIT_TEST(testGetSetFormulaArray); + + // XCellSeries + CPPUNIT_TEST(testFillAuto); + CPPUNIT_TEST(testFillSeries); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XMergeable + CPPUNIT_TEST(testGetIsMergedMerge); + + // XMultipleOperation + CPPUNIT_TEST(testSetTableOperation); + + // XSheetCellCursor + CPPUNIT_TEST(testCollapseToCurrentArray); + CPPUNIT_TEST(testCollapseToCurrentRegion); + CPPUNIT_TEST(testCollapseToMergedArea); + CPPUNIT_TEST(testCollapseToSize); + CPPUNIT_TEST(testExpandToEntireColumns); + CPPUNIT_TEST(testExpandToEntireRows); + + // XSheetCellRange + CPPUNIT_TEST(testGetSpreadsheet); + + // XSheetFilterable + CPPUNIT_TEST(testCreateFilterDescriptor); + CPPUNIT_TEST(testFilter); + + // XSheetFilterableEx + CPPUNIT_TEST(testCreateFilterDescriptorByObject); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + // XSubTotalCalculatable + CPPUNIT_TEST(testCreateSubTotalDescriptor); + CPPUNIT_TEST(testApplyRemoveSubTotals); + + // XUsedAreaCursor + CPPUNIT_TEST(testGotoStartOfUsedArea); + CPPUNIT_TEST(testGotoEndOfUsedArea); + + // XUniqueCellFormatRangesSupplier + CPPUNIT_TEST(testGetUniqueCellFormatRanges); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellCursorObj::ScCellCursorObj(): + UnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XCellSeries(0, 0), + apitest::XFormulaQuery(table::CellRangeAddress(0, 15, 15, 15, 15), table::CellRangeAddress(0, 0, 15, 0, 15)) +{ +} + +uno::Reference< uno::XInterface > ScCellCursorObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByName("$A$1:$D$4"); + uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xCellRange, UNO_QUERY_THROW); + uno::Reference<table::XCellCursor> xCellCursor(xSheet->createCursorByRange(xSheetCellRange), UNO_QUERY_THROW); + + xSheet->getCellByPosition(1, 1)->setValue(1); + xSheet->getCellByPosition(4, 5)->setValue(1); + xSheet->getCellByPosition(3, 2)->setFormula("xTextDoc"); + xSheet->getCellByPosition(3, 3)->setFormula("xTextDoc"); + + return xCellCursor; +} + +uno::Reference< uno::XInterface > ScCellCursorObj::getXCellRangeData() +{ + return init(); +} + +uno::Reference< uno::XInterface > ScCellCursorObj::getXSpreadsheet() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +void ScCellCursorObj::setUp() +{ + UnoApiTest::setUp(); + + loadFromFile(u"ScCellCursorObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellCursorObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellfieldsobj.cxx b/sc/qa/extras/sccellfieldsobj.cxx new file mode 100644 index 0000000000..17db9339f1 --- /dev/null +++ b/sc/qa/extras/sccellfieldsobj.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFieldsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XRefreshable +{ +public: + ScCellFieldsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScCellFieldsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellFieldsObj::ScCellFieldsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<text::XTextField>::get()) +{ +} + +uno::Reference<uno::XInterface> ScCellFieldsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xTC(xMSF->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell(xSheet0->getCellByPosition(2, 3), uno::UNO_SET_THROW); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + xText->insertTextContent(xText->createTextCursor(), xTC, true); + + uno::Reference<text::XTextFieldsSupplier> xTFS(xCell, uno::UNO_QUERY_THROW); + return xTFS->getTextFields(); +} + +void ScCellFieldsObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellFieldsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellformatsenumeration.cxx b/sc/qa/extras/sccellformatsenumeration.cxx new file mode 100644 index 0000000000..85128937e2 --- /dev/null +++ b/sc/qa/extras/sccellformatsenumeration.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellFormatRangesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFormatsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScCellFormatsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScCellFormatsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellFormatsEnumeration::ScCellFormatsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScCellFormatsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XCellFormatRangesSupplier> xCFRS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_CFR(xCFRS->getCellFormatRanges(), + uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xIA_CFR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScCellFormatsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellFormatsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellformatsobj.cxx b/sc/qa/extras/sccellformatsobj.cxx new file mode 100644 index 0000000000..0add386b43 --- /dev/null +++ b/sc/qa/extras/sccellformatsobj.cxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellFormatRangesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFormatsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScCellFormatsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScCellFormatsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellFormatsObj::ScCellFormatsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCellRange>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScCellFormatsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XCellFormatRangesSupplier> xCFRS(xSheet0, uno::UNO_QUERY_THROW); + + return xCFRS->getCellFormatRanges(); +} + +void ScCellFormatsObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellFormatsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellobj.cxx b/sc/qa/extras/sccellobj.cxx new file mode 100644 index 0000000000..2a7f6d5cdf --- /dev/null +++ b/sc/qa/extras/sccellobj.cxx @@ -0,0 +1,142 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/sheet/sheetcell.hxx> +#include <test/sheet/xcelladdressable.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xsheetannotationanchor.hxx> +#include <test/table/xcell.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/text/xsimpletext.hxx> +#include <test/util/xindent.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellObj : public UnoApiTest, + public apitest::SheetCell, + public apitest::XCell, + public apitest::XCellAddressable, + public apitest::XColumnRowRange, + public apitest::XEnumerationAccess, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XSheetAnnotationAnchor, + public apitest::XSimpleText +{ +public: + ScCellObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScCellObj); + + // SheetCell + CPPUNIT_TEST(testSheetCellProperties); + + // XCell + CPPUNIT_TEST(testGetError); + CPPUNIT_TEST(testGetType); + CPPUNIT_TEST(testSetGetFormula); + CPPUNIT_TEST(testSetGetValue); + + // XCellAddressable + CPPUNIT_TEST(testGetCellAddress); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XSheetAnnotationAnchor + CPPUNIT_TEST(testGetAnnotation); + + // XSimpleText + CPPUNIT_TEST(testCreateTextCursor); + CPPUNIT_TEST(testCreateTextCursorByRange); + CPPUNIT_TEST(testInsertString); + CPPUNIT_TEST(testInsertControlCharacter); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellObj::ScCellObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XFormulaQuery(table::CellRangeAddress(0, 2, 3, 2, 3), + table::CellRangeAddress(0, 0, 0, 3, 0), 0, 0) +{ +} + +uno::Reference<uno::XInterface> ScCellObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetAnnotationsSupplier> xSheetAnnosSupplier(xSheet, UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotations> xSheetAnnos(xSheetAnnosSupplier->getAnnotations(), + UNO_SET_THROW); + xSheetAnnos->insertNew(table::CellAddress(0, 2, 3), "xSheetAnnotation"); + + return xSheet->getCellByPosition(2, 3); +} + +uno::Reference<uno::XInterface> ScCellObj::getXSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(2, 3)); + + return xSheet; +} + +void ScCellObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellrangeobj.cxx b/sc/qa/extras/sccellrangeobj.cxx new file mode 100644 index 0000000000..5470ae7579 --- /dev/null +++ b/sc/qa/extras/sccellrangeobj.cxx @@ -0,0 +1,257 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/chart/xchartdata.hxx> +#include <test/sheet/cellproperties.hxx> +#include <test/sheet/sheetcellrange.hxx> +#include <test/sheet/xarrayformularange.hxx> +#include <test/sheet/xcellformatrangessupplier.hxx> +#include <test/sheet/xcellrangeaddressable.hxx> +#include <test/sheet/xcellrangedata.hxx> +#include <test/sheet/xcellrangeformula.hxx> +#include <test/sheet/xcellrangesquery.hxx> +#include <test/sheet/xcellseries.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xmultipleoperation.hxx> +#include <test/sheet/xsheetcellrange.hxx> +#include <test/sheet/xsheetfilterable.hxx> +#include <test/sheet/xsheetfilterableex.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/sheet/xsubtotalcalculatable.hxx> +#include <test/sheet/xuniquecellformatrangessupplier.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/util/xindent.hxx> +#include <test/util/xmergeable.hxx> +#include <test/util/xreplaceable.hxx> +#include <test/util/xsearchable.hxx> +#include <comphelper/propertysequence.hxx> + +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/util/SortField.hpp> +#include <com/sun/star/util/XSortable.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScCellRangeObj : public UnoApiTest, + public apitest::CellProperties, + public apitest::SheetCellRange, + public apitest::XArrayFormulaRange, + public apitest::XCellFormatRangesSupplier, + public apitest::XCellRangeAddressable, + public apitest::XCellRangeData, + public apitest::XCellRangeFormula, + public apitest::XCellRangesQuery, + public apitest::XCellSeries, + public apitest::XChartData, + public apitest::XColumnRowRange, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XMergeable, + public apitest::XMultipleOperation, + public apitest::XReplaceable, + public apitest::XSearchable, + public apitest::XSheetCellRange, + public apitest::XSheetFilterable, + public apitest::XSheetFilterableEx, + public apitest::XSheetOperation, + public apitest::XSubTotalCalculatable, + public apitest::XUniqueCellFormatRangesSupplier +{ +public: + ScCellRangeObj(); + + virtual void setUp() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXCellRangeData() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet() override; + void testSortOOB(); + + CPPUNIT_TEST_SUITE(ScCellRangeObj); + + // CellProperties + CPPUNIT_TEST(testVertJustify); + CPPUNIT_TEST(testRotateReference); + + // SheetCellRange + CPPUNIT_TEST(testSheetCellRangeProperties); + + // XArrayFormulaRange + CPPUNIT_TEST(testGetSetArrayFormula); + + // XCellFormatRangesSupplier + CPPUNIT_TEST(testGetCellFormatRanges); + + // XCellRangeAddressable + CPPUNIT_TEST(testGetRangeAddress); + + // XCellRangeData + CPPUNIT_TEST(testGetDataArray); + CPPUNIT_TEST(testSetDataArray); + + // XCellRangeFormula + CPPUNIT_TEST(testGetSetFormulaArray); + + // XCellRangesQuery + CPPUNIT_TEST(testQueryColumnDifference); + CPPUNIT_TEST(testQueryContentDifference); + CPPUNIT_TEST(testQueryEmptyCells); + //CPPUNIT_TEST(testQueryFormulaCells); + CPPUNIT_TEST(testQueryIntersection); + CPPUNIT_TEST(testQueryRowDifference); + CPPUNIT_TEST(testQueryVisibleCells); + + // XCellSeries + CPPUNIT_TEST(testFillAuto); + CPPUNIT_TEST(testFillSeries); + + // XChartData + CPPUNIT_TEST(testGetNotANumber); + CPPUNIT_TEST(testIsNotANumber); + CPPUNIT_TEST(testChartDataChangeEventListener); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XMergeable + CPPUNIT_TEST(testGetIsMergedMerge); + + // XMultipleOperation + CPPUNIT_TEST(testSetTableOperation); + + // XReplaceable + CPPUNIT_TEST(testReplaceAll); + CPPUNIT_TEST(testCreateReplaceDescriptor); + + // XSearchable + CPPUNIT_TEST(testFindAll); + CPPUNIT_TEST(testFindFirst); + + // XSheetCellRange + CPPUNIT_TEST(testGetSpreadsheet); + + // XSheetFilterable + CPPUNIT_TEST(testCreateFilterDescriptor); + CPPUNIT_TEST(testFilter); + + // XSheetFilterableEx + CPPUNIT_TEST(testCreateFilterDescriptorByObject); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + // XSubTotalCalculatable + CPPUNIT_TEST(testCreateSubTotalDescriptor); + CPPUNIT_TEST(testApplyRemoveSubTotals); + + // XUniqueCellFormatRangesSupplier + CPPUNIT_TEST(testGetUniqueCellFormatRanges); + + CPPUNIT_TEST(testSortOOB); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellRangeObj::ScCellRangeObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XCellSeries(2, 1) + , XFormulaQuery(table::CellRangeAddress(0, 15, 15, 15, 15), + table::CellRangeAddress(0, 0, 15, 0, 15)) + , XReplaceable("15", "35") + , XSearchable("15", 1) +{ +} + +uno::Reference<uno::XInterface> ScCellRangeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xReturn(xSheet->getCellRangeByPosition(0, 0, 4, 4), + uno::UNO_SET_THROW); + + return xReturn; +} + +uno::Reference<uno::XInterface> ScCellRangeObj::getXSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +uno::Reference<uno::XInterface> ScCellRangeObj::getXCellRangeData() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(1), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xReturn(xSheet->getCellRangeByPosition(0, 0, 3, 3), + uno::UNO_SET_THROW); + + return xReturn; +} + +void ScCellRangeObj::testSortOOB() +{ + uno::Reference<util::XSortable> xSortable(init(), uno::UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> aEmptyDescriptor; + xSortable->sort(aEmptyDescriptor); + + uno::Sequence<util::SortField> aSort(1); + auto pSort = aSort.getArray(); + pSort[0].Field = 0xffffff; + pSort[0].SortAscending = true; + + uno::Sequence<beans::PropertyValue> aProps( + comphelper::InitPropertySequence({ { "SortFields", uno::Any(aSort) } })); + + xSortable->sort(aProps); +} + +void ScCellRangeObj::setUp() +{ + UnoApiTest::setUp(); + + loadFromFile(u"xcellrangesquery.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellRangeObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellrangesobj.cxx b/sc/qa/extras/sccellrangesobj.cxx new file mode 100644 index 0000000000..0c27f584c6 --- /dev/null +++ b/sc/qa/extras/sccellrangesobj.cxx @@ -0,0 +1,145 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/sheet/sheetcellranges.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xsheetcellrangecontainer.hxx> +#include <test/sheet/xsheetcellranges.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/util/xindent.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellRangesObj : public UnoApiTest, + public apitest::SheetCellRanges, + public apitest::XEnumerationAccess, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XSheetCellRangeContainer, + public apitest::XSheetCellRanges, + public apitest::XSheetOperation +{ +public: + ScCellRangesObj(); + + virtual void setUp() override; + + virtual uno::Reference<uno::XInterface> getXSpreadsheet() override; + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScCellRangesObj); + + // SheetCellRanges + CPPUNIT_TEST(testSheetCellRangesProperties); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XSheetCellRangeContainer + CPPUNIT_TEST(testAddRemoveRangeAddress); + CPPUNIT_TEST(testAddRemoveRangeAddresses); + + // XSheetCellRanges + CPPUNIT_TEST(testGetCells); + CPPUNIT_TEST(testGetRangeAddresses); + CPPUNIT_TEST(testGetRangeAddressesAsString); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellRangesObj::ScCellRangesObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XFormulaQuery(table::CellRangeAddress(0, 4, 1, 5, 4), + table::CellRangeAddress(0, 4, 1, 5, 4)) +{ +} + +uno::Reference<uno::XInterface> ScCellRangesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndexAccess(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xRanges( + xMSF->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY_THROW); + + uno::Any xCellRange; + xCellRange <<= xSheet->getCellRangeByName("C1:D4"); + xRanges->insertByName("Range1", xCellRange); + xCellRange <<= xSheet->getCellRangeByName("E2:F5"); + xRanges->insertByName("Range2", xCellRange); + xCellRange <<= xSheet->getCellRangeByName("G2:H3"); + xRanges->insertByName("Range3", xCellRange); + xCellRange <<= xSheet->getCellRangeByName("I7:J8"); + xRanges->insertByName("Range4", xCellRange); + + for (int i = 0; i < 10; i++) + { + for (int j = 5; j < 10; j++) + { + xSheet->getCellByPosition(i, j)->setValue(i + j); + } + } + + return xRanges; +} + +uno::Reference<uno::XInterface> ScCellRangesObj::getXSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +void ScCellRangesObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellRangesObj); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellsearchobj.cxx b/sc/qa/extras/sccellsearchobj.cxx new file mode 100644 index 0000000000..97283fa356 --- /dev/null +++ b/sc/qa/extras/sccellsearchobj.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/util/searchdescriptor.hxx> +#include <test/util/xreplacedescriptor.hxx> +#include <test/util/xsearchdescriptor.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/util/XSearchable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScCellSearchObj : public UnoApiTest, + public apitest::SearchDescriptor, + public apitest::XPropertySet, + public apitest::XReplaceDescriptor, + public apitest::XSearchDescriptor, + public apitest::XServiceInfo +{ +public: + ScCellSearchObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScCellSearchObj); + + // SearchDescriptor + CPPUNIT_TEST(testSearchDescriptorProperties); + + // XPropertSet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XReplaceDescriptor + CPPUNIT_TEST(testGetSetReplaceString); + + // XSearchDescriptor + CPPUNIT_TEST(testGetSetSearchString); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellSearchObj::ScCellSearchObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScCellSearchObj", + { "com.sun.star.util.ReplaceDescriptor", "com.sun.star.util.SearchDescriptor" }) +{ +} + +uno::Reference<uno::XInterface> ScCellSearchObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<util::XSearchable> xSearchable(xSheet0, uno::UNO_QUERY_THROW); + return xSearchable->createSearchDescriptor(); +} + +void ScCellSearchObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellSearchObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellsenumeration.cxx b/sc/qa/extras/sccellsenumeration.cxx new file mode 100644 index 0000000000..21263b1e88 --- /dev/null +++ b/sc/qa/extras/sccellsenumeration.cxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScCellsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScCellsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellsEnumeration::ScCellsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScCellsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCellRange(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell0(xCellRange->getCellByPosition(0, 0), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange0(xCell0, uno::UNO_QUERY_THROW); + xTextRange0->setString("Test string 1"); + + uno::Reference<table::XCell> xCell1(xCellRange->getCellByPosition(5, 1), uno::UNO_SET_THROW); + xCell1->setValue(15); + + uno::Reference<table::XCell> xCell2(xCellRange->getCellByPosition(3, 9), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange1(xCell2, uno::UNO_QUERY_THROW); + xTextRange1->setString("Test string 2"); + + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(xCellRange, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR(xCellRangesQuery->queryVisibleCells(), + uno::UNO_SET_THROW); + + return xSCR->getCells()->createEnumeration(); +} + +void ScCellsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellsobj.cxx b/sc/qa/extras/sccellsobj.cxx new file mode 100644 index 0000000000..32c7a88d17 --- /dev/null +++ b/sc/qa/extras/sccellsobj.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess +{ +public: + ScCellsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScCellsObj); + + // XElementAccess + CPPUNIT_TEST(testHasElements); + CPPUNIT_TEST(testGetElementType); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScCellsObj::ScCellsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCell>::get()) +{ +} + +uno::Reference<uno::XInterface> ScCellsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell0(xCellRange->getCellByPosition(0, 0), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange0(xCell0, uno::UNO_QUERY_THROW); + xTextRange0->setString("ScCellsObj test 1"); + + uno::Reference<table::XCell> xCell1(xCellRange->getCellByPosition(5, 1), uno::UNO_SET_THROW); + xCell1->setValue(15); + + uno::Reference<table::XCell> xCell2(xCellRange->getCellByPosition(3, 9), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange2(xCell2, uno::UNO_QUERY_THROW); + xTextRange2->setString("ScCellsObj test 2"); + + uno::Reference<sheet::XCellRangesQuery> xCRQ(xCellRange, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR(xCRQ->queryVisibleCells(), uno::UNO_SET_THROW); + + return xSCR->getCells(); +} + +void ScCellsObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scchartobj.cxx b/sc/qa/extras/scchartobj.cxx new file mode 100644 index 0000000000..aac4ee1171 --- /dev/null +++ b/sc/qa/extras/scchartobj.cxx @@ -0,0 +1,180 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> +#include <test/document/xembeddedobjectsupplier.hxx> +#include <test/table/xtablechart.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScChartObj : public UnoApiTest, + public apitest::XEmbeddedObjectSupplier, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XTableChart +{ +public: + ScChartObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScChartObj); + + // XEmbeddedObjectSupplier + CPPUNIT_TEST(testGetEmbeddedObject); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetNameThrowsException); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableChart + CPPUNIT_TEST(testGetSetHasColumnHeaders); + CPPUNIT_TEST(testGetSetHasRowHeaders); + CPPUNIT_TEST(testGetSetRanges); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScChartObj::ScChartObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("ScChartObj") + , XServiceInfo("ScChartObj", "com.sun.star.table.TableChart") +{ +} + +uno::Reference<uno::XInterface> ScChartObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(1, 0)->setFormula("JAN"); + xSheet0->getCellByPosition(2, 0)->setFormula("FEB"); + xSheet0->getCellByPosition(3, 0)->setFormula("MAR"); + xSheet0->getCellByPosition(4, 0)->setFormula("APR"); + xSheet0->getCellByPosition(5, 0)->setFormula("MAY"); + xSheet0->getCellByPosition(6, 0)->setFormula("JUN"); + xSheet0->getCellByPosition(7, 0)->setFormula("JUL"); + xSheet0->getCellByPosition(8, 0)->setFormula("AUG"); + xSheet0->getCellByPosition(9, 0)->setFormula("SEP"); + xSheet0->getCellByPosition(10, 0)->setFormula("OCT"); + xSheet0->getCellByPosition(11, 0)->setFormula("NOV"); + xSheet0->getCellByPosition(12, 0)->setFormula("DEC"); + xSheet0->getCellByPosition(13, 0)->setFormula("SUM"); + + xSheet0->getCellByPosition(0, 1)->setFormula("Smith"); + xSheet0->getCellByPosition(1, 1)->setValue(42); + xSheet0->getCellByPosition(2, 1)->setValue(58.9); + xSheet0->getCellByPosition(3, 1)->setValue(-66.5); + xSheet0->getCellByPosition(4, 1)->setValue(43.4); + xSheet0->getCellByPosition(5, 1)->setValue(44.5); + xSheet0->getCellByPosition(6, 1)->setValue(45.3); + xSheet0->getCellByPosition(7, 1)->setValue(-67.3); + xSheet0->getCellByPosition(8, 1)->setValue(30.5); + xSheet0->getCellByPosition(9, 1)->setValue(23.2); + xSheet0->getCellByPosition(10, 1)->setValue(-97.3); + xSheet0->getCellByPosition(11, 1)->setValue(22.4); + xSheet0->getCellByPosition(11, 1)->setValue(23.5); + xSheet0->getCellByPosition(13, 1)->setFormula("SUM(B2:M2"); + + xSheet0->getCellByPosition(0, 2)->setFormula("Jones"); + xSheet0->getCellByPosition(1, 2)->setValue(21); + xSheet0->getCellByPosition(2, 2)->setValue(40.9); + xSheet0->getCellByPosition(3, 2)->setValue(-57.5); + xSheet0->getCellByPosition(4, 2)->setValue(-23.4); + xSheet0->getCellByPosition(5, 2)->setValue(34.5); + xSheet0->getCellByPosition(6, 2)->setValue(59.3); + xSheet0->getCellByPosition(7, 2)->setValue(27.3); + xSheet0->getCellByPosition(8, 2)->setValue(-38.5); + xSheet0->getCellByPosition(9, 2)->setValue(43.2); + xSheet0->getCellByPosition(10, 2)->setValue(57.3); + xSheet0->getCellByPosition(11, 2)->setValue(25.4); + xSheet0->getCellByPosition(11, 2)->setValue(28.5); + xSheet0->getCellByPosition(13, 2)->setFormula("SUM(B3:M3"); + + xSheet0->getCellByPosition(0, 3)->setFormula("Brown"); + xSheet0->getCellByPosition(1, 3)->setValue(31.45); + xSheet0->getCellByPosition(2, 3)->setValue(-20.9); + xSheet0->getCellByPosition(3, 3)->setValue(-117.5); + xSheet0->getCellByPosition(4, 3)->setValue(23.4); + xSheet0->getCellByPosition(5, 3)->setValue(-114.5); + xSheet0->getCellByPosition(6, 3)->setValue(115.3); + xSheet0->getCellByPosition(7, 3)->setValue(-171.3); + xSheet0->getCellByPosition(8, 3)->setValue(89.5); + xSheet0->getCellByPosition(9, 3)->setValue(41.2); + xSheet0->getCellByPosition(10, 3)->setValue(71.3); + xSheet0->getCellByPosition(11, 3)->setValue(25.4); + xSheet0->getCellByPosition(11, 3)->setValue(38.5); + xSheet0->getCellByPosition(13, 3)->setFormula("SUM(A4:L4"); + + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCRA{ xCRA->getRangeAddress() }; + + uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableCharts> xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000), aCRA, true, true); + + uno::Reference<container::XNameAccess> xNA(xTC, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableChart> xChart(xNA->getByName("ScChartObj"), uno::UNO_QUERY_THROW); + return xChart; +} + +void ScChartObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChartObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scchartsobj.cxx b/sc/qa/extras/scchartsobj.cxx new file mode 100644 index 0000000000..0f5167de5f --- /dev/null +++ b/sc/qa/extras/scchartsobj.cxx @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/xtablecharts.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScChartsObj : public UnoApiTest, + public apitest::XEnumerationAccess, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XTableCharts +{ +public: + ScChartsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScChartsObj); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableCharts + CPPUNIT_TEST(testAddNewRemoveByName); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScChartsObj::ScChartsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XTableChart>::get()) + , XIndexAccess(1) + , XNameAccess("ScChartsObj") + , XServiceInfo("ScChartsObj", "com.sun.star.table.TableCharts") +{ +} + +uno::Reference<uno::XInterface> ScChartsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(1, 0)->setFormula("JAN"); + xSheet0->getCellByPosition(2, 0)->setFormula("FEB"); + xSheet0->getCellByPosition(3, 0)->setFormula("MAR"); + xSheet0->getCellByPosition(4, 0)->setFormula("APR"); + xSheet0->getCellByPosition(5, 0)->setFormula("MAY"); + xSheet0->getCellByPosition(6, 0)->setFormula("JUN"); + xSheet0->getCellByPosition(7, 0)->setFormula("JUL"); + xSheet0->getCellByPosition(8, 0)->setFormula("AUG"); + xSheet0->getCellByPosition(9, 0)->setFormula("SEP"); + xSheet0->getCellByPosition(10, 0)->setFormula("OCT"); + xSheet0->getCellByPosition(11, 0)->setFormula("NOV"); + xSheet0->getCellByPosition(12, 0)->setFormula("DEC"); + xSheet0->getCellByPosition(13, 0)->setFormula("SUM"); + + xSheet0->getCellByPosition(0, 1)->setFormula("Smith"); + xSheet0->getCellByPosition(1, 1)->setValue(42); + xSheet0->getCellByPosition(2, 1)->setValue(58.9); + xSheet0->getCellByPosition(3, 1)->setValue(-66.5); + xSheet0->getCellByPosition(4, 1)->setValue(43.4); + xSheet0->getCellByPosition(5, 1)->setValue(44.5); + xSheet0->getCellByPosition(6, 1)->setValue(45.3); + xSheet0->getCellByPosition(7, 1)->setValue(-67.3); + xSheet0->getCellByPosition(8, 1)->setValue(30.5); + xSheet0->getCellByPosition(9, 1)->setValue(23.2); + xSheet0->getCellByPosition(10, 1)->setValue(-97.3); + xSheet0->getCellByPosition(11, 1)->setValue(22.4); + xSheet0->getCellByPosition(11, 1)->setValue(23.5); + xSheet0->getCellByPosition(13, 1)->setFormula("SUM(B2:M2"); + + xSheet0->getCellByPosition(0, 2)->setFormula("Jones"); + xSheet0->getCellByPosition(1, 2)->setValue(21); + xSheet0->getCellByPosition(2, 2)->setValue(40.9); + xSheet0->getCellByPosition(3, 2)->setValue(-57.5); + xSheet0->getCellByPosition(4, 2)->setValue(-23.4); + xSheet0->getCellByPosition(5, 2)->setValue(34.5); + xSheet0->getCellByPosition(6, 2)->setValue(59.3); + xSheet0->getCellByPosition(7, 2)->setValue(27.3); + xSheet0->getCellByPosition(8, 2)->setValue(-38.5); + xSheet0->getCellByPosition(9, 2)->setValue(43.2); + xSheet0->getCellByPosition(10, 2)->setValue(57.3); + xSheet0->getCellByPosition(11, 2)->setValue(25.4); + xSheet0->getCellByPosition(11, 2)->setValue(28.5); + xSheet0->getCellByPosition(13, 2)->setFormula("SUM(B3:M3"); + + xSheet0->getCellByPosition(0, 3)->setFormula("Brown"); + xSheet0->getCellByPosition(1, 3)->setValue(31.45); + xSheet0->getCellByPosition(2, 3)->setValue(-20.9); + xSheet0->getCellByPosition(3, 3)->setValue(-117.5); + xSheet0->getCellByPosition(4, 3)->setValue(23.4); + xSheet0->getCellByPosition(5, 3)->setValue(-114.5); + xSheet0->getCellByPosition(6, 3)->setValue(115.3); + xSheet0->getCellByPosition(7, 3)->setValue(-171.3); + xSheet0->getCellByPosition(8, 3)->setValue(89.5); + xSheet0->getCellByPosition(9, 3)->setValue(41.2); + xSheet0->getCellByPosition(10, 3)->setValue(71.3); + xSheet0->getCellByPosition(11, 3)->setValue(25.4); + xSheet0->getCellByPosition(11, 3)->setValue(38.5); + xSheet0->getCellByPosition(13, 3)->setFormula("SUM(A4:L4"); + + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableCharts> xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartsObj", awt::Rectangle(500, 3000, 25000, 11000), + { xCRA->getRangeAddress() }, true, true); + + return xTC; +} + +void ScChartsObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChartsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccheck_data_pilot_field.cxx b/sc/qa/extras/sccheck_data_pilot_field.cxx new file mode 100644 index 0000000000..52cc344819 --- /dev/null +++ b/sc/qa/extras/sccheck_data_pilot_field.cxx @@ -0,0 +1,179 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <test/container/xnamed.hxx> +#include <test/beans/xpropertyset.hxx> +//check the DataPilot of Calc. + +using namespace css; +using namespace css::lang; + +namespace sc_apitest +{ +class CheckDataPilotField : public UnoApiTest, public apitest::XNamed, public apitest::XPropertySet +{ +public: + CheckDataPilotField(); + + virtual void setUp() override; + + uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(CheckDataPilotField); + + // _XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testGetPropertyValue); + + CPPUNIT_TEST_SUITE_END(); + +protected: + virtual bool isPropertyIgnored(const OUString& rName) override; + +private: + uno::Reference<uno::XInterface> mxObject; + int mMaxFieldIndex = 6; +}; + +bool CheckDataPilotField::isPropertyIgnored(const OUString& rName) +{ + return rName == "Function" || rName == "Subtotals" || rName == "Function2" + || rName == "Subtotals2"; +} + +CheckDataPilotField::CheckDataPilotField() + : UnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XNamed("Col1") +{ +} + +uno::Reference<uno::XInterface> CheckDataPilotField::init() +{ + // create a calc document + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + else + return mxObject; + + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + // the cell range + table::CellRangeAddress sCellRangeAddress; + sCellRangeAddress.Sheet = 0; + sCellRangeAddress.StartColumn = 1; + sCellRangeAddress.StartRow = 0; + sCellRangeAddress.EndColumn = mMaxFieldIndex - 1; + sCellRangeAddress.EndRow = mMaxFieldIndex - 1; + + // position of the data pilot table + table::CellAddress sCellAddress; + sCellAddress.Sheet = 0; + sCellAddress.Column = 7; + sCellAddress.Row = 8; + // Getting spreadsheet + uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets(); + uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW); + + // Per default there's now just one sheet, make sure we have at least two, then + xSpreadsheets->insertNewByName("Some Sheet", 0); + uno::Any aAny = oIndexAccess->getByIndex(0); + uno::Reference<sheet::XSpreadsheet> oSheet; + CPPUNIT_ASSERT(aAny >>= oSheet); + + uno::Any aAny2 = oIndexAccess->getByIndex(1); + uno::Reference<sheet::XSpreadsheet> oSheet2; + CPPUNIT_ASSERT(aAny2 >>= oSheet2); + + //Filling a table + for (int i = 1; i < mMaxFieldIndex; i++) + { + oSheet->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + oSheet2->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet2->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (int i = 1; i < mMaxFieldIndex; i++) + { + for (int j = 1; j < mMaxFieldIndex; j++) + { + oSheet->getCellByPosition(i, j)->setValue(i * (j + 1)); + oSheet2->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + // change a value of a cell and check the change in the data pilot + // cell of data + uno::Any oChangeCell; + oChangeCell <<= oSheet->getCellByPosition(1, 5); + int x = sCellAddress.Column; + int y = sCellAddress.Row + 3; + // cell of the data pilot output + uno::Any oCheckCell; + oCheckCell <<= oSheet->getCellByPosition(x, y); + // create the test objects + uno::Reference<sheet::XDataPilotTablesSupplier> DPTS(oSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> DPT = DPTS->getDataPilotTables(); + uno::Reference<sheet::XDataPilotDescriptor> DPDsc = DPT->createDataPilotDescriptor(); + DPDsc->setSourceRange(sCellRangeAddress); + + uno::Any oDataPilotField = DPDsc->getDataPilotFields()->getByIndex(0); + uno::Reference<beans::XPropertySet> fieldPropSet(oDataPilotField, uno::UNO_QUERY_THROW); + + uno::Any sum; + sum <<= sheet::GeneralFunction_SUM; + fieldPropSet->setPropertyValue("Function", sum); + + uno::Any data; + data <<= sheet::DataPilotFieldOrientation_DATA; + fieldPropSet->setPropertyValue("Orientation", data); + + //Insert the DataPilotTable + if (DPT->hasByName("DataPilotField")) + DPT->removeByName("DataPilotField"); + DPT->insertNewByName("DataPilotTField", sCellAddress, DPDsc); + + uno::Reference<container::XIndexAccess> IA = DPDsc->getDataPilotFields(); + uno::Reference<uno::XInterface> xDataPilotFieldObject; + data = IA->getByIndex(0); + CPPUNIT_ASSERT(data >>= xDataPilotFieldObject); + mxObject = xDataPilotFieldObject; + + return xDataPilotFieldObject; +} + +void CheckDataPilotField::setUp() +{ + UnoApiTest::setUp(); + init(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckDataPilotField); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/sccheck_data_pilot_table.cxx b/sc/qa/extras/sccheck_data_pilot_table.cxx new file mode 100644 index 0000000000..92494fb583 --- /dev/null +++ b/sc/qa/extras/sccheck_data_pilot_table.cxx @@ -0,0 +1,182 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <test/container/xnamed.hxx> +#include <test/sheet/xdatapilottable.hxx> +#include <test/sheet/xdatapilotdescriptor.hxx> +#include <test/beans/xpropertyset.hxx> +//check the DataPilot of Calc. + +using namespace css; +using namespace css::lang; + +namespace sc_apitest +{ +class CheckDataPilotTable : public UnoApiTest, + public apitest::XNamed, + public apitest::XDataPilotTable, + public apitest::XPropertySet, + public apitest::XDataPilotDescriptor +{ +public: + CheckDataPilotTable(); + + virtual void setUp() override; + + uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(CheckDataPilotTable); + // _XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // _XDataPilotTable + CPPUNIT_TEST(testGetOutputRange); + + // _XDataPilotDescriptor + CPPUNIT_TEST(testTag); + CPPUNIT_TEST(testGetFilterDescriptor); + CPPUNIT_TEST(testGetDataPilotFields); + CPPUNIT_TEST(testGetColumnFields); + CPPUNIT_TEST(testGetRowFields); + // CPPUNIT_TEST(testGetDataFields); + // CPPUNIT_TEST(testGetHiddenFields); + CPPUNIT_TEST(testGetPageFields); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<uno::XInterface> mxObject; + static constexpr int MAX_FIELD_INDEX = 6; +}; + +CheckDataPilotTable::CheckDataPilotTable() + : UnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XNamed("DataPilotTable") +{ +} + +uno::Reference<uno::XInterface> CheckDataPilotTable::init() +{ + // create a calc document + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + else + return mxObject; + + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + // the cell range + table::CellRangeAddress sCellRangeAddress; + sCellRangeAddress.Sheet = 0; + sCellRangeAddress.StartColumn = 1; + sCellRangeAddress.StartRow = 0; + sCellRangeAddress.EndColumn = MAX_FIELD_INDEX - 1; + sCellRangeAddress.EndRow = MAX_FIELD_INDEX - 1; + + // position of the data pilot table + table::CellAddress sCellAddress; + sCellAddress.Sheet = 0; + sCellAddress.Column = 7; + sCellAddress.Row = 8; + // Getting spreadsheet + uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets(); + uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW); + + // Per default there's now just one sheet, make sure we have at least two, then + xSpreadsheets->insertNewByName("Some Sheet", 0); + uno::Any aAny = oIndexAccess->getByIndex(0); + uno::Reference<sheet::XSpreadsheet> oSheet; + CPPUNIT_ASSERT(aAny >>= oSheet); + + uno::Any aAny2 = oIndexAccess->getByIndex(1); + uno::Reference<sheet::XSpreadsheet> oSheet2; + CPPUNIT_ASSERT(aAny2 >>= oSheet2); + + //Filling a table + for (int i = 1; i < MAX_FIELD_INDEX; i++) + { + oSheet->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + oSheet2->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet2->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (int i = 1; i < MAX_FIELD_INDEX; i++) + { + for (int j = 1; j < MAX_FIELD_INDEX; j++) + { + oSheet->getCellByPosition(i, j)->setValue(i * (j + 1)); + oSheet2->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + // change a value of a cell and check the change in the data pilot + // cell of data + uno::Any oChangeCell; + oChangeCell <<= oSheet->getCellByPosition(1, 5); + int x = sCellAddress.Column; + int y = sCellAddress.Row + 3; + // cell of the data pilot output + uno::Any oCheckCell; + oCheckCell <<= oSheet->getCellByPosition(x, y); + // create the test objects + uno::Reference<sheet::XDataPilotTablesSupplier> DPTS(oSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> DPT = DPTS->getDataPilotTables(); + uno::Reference<sheet::XDataPilotDescriptor> DPDsc = DPT->createDataPilotDescriptor(); + DPDsc->setSourceRange(sCellRangeAddress); + + uno::Any oDataPilotField = DPDsc->getDataPilotFields()->getByIndex(0); + uno::Reference<beans::XPropertySet> fieldPropSet(oDataPilotField, uno::UNO_QUERY_THROW); + + uno::Any sum; + sum <<= sheet::GeneralFunction_SUM; + fieldPropSet->setPropertyValue("Function", sum); + + uno::Any data; + data <<= sheet::DataPilotFieldOrientation_DATA; + fieldPropSet->setPropertyValue("Orientation", data); + + //Insert the DataPilotTable + if (DPT->hasByName("DataPilotTable")) + DPT->removeByName("DataPilotTable"); + DPT->insertNewByName("DataPilotTable", sCellAddress, DPDsc); + + uno::Reference<uno::XInterface> xDataPilotTableObject; + data = DPT->getByName(DPT->getElementNames()[0]); + CPPUNIT_ASSERT(data >>= xDataPilotTableObject); + mxObject = xDataPilotTableObject; + + return xDataPilotTableObject; +} + +void CheckDataPilotTable::setUp() +{ + UnoApiTest::setUp(); + init(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckDataPilotTable); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/sccheck_xcell_ranges_query.cxx b/sc/qa/extras/sccheck_xcell_ranges_query.cxx new file mode 100644 index 0000000000..f0de7f7def --- /dev/null +++ b/sc/qa/extras/sccheck_xcell_ranges_query.cxx @@ -0,0 +1,179 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/container/XNamed.hpp> + +using namespace css; +using namespace css::lang; + +namespace sc_apitest +{ +class CheckXCellRangesQuery : public UnoApiTest +{ +public: + CheckXCellRangesQuery(); + + virtual void setUp() override; + + uno::Reference<uno::XInterface> init(); + void checkEmptyCell(); + void checkFilledCell(); + + void _queryColumnDifferences(const OUString& expected); + void _queryRowDifferences(const OUString& expected); + void _queryEmptyCells(const OUString& expected); + + CPPUNIT_TEST_SUITE(CheckXCellRangesQuery); + CPPUNIT_TEST(checkEmptyCell); + CPPUNIT_TEST(checkFilledCell); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<sheet::XCellRangesQuery> m_xCell; + OUString sSheetName; +}; + +CheckXCellRangesQuery::CheckXCellRangesQuery() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> CheckXCellRangesQuery::init() +{ + // create a calc document + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + // Getting spreadsheet + uno::Reference<sheet::XSpreadsheets> oSheets = xSheetDoc->getSheets(); + uno::Reference<container::XIndexAccess> oIndexSheets(oSheets, uno::UNO_QUERY_THROW); + uno::Any aAny = oIndexSheets->getByIndex(0); + uno::Reference<container::XNamed> xNamed; + CPPUNIT_ASSERT(aAny >>= xNamed); + sSheetName = xNamed->getName(); + + // get the cell + uno::Reference<sheet::XSpreadsheet> xSpreadSheet; + CPPUNIT_ASSERT(aAny >>= xSpreadSheet); + uno::Reference<uno::XInterface> oObj = xSpreadSheet->getCellByPosition(2, 3); + m_xCell = uno::Reference<sheet::XCellRangesQuery>(oObj, uno::UNO_QUERY_THROW); + + // set one value for comparison. + xSpreadSheet->getCellByPosition(1, 1)->setValue(15); + xSpreadSheet->getCellByPosition(1, 3)->setValue(5); + xSpreadSheet->getCellByPosition(2, 1)->setFormula("=B2+B4"); + + return xSpreadSheet; +} + +/** + * Perform some tests on an empty cell: + * <ol> + * <li>compare an empty cell with a cell with a value in the same column</li> + * <li>compare an empty cell with a cell with a value in the same row</li> + * <li>query for empty cells</li> + * <ol> + */ +void CheckXCellRangesQuery::checkEmptyCell() +{ + // compare an empty cell with a cell with a value + _queryColumnDifferences(sSheetName + ".C4"); + // compare an empty cell with a cell with a value + _queryRowDifferences(sSheetName + ".C4"); +} + +/** + * Perform some tests on a filled cell: + * <ol> + * <li>compare a cell with value 5 with a cell with value 15 in the same + * column</li> + * <li>compare a cell with value 5 with a cell with value 15 in the same + * row</li> + * <li>query for an empty cell.</li> + * <ol> + */ + +void CheckXCellRangesQuery::checkFilledCell() +{ + uno::Reference<sheet::XSpreadsheet> xSpreadSheet(init(), uno::UNO_QUERY_THROW); + // fill the cell with a value + xSpreadSheet->getCellByPosition(2, 3)->setValue(15); + + // compare a cell with value 5 with a cell with value 15 + _queryColumnDifferences(sSheetName + ".C4"); + // compare a cell with value 5 with a cell with value 15 + _queryRowDifferences(sSheetName + ".C4"); + // try to get nothing + _queryEmptyCells(""); +} + +/** + * Query column differences between my cell(2,3) and (1,1). + * + * @param expected The expected outcome value. + */ +void CheckXCellRangesQuery::_queryColumnDifferences(const OUString& expected) +{ + //Query column differences + uno::Reference<sheet::XSheetCellRanges> ranges + = m_xCell->queryColumnDifferences(table::CellAddress(0, 1, 1)); + OUString getting = ranges->getRangeAddressesAsString(); + + CPPUNIT_ASSERT_EQUAL(expected, getting); +} + +/** + * Query for an empty cell. + * + * @param expected The expected outcome value. + */ +void CheckXCellRangesQuery::_queryEmptyCells(const OUString& expected) +{ + //Query empty cells + uno::Reference<sheet::XSheetCellRanges> ranges = m_xCell->queryEmptyCells(); + OUString getting = ranges->getRangeAddressesAsString(); + + CPPUNIT_ASSERT_EQUAL(expected, getting); +} + +/** + * Query row differences between my cell(2,3) and (1,1). + * + * @param expected The expected outcome value. + */ +void CheckXCellRangesQuery::_queryRowDifferences(const OUString& expected) +{ + //Query row differences + uno::Reference<sheet::XSheetCellRanges> ranges + = m_xCell->queryRowDifferences(table::CellAddress(0, 1, 1)); + OUString getting = ranges->getRangeAddressesAsString(); + + CPPUNIT_ASSERT_EQUAL(expected, getting); +} + +void CheckXCellRangesQuery::setUp() +{ + UnoApiTest::setUp(); + init(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckXCellRangesQuery); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/scconsolidationdescriptorobj.cxx b/sc/qa/extras/scconsolidationdescriptorobj.cxx new file mode 100644 index 0000000000..eb0392d878 --- /dev/null +++ b/sc/qa/extras/scconsolidationdescriptorobj.cxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/xconsolidationdescriptor.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XConsolidatable.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScConsolidationDescriptorObj : public UnoApiTest, public apitest::XConsolidationDescriptor +{ +public: + ScConsolidationDescriptorObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScConsolidationDescriptorObj); + + // XConsolidationDescriptor + CPPUNIT_TEST(testGetFunction); + CPPUNIT_TEST(testSetFunction); + CPPUNIT_TEST(testGetSources); + CPPUNIT_TEST(testSetSources); + CPPUNIT_TEST(testGetStartOutputPosition); + CPPUNIT_TEST(testSetStartOutputPosition); + CPPUNIT_TEST(testGetUseColumnHeaders); + CPPUNIT_TEST(testSetUseColumnHeaders); + CPPUNIT_TEST(testGetUseRowHeaders); + CPPUNIT_TEST(testSetUseRowHeaders); + CPPUNIT_TEST(testGetInsertLinks); + CPPUNIT_TEST(testSetInsertLinks); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScConsolidationDescriptorObj::ScConsolidationDescriptorObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScConsolidationDescriptorObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XConsolidatable> xConsolidatable(xDoc, UNO_QUERY_THROW); + return xConsolidatable->createConsolidationDescriptor(true); +} + +void ScConsolidationDescriptorObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScConsolidationDescriptorObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatabaserangeobj.cxx b/sc/qa/extras/scdatabaserangeobj.cxx new file mode 100644 index 0000000000..4ddc137e4b --- /dev/null +++ b/sc/qa/extras/scdatabaserangeobj.cxx @@ -0,0 +1,109 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/sheet/databaserange.hxx> +#include <test/sheet/xcellrangereferrer.hxx> +#include <test/sheet/xdatabaserange.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScDatabaseRangeObj : public UnoApiTest, + public apitest::DatabaseRange, + public apitest::XCellRangeReferrer, + public apitest::XDatabaseRange +{ +public: + virtual void setUp() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > init( const OUString& rDBName ) override; + + ScDatabaseRangeObj(); + + CPPUNIT_TEST_SUITE(ScDatabaseRangeObj); + + // DatabaseRange + CPPUNIT_TEST(testMoveCells); + CPPUNIT_TEST(testKeepFormats); + CPPUNIT_TEST(testStripData); + CPPUNIT_TEST(testAutoFilter); + CPPUNIT_TEST(testUseFilterCriteriaSource); + CPPUNIT_TEST(testFilterCriteriaSource); + CPPUNIT_TEST(testRefreshPeriod); + CPPUNIT_TEST(testFromSelection); + CPPUNIT_TEST(testTokenIndex); + CPPUNIT_TEST(testTotalsRow); + CPPUNIT_TEST(testContainsHeader); + + // XCellRangeReferrer + CPPUNIT_TEST(testGetReferredCells); + + // XDatabaseRange + CPPUNIT_TEST(testDataArea); + CPPUNIT_TEST(testGetSortDescriptor); + CPPUNIT_TEST(testGetSubtotalDescriptor); + CPPUNIT_TEST(testGetImportDescriptor); + CPPUNIT_TEST(testGetFilterDescriptor); + CPPUNIT_TEST(testRefresh); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDatabaseRangeObj::ScDatabaseRangeObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScDatabaseRangeObj::init() +{ + return init("DataArea"); +} + +uno::Reference< uno::XInterface > ScDatabaseRangeObj::init( const OUString& rDBName ) +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< beans::XPropertySet > xPropSet(xDoc, UNO_QUERY_THROW); + uno::Reference< container::XNameAccess > xNameAccess( xPropSet->getPropertyValue("DatabaseRanges"), UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeReferrer> xCRR(xNameAccess->getByName(rDBName), UNO_QUERY_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRR->getReferredCells(), UNO_QUERY_THROW); + setCellRange(xCRA->getRangeAddress()); + + uno::Reference< sheet::XDatabaseRange > xDBRange( xNameAccess->getByName(rDBName), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDBRange.is()); + + return xDBRange; +} + +void ScDatabaseRangeObj::setUp() +{ + UnoApiTest::setUp(); + + loadFromFile(u"ScDatabaseRangeObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDatabaseRangeObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatabaserangesobj.cxx b/sc/qa/extras/scdatabaserangesobj.cxx new file mode 100644 index 0000000000..7926cb6ecf --- /dev/null +++ b/sc/qa/extras/scdatabaserangesobj.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xdatabaseranges.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDatabaseRangesObj : public UnoApiTest, + public apitest::XDatabaseRanges, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDatabaseRangesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDatabaseRangesObj); + + // XDatabaseRanges + CPPUNIT_TEST(testAddRemoveDbRanges); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDatabaseRangesObj::ScDatabaseRangesObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XDatabaseRange>::get()) + , XIndexAccess(1) + , XNameAccess("DbRange") + , XServiceInfo("ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges") +{ +} + +uno::Reference<uno::XInterface> ScDatabaseRangesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, UNO_QUERY_THROW); + uno::Reference<sheet::XDatabaseRanges> xDbRanges(xPropSet->getPropertyValue("DatabaseRanges"), + UNO_QUERY_THROW); + + if (!xDbRanges->hasByName("DbRange")) + xDbRanges->addNewByName("DbRange", table::CellRangeAddress(0, 2, 4, 5, 6)); + + return xDbRanges; +} + +void ScDatabaseRangesObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDatabaseRangesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldgroupitemobj.cxx b/sc/qa/extras/scdatapilotfieldgroupitemobj.cxx new file mode 100644 index 0000000000..09df41061b --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupitemobj.cxx @@ -0,0 +1,184 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <comphelper/types.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupItemObj : public UnoApiTest, + public apitest::XNamed, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupItemObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupItemObj); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; +}; + +ScDataPilotFieldGroupItemObj::ScDataPilotFieldGroupItemObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("aName") + , XServiceInfo("ScDataPilotFieldGroupItemObj", "com.sun.star.sheet.DataPilotFieldGroupItem") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldGroupItemObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 1)->setFormula("aName"); + xSheet0->getCellByPosition(1, 2)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 3)->setFormula("una"); + xSheet0->getCellByPosition(1, 4)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse"); + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet1->setPropertyValue("Function", uno::Any(sheet::GeneralFunction_SUM)); + xPropertySet1->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_DATA)); + + uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::Any(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + xDPFG->createNameGroup({ "aName", "otherName" }); + + uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<uno::XInterface> xReturn(xNA_GN->getByName("aName"), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScDataPilotFieldGroupItemObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupItemObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatapilotfieldgroupobj.cxx b/sc/qa/extras/scdatapilotfieldgroupobj.cxx new file mode 100644 index 0000000000..2e54f1c236 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupobj.cxx @@ -0,0 +1,209 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <comphelper/types.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNamed, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; +}; + +ScDataPilotFieldGroupObj::ScDataPilotFieldGroupObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNamed>::get()) + , XIndexAccess(2) + , XNameAccess("aName") + , XNamed("Group1") + , XServiceInfo("ScDataPilotFieldGroupObj", "com.sun.star.sheet.DataPilotFieldGroup") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldGroupObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 1)->setFormula("aName"); + xSheet0->getCellByPosition(1, 2)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 3)->setFormula("una"); + xSheet0->getCellByPosition(1, 4)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse"); + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet1->setPropertyValue("Function", uno::Any(sheet::GeneralFunction_SUM)); + xPropertySet1->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_DATA)); + + uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::Any(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + xDPFG->createNameGroup({ "aName", "otherName" }); + + uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW); + + return xNA_GN; +} + +void ScDataPilotFieldGroupObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldgroupsobj.cxx b/sc/qa/extras/scdatapilotfieldgroupsobj.cxx new file mode 100644 index 0000000000..485fc7d28a --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupsobj.cxx @@ -0,0 +1,214 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <comphelper/types.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameEmptyName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; +}; + +ScDataPilotFieldGroupsObj::ScDataPilotFieldGroupsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNameAccess>::get()) + , XIndexAccess(1) + , XNameAccess("Group1") + , XNameContainer("Group1") + , XServiceInfo("ScDataPilotFieldGroupsObj", "com.sun.star.sheet.DataPilotFieldGroups") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldGroupsObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 1)->setFormula("aName"); + xSheet0->getCellByPosition(1, 2)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 3)->setFormula("una"); + xSheet0->getCellByPosition(1, 4)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse"); + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet1->setPropertyValue("Function", uno::Any(sheet::GeneralFunction_SUM)); + xPropertySet1->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_DATA)); + + uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::Any(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + xDPFG->createNameGroup({ "aName", "otherName" }); + + uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + // set element for testing XNameContainer::insertByName() + uno::Any aElement; + setElement(aElement); + + return aDPFGI.Groups; +} + +void ScDataPilotFieldGroupsObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldobj.cxx b/sc/qa/extras/scdatapilotfieldobj.cxx new file mode 100644 index 0000000000..789bc5a5ba --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldobj.cxx @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/datapilotfield.hxx> +#include <test/sheet/xdatapilotfield.hxx> +#include <test/sheet/xdatapilotfieldgrouping.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldObj : public UnoApiTest, + public apitest::DataPilotField, + public apitest::XDataPilotField, + public apitest::XDataPilotFieldGrouping, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + virtual void setUp() override; + virtual uno::Reference<uno::XInterface> init() override; + + ScDataPilotFieldObj(); + + CPPUNIT_TEST_SUITE(ScDataPilotFieldObj); + + // DataPilotField + CPPUNIT_TEST(testSortInfo); + CPPUNIT_TEST(testLayoutInfo); + CPPUNIT_TEST(testAutoShowInfo); + CPPUNIT_TEST(testReference); + CPPUNIT_TEST(testIsGroupField); + + // XDataPilotField + CPPUNIT_TEST(testGetItems); + + // XDataPilotFieldGrouping + CPPUNIT_TEST(testCreateNameGroup); + // see fdo# + //CPPUNIT_TEST(testCreateDateGroup); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDataPilotFieldObj::ScDataPilotFieldObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("Col1") + , XPropertySet({ "Function", "HasAutoShowInfo", "HasLayoutInfo", "HasSortInfo", "Subtotals", + "Subtotals2" }) + , XServiceInfo("ScDataPilotFieldObj", "com.sun.star.sheet.DataPilotField") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(1), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + (void)xDPT->getElementNames(); + + uno::Reference<sheet::XDataPilotDescriptor> xDPDsc(xDPT->getByName("DataPilot1"), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDPDsc->getDataPilotFields(), uno::UNO_SET_THROW); + uno::Reference<uno::XInterface> xReturnValue(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + return xReturnValue; +} + +void ScDataPilotFieldObj::setUp() +{ + UnoApiTest::setUp(); + + loadFromFile(u"scdatapilotfieldobj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldsobj.cxx b/sc/qa/extras/scdatapilotfieldsobj.cxx new file mode 100644 index 0000000000..4320dbd311 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldsobj.cxx @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <cppu/unotype.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +namespace sc_apitest +{ +class ScDataPilotFieldsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldsObj(); + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldsObj); + + // XElementAccess + CPPUNIT_TEST(testHasElements); + CPPUNIT_TEST(testGetElementType); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDataPilotFieldsObj::ScDataPilotFieldsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(6) + , XNameAccess("") + , XServiceInfo("ScDataPilotFieldsObj", "com.sun.star.sheet.DataPilotFields") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + for (int i = 1; i < 4; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (int i = 1; i < 4; ++i) + { + for (int j = 1; j < 4; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + } + } + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + return xDPD->getDataPilotFields(); +} + +void ScDataPilotFieldsObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotitemobj.cxx b/sc/qa/extras/scdatapilotitemobj.cxx new file mode 100644 index 0000000000..46a45b47bd --- /dev/null +++ b/sc/qa/extras/scdatapilotitemobj.cxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/datapilotitem.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotField.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotItemObj : public UnoApiTest, public apitest::DataPilotItem, public apitest::XNamed +{ +public: + virtual void setUp() override; + virtual uno::Reference<uno::XInterface> init() override; + + ScDataPilotItemObj(); + + CPPUNIT_TEST_SUITE(ScDataPilotItemObj); + + // DataPilotItem + CPPUNIT_TEST(testProperties); + + // XNamed + CPPUNIT_TEST(testGetName); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; +}; + +ScDataPilotItemObj::ScDataPilotItemObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("2") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotItemObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; i++) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; i++) + for (auto j = 1; j < m_nMaxFieldIndex; j++) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xDataPilotFieldProp( + xDPD->getDataPilotFields()->getByIndex(0), uno::UNO_QUERY_THROW); + xDataPilotFieldProp->setPropertyValue("Function", uno::Any(sheet::GeneralFunction_SUM)); + xDataPilotFieldProp->setPropertyValue("Orientation", + uno::Any(sheet::DataPilotFieldOrientation_DATA)); + + if (xDPT->hasByName("DataPilotTable")) + xDPT->removeByName("DataPilotTable"); + + uno::Reference<container::XIndexAccess> xIA_DPF(xDPD->getDataPilotFields(), uno::UNO_SET_THROW); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + uno::Reference<sheet::XDataPilotField> xDPF(xIA_DPF->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xDPF->getItems()->getByIndex(0), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScDataPilotItemObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotItemObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotitemsobj.cxx b/sc/qa/extras/scdatapilotitemsobj.cxx new file mode 100644 index 0000000000..550a0fcf0e --- /dev/null +++ b/sc/qa/extras/scdatapilotitemsobj.cxx @@ -0,0 +1,156 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotField.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotItemsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotItemsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDataPilotItemsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; +}; + +ScDataPilotItemsObj::ScDataPilotItemsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(5) + , XNameAccess("2") + , XServiceInfo("ScDataPilotItemsObj", "com.sun.star.sheet.DataPilotItems") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotItemsObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet->setPropertyValue("Function", uno::Any(sheet::GeneralFunction_SUM)); + xPropertySet->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_DATA)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPF(xDPD->getDataPilotFields(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotField> xDPF(xIA_DPF->getByIndex(0), uno::UNO_QUERY_THROW); + + return xDPF->getItems(); +} + +void ScDataPilotItemsObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotItemsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatapilottableobj.cxx b/sc/qa/extras/scdatapilottableobj.cxx new file mode 100644 index 0000000000..e0c66269f5 --- /dev/null +++ b/sc/qa/extras/scdatapilottableobj.cxx @@ -0,0 +1,143 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/xdatapilotdescriptor.hxx> +#include <test/sheet/xdatapilottable.hxx> +#include <test/sheet/xdatapilottable2.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTable.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScDataPilotTableObj : public UnoApiTest, + public apitest::XDataPilotDescriptor, + public apitest::XDataPilotTable, + public apitest::XDataPilotTable2, + public apitest::XNamed +{ +public: + ScDataPilotTableObj(); + + virtual void setUp() override; + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > initDP2() override; + virtual uno::Reference< uno::XInterface > getSheets() override; + + CPPUNIT_TEST_SUITE(ScDataPilotTableObj); + + // XDataPilotDescriptor + CPPUNIT_TEST(testSourceRange); + CPPUNIT_TEST(testTag); + CPPUNIT_TEST(testGetFilterDescriptor); + CPPUNIT_TEST(testGetDataPilotFields); + CPPUNIT_TEST(testGetColumnFields); + CPPUNIT_TEST(testGetRowFields); + CPPUNIT_TEST(testGetPageFields); + CPPUNIT_TEST(testGetDataFields); + //CPPUNIT_TEST(testGetHiddenFields); + + // XDataPilotTable + CPPUNIT_TEST(testGetOutputRange); + CPPUNIT_TEST(testRefresh); + + // XDataPilotTable2 + CPPUNIT_TEST(testGetDrillDownData); + CPPUNIT_TEST(testInsertDrillDownSheet); + CPPUNIT_TEST(testGetPositionData); + CPPUNIT_TEST(testGetOutputRangeByType); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDataPilotTableObj::ScDataPilotTableObj() + : UnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XNamed("DataPilotTable") +{ +} + +uno::Reference< uno::XInterface > ScDataPilotTableObj::init() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + // set variables from xdatapilottable.[ch]xx + xCellForChange = xSheet->getCellByPosition( 1, 5 ); + xCellForCheck = xSheet->getCellByPosition( 7, 11 ); + CPPUNIT_ASSERT(xCellForCheck.is()); + CPPUNIT_ASSERT(xCellForChange.is()); + + CPPUNIT_ASSERT_MESSAGE("Could not create interface of type XSpreadsheet", xSheet.is()); + uno::Reference< sheet::XDataPilotTablesSupplier > xDPTS(xSheet, UNO_QUERY_THROW); + uno::Reference< sheet::XDataPilotTables > xDPT = xDPTS->getDataPilotTables(); + CPPUNIT_ASSERT(xDPT.is()); + + uno::Reference< sheet::XDataPilotTable > xDPTable(xDPT->getByName("DataPilotTable"),UNO_QUERY_THROW); + + return xDPTable; +} + +uno::Reference< uno::XInterface > ScDataPilotTableObj::getSheets() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference< uno::XInterface > xSheets(xDoc->getSheets()); + return xSheets; +} + +uno::Reference< uno::XInterface > ScDataPilotTableObj::initDP2() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + // set variables from xdatapilottable.[ch]xx + xCellForChange = xSheet->getCellByPosition( 1, 5 ); + xCellForCheck = xSheet->getCellByPosition( 7, 11 ); + CPPUNIT_ASSERT(xCellForCheck.is()); + CPPUNIT_ASSERT(xCellForChange.is()); + + CPPUNIT_ASSERT_MESSAGE("Could not create interface of type XSpreadsheet", xSheet.is()); + uno::Reference< sheet::XDataPilotTablesSupplier > xDPTS(xSheet, UNO_QUERY_THROW); + uno::Reference< sheet::XDataPilotTables > xDPT = xDPTS->getDataPilotTables(); + CPPUNIT_ASSERT(xDPT.is()); + + uno::Reference< sheet::XDataPilotTable > xDPTable(xDPT->getByName("DataPilotTable2"),UNO_QUERY_THROW); + + return xDPTable; +} + +void ScDataPilotTableObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + loadFromFile(u"ScDataPilotTableObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotTableObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatapilottablesobj.cxx b/sc/qa/extras/scdatapilottablesobj.cxx new file mode 100644 index 0000000000..faa9c5f0f5 --- /dev/null +++ b/sc/qa/extras/scdatapilottablesobj.cxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xdatapilottables.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTable2.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDataPilotTablesObj : public UnoApiTest, + public apitest::XDataPilotTables, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotTablesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDataPilotTablesObj); + + // XDataPilotTables + CPPUNIT_TEST(testXDataPilotTables); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDataPilotTablesObj::ScDataPilotTablesObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XDataPilotTable2>::get()) + , XIndexAccess(1) + , XNameAccess("DataPilotTable") + , XServiceInfo("ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotTablesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + for (auto i = 1; i < 4; i++) + { + xSheet->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet, UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + UNO_SET_THROW); + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + return xDPT; +} + +uno::Reference<uno::XInterface> ScDataPilotTablesObj::getXSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + return xSheet; +} + +void ScDataPilotTablesObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotTablesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scddelinkobj.cxx b/sc/qa/extras/scddelinkobj.cxx new file mode 100644 index 0000000000..8f798beedd --- /dev/null +++ b/sc/qa/extras/scddelinkobj.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/xddelink.hxx> +#include <test/util/xrefreshable.hxx> + +#include <unotools/tempfile.hxx> +#include <vcl/svapp.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDDELink.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDDELinkObj : public UnoApiTest, + public apitest::XDDELink, + public apitest::XNamed, + public apitest::XRefreshable +{ +public: + ScDDELinkObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDDELinkObj); + + // XDDELink + CPPUNIT_TEST(testGetApplication); + CPPUNIT_TEST(testGetItem); + CPPUNIT_TEST(testGetTopic); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetNameThrowsException); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDDELinkObj::ScDDELinkObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XDDELink(maTempFile.GetURL()) + , XNamed("soffice|" + maTempFile.GetURL() + "!Sheet1.A1") +{ +} + +uno::Reference<uno::XInterface> ScDDELinkObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + + const OUString testdoc = maTempFile.GetURL(); + + xSheet->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + xSheet->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, UNO_QUERY_THROW); + uno::Any aDDELinks = xPropSet->getPropertyValue("DDELinks"); + uno::Reference<container::XNameAccess> xNA(aDDELinks, UNO_QUERY_THROW); + uno::Sequence<OUString> sLinkNames = xNA->getElementNames(); + uno::Reference<sheet::XDDELink> xDDELink(xNA->getByName(sLinkNames[0]), UNO_QUERY_THROW); + return xDDELink; +} + +void ScDDELinkObj::setUp() +{ + Application::SetAppName("soffice"); // Enable DDE + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); + + createTempCopy(u"ScDDELinksObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinkObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scddelinksobj.cxx b/sc/qa/extras/scddelinksobj.cxx new file mode 100644 index 0000000000..6a3a843ca9 --- /dev/null +++ b/sc/qa/extras/scddelinksobj.cxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xddelinks.hxx> + +#include <cppu/unotype.hxx> +#include <rtl/ustring.hxx> +#include <vcl/svapp.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDDELink.hpp> +#include <com/sun/star/sheet/XDDELinks.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDDELinksObj : public UnoApiTest, + public apitest::XDDELinks, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDDELinksObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDDELinksObj); + + // XDDELinks + CPPUNIT_TEST(testAddDDELink); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDDELinksObj::ScDDELinksObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XDDELinks(createFileURL(u"ScDDELinksObj.ods")) + , XElementAccess(cppu::UnoType<sheet::XDDELink>::get()) + , XIndexAccess(1) + , XNameAccess("soffice|" + createFileURL(u"ScDDELinksObj.ods") + "!Sheet1.A1") + , XServiceInfo("ScDDELinksObj", "com.sun.star.sheet.DDELinks") +{ +} + +uno::Reference<uno::XInterface> ScDDELinksObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + const OUString testdoc = createFileURL(u"ScDDELinksObj.ods"); + + xSheet->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + xSheet->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + xSheet->getCellByPosition(2, 0)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Any aDDELinks = xPropSet->getPropertyValue("DDELinks"); + uno::Reference<sheet::XDDELinks> xDDELinks(aDDELinks, uno::UNO_QUERY_THROW); + + return xDDELinks; +} + +void ScDDELinksObj::setUp() +{ + Application::SetAppName("soffice"); // Enable DDE + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinksObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdocumentconfigurationobj.cxx b/sc/qa/extras/scdocumentconfigurationobj.cxx new file mode 100644 index 0000000000..d5dbd0bf46 --- /dev/null +++ b/sc/qa/extras/scdocumentconfigurationobj.cxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/documentsettings.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDocumentConfigurationObj : public UnoApiTest, public apitest::DocumentSettings +{ +public: + ScDocumentConfigurationObj(); + + virtual uno::Reference<uno::XInterface> init() override; + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDocumentConfigurationObj); + + // DocumentSettings + CPPUNIT_TEST(testDocumentSettingsProperties); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDocumentConfigurationObj::ScDocumentConfigurationObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScDocumentConfigurationObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.DocumentSettings"); +} + +void ScDocumentConfigurationObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDocumentConfigurationObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdrawpageobj.cxx b/sc/qa/extras/scdrawpageobj.cxx new file mode 100644 index 0000000000..1899650d3e --- /dev/null +++ b/sc/qa/extras/scdrawpageobj.cxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/helper/shape.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/drawing/xshapegrouper.hxx> +#include <test/drawing/xshapes.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDrawPageObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo, + public apitest::XShapeGrouper, + public apitest::XShapes +{ +public: + ScDrawPageObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDrawPageObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XShapeGrouper + CPPUNIT_TEST(testGroup); + CPPUNIT_TEST(testUngroup); + + // XShapes + CPPUNIT_TEST(testAddRemove); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDrawPageObj::ScDrawPageObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<drawing::XShape>::get()) + , XIndexAccess(2) + , XServiceInfo("ScPageObj", "com.sun.star.sheet.SpreadsheetDrawPage") +{ +} + +uno::Reference<uno::XInterface> ScDrawPageObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + xDP->insertNewByIndex(0); + xDP->insertNewByIndex(1); + + uno::Reference<drawing::XDrawPage> xDrawPage(xDP->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShapes> xShapes(xDrawPage, uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XShape> xRectangle0( + apitest::helper::shape::createRectangle(mxComponent, 7500, 5000, 5000, 3500), + uno::UNO_SET_THROW); + xShapes->add(xRectangle0); + uno::Reference<drawing::XShape> xRectangle1( + apitest::helper::shape::createRectangle(mxComponent, 5000, 5000, 5000, 5500), + uno::UNO_SET_THROW); + xShapes->add(xRectangle1); + + // needed for XShapeGrouper tests + setDrawPage(xDrawPage); + // needed for XShapes tests + setShape(apitest::helper::shape::createLine(mxComponent, 7500, 10000, 5000, 3500)); + return xDrawPage; +} + +void ScDrawPageObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDrawPageObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdrawpagesobj.cxx b/sc/qa/extras/scdrawpagesobj.cxx new file mode 100644 index 0000000000..b63d4d1d57 --- /dev/null +++ b/sc/qa/extras/scdrawpagesobj.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/drawing/xdrawpages.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScDrawPagesObj : public UnoApiTest, + public apitest::XDrawPages, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo +{ +public: + ScDrawPagesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScDrawPagesObj); + + // XDrawPages + CPPUNIT_TEST(testInsertNewByIndex); + CPPUNIT_TEST(testRemove); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScDrawPagesObj::ScDrawPagesObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<drawing::XDrawPage>::get()) + , XIndexAccess(3) + , XServiceInfo("ScDrawPagesObj", "com.sun.star.drawing.DrawPages") +{ +} + +uno::Reference<uno::XInterface> ScDrawPagesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + + xDP->insertNewByIndex(1); + xDP->insertNewByIndex(2); + + return xDP; +} + +void ScDrawPagesObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDrawPagesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sceditfieldobj_cell.cxx b/sc/qa/extras/sceditfieldobj_cell.cxx new file mode 100644 index 0000000000..79dff2ae7b --- /dev/null +++ b/sc/qa/extras/sceditfieldobj_cell.cxx @@ -0,0 +1,211 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xcomponent.hxx> +#include <test/text/textcontent.hxx> +#include <test/text/xtextfield.hxx> +#include <test/text/xtextcontent.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScEditFieldObj_Cell : public UnoApiTest, + public apitest::TextContent, + public apitest::XComponent, + public apitest::XPropertySet, + public apitest::XTextContent, + public apitest::XTextField +{ +public: + ScEditFieldObj_Cell(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<text::XTextContent> getTextContent() override; + virtual uno::Reference<text::XTextRange> getTextRange() override; + virtual bool isAttachSupported() override { return true; } + virtual void triggerDesktopTerminate() override{}; + + void testEditFieldProperties(); + + CPPUNIT_TEST_SUITE(ScEditFieldObj_Cell); + + // TextContent + CPPUNIT_TEST(testTextContentProperties); + + // XComponent + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST(testDispose); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XTextField + CPPUNIT_TEST(testGetPresentation); + + // XTextContent + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAttach); + + // Tests specific to this service implementation. + CPPUNIT_TEST(testEditFieldProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + static uno::Reference<text::XTextField> mxField; +}; + +uno::Reference<text::XTextField> ScEditFieldObj_Cell::mxField; + +ScEditFieldObj_Cell::ScEditFieldObj_Cell() + : UnoApiTest("/sc/qa/extras/testdocuments") + , TextContent(text::TextContentAnchorType_AS_CHARACTER, + text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE, + text::WrapTextMode_NONE) +{ +} + +void ScEditFieldObj_Cell::setUp() +{ + UnoApiTest::setUp(); + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScEditFieldObj_Cell::tearDown() +{ + mxField.clear(); + UnoApiTest::tearDown(); +} + +namespace +{ +uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM) +{ + uno::Reference<text::XTextField> xField(xSM->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW); + xPropSet->setPropertyValue("Representation", uno::Any(OUString("LibreOffice"))); + xPropSet->setPropertyValue("URL", uno::Any(OUString("http://www.libreoffice.org/"))); + return xField; +} + +} // namespace + +uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init() +{ + // Return a field that's already in the cell. + if (!mxField.is()) + { + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + + // Create a new URL field object, and populate it with name and URL. + mxField = getNewField(xSM); + + // Insert this field into a cell. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + // Use cell A1 for this. + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xContent(mxField, uno::UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, false); + } + return mxField; +} + +uno::Reference<text::XTextContent> ScEditFieldObj_Cell::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + return uno::Reference<text::XTextContent>(getNewField(xSM), uno::UNO_QUERY_THROW); +} + +uno::Reference<text::XTextRange> ScEditFieldObj_Cell::getTextRange() +{ + // Use cell A2 for this. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW); + return xRange; +} + +void ScEditFieldObj_Cell::testEditFieldProperties() +{ + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + + { + // Test properties of date time field. + uno::Reference<text::XTextField> xField( + xSM->createInstance("com.sun.star.text.textfield.DateTime"), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); + CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is()); + + CPPUNIT_ASSERT_MESSAGE("Calc's date time field should have 'IsFixed' property.", + xInfo->hasPropertyByName("IsFixed")); + } + + { + // Test properties of document title field. + uno::Reference<text::XTextField> xField( + xSM->createInstance("com.sun.star.text.textfield.docinfo.Title"), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); + CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is()); + + CPPUNIT_ASSERT_MESSAGE("Calc's title field shouldn't have 'IsFixed' property.", + !xInfo->hasPropertyByName("IsFixed")); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Cell); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sceditfieldobj_header.cxx b/sc/qa/extras/sceditfieldobj_header.cxx new file mode 100644 index 0000000000..3c577836b6 --- /dev/null +++ b/sc/qa/extras/sceditfieldobj_header.cxx @@ -0,0 +1,171 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xcomponent.hxx> +#include <test/text/textcontent.hxx> +#include <test/text/xtextcontent.hxx> +#include <test/text/xtextfield.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScEditFieldObj_Header : public UnoApiTest, + public apitest::TextContent, + public apitest::XComponent, + public apitest::XPropertySet, + public apitest::XTextContent, + public apitest::XTextField +{ +public: + ScEditFieldObj_Header(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<text::XTextContent> getTextContent() override; + virtual uno::Reference<text::XTextRange> getTextRange() override; + virtual bool isAttachSupported() override { return false; } + virtual void triggerDesktopTerminate() override{}; + + CPPUNIT_TEST_SUITE(ScEditFieldObj_Header); + + // TextContent + CPPUNIT_TEST(testTextContentProperties); + + // XComponent + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST(testDispose); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XTextContent + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAttach); + + // XTextField + CPPUNIT_TEST(testGetPresentationEmptyString); + + CPPUNIT_TEST_SUITE_END(); + +private: + static uno::Reference<text::XTextField> mxField; + static uno::Reference<text::XText> mxRightText; +}; + +uno::Reference<text::XTextField> ScEditFieldObj_Header::mxField; +uno::Reference<text::XText> ScEditFieldObj_Header::mxRightText; + +ScEditFieldObj_Header::ScEditFieldObj_Header() + : UnoApiTest("/sc/qa/extras/testdocuments") + , TextContent(text::TextContentAnchorType_AS_CHARACTER, + text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE, + text::WrapTextMode_NONE) +{ +} + +void ScEditFieldObj_Header::setUp() +{ + UnoApiTest::setUp(); + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScEditFieldObj_Header::tearDown() +{ + // Clear these before the component is destroyed. This is important! + mxField.clear(); + mxRightText.clear(); + + UnoApiTest::tearDown(); +} + +uno::Reference<uno::XInterface> ScEditFieldObj_Header::init() +{ + // Return a field that's already in the header. + if (!mxField.is()) + { + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + + // Create a new URL field object, and populate it with name and URL. + mxField.set(xSM->createInstance("com.sun.star.text.TextField.Time"), uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xStyleFamilies(xSFS->getStyleFamilies(), + uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xPageStyles->getByName("Default"), + uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( + xPropSet->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW); + + // Use the left header text. + uno::Reference<text::XText> xText = xHeaderContent->getLeftText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xContent(mxField, uno::UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, false); + + xPropSet->setPropertyValue("RightPageHeaderContent", uno::Any(xHeaderContent)); + + mxRightText = xHeaderContent->getRightText(); + } + + return mxField; +} + +uno::Reference<text::XTextContent> ScEditFieldObj_Header::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xField( + xSM->createInstance("com.sun.star.text.TextField.Date"), uno::UNO_QUERY_THROW); + return xField; +} + +uno::Reference<text::XTextRange> ScEditFieldObj_Header::getTextRange() +{ + // Use the right header text for this. + uno::Reference<text::XTextRange> xRange(mxRightText, uno::UNO_QUERY_THROW); + return xRange; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scfilterdescriptorbase.cxx b/sc/qa/extras/scfilterdescriptorbase.cxx new file mode 100644 index 0000000000..fead15e96d --- /dev/null +++ b/sc/qa/extras/scfilterdescriptorbase.cxx @@ -0,0 +1,112 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/sheetfilterdescriptor.hxx> +#include <test/sheet/xsheetfilterdescriptor.hxx> +#include <test/sheet/xsheetfilterdescriptor2.hxx> +#include <test/sheet/xsheetfilterdescriptor3.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetFilterable.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScFilterDescriptorBase : public UnoApiTest, + public apitest::SheetFilterDescriptor, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XSheetFilterDescriptor, + public apitest::XSheetFilterDescriptor2, + public apitest::XSheetFilterDescriptor3 +{ +public: + ScFilterDescriptorBase(); + + virtual void setUp() override; + + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScFilterDescriptorBase); + + // SheetFilterDescriptor + CPPUNIT_TEST(testSheetFilterDescriptorProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetFilterDescriptor + CPPUNIT_TEST(testGetSetFilterFields); + + // XSheetFilterDescriptor2 + CPPUNIT_TEST(testGetSetFilterFields2); + + // XSheetFilterDescriptor3 + CPPUNIT_TEST(testGetSetFilterFields3); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScFilterDescriptorBase::ScFilterDescriptorBase() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "Orientation", "OutputPosition" }) + , XServiceInfo("ScFilterDescriptorBase", "com.sun.star.sheet.SheetFilterDescriptor") +{ +} + +uno::Reference<uno::XInterface> ScFilterDescriptorBase::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndexAccess(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<sheet::XSheetFilterable> xSF(xSheet, uno::UNO_QUERY_THROW); + + return xSF->createFilterDescriptor(true); +} + +void ScFilterDescriptorBase::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScFilterDescriptorBase); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scfunctiondescriptionobj.cxx b/sc/qa/extras/scfunctiondescriptionobj.cxx new file mode 100644 index 0000000000..01b8d36572 --- /dev/null +++ b/sc/qa/extras/scfunctiondescriptionobj.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/functiondescription.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XFunctionDescriptions.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScFunctionDescriptionObj : public UnoApiTest, public apitest::FunctionDescription +{ +public: + ScFunctionDescriptionObj(); + + virtual uno::Sequence<beans::PropertyValue> init() override; + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScFunctionDescriptionObj); + + // FunctionDescription + CPPUNIT_TEST(testFunctionDescriptionProperties); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScFunctionDescriptionObj::ScFunctionDescriptionObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Sequence<beans::PropertyValue> ScFunctionDescriptionObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + uno::Reference<sheet::XFunctionDescriptions> xFDs( + xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"), UNO_QUERY_THROW); + + uno::Reference<container::XNameAccess> xNA(xFDs, UNO_QUERY_THROW); + uno::Sequence<OUString> names = xNA->getElementNames(); + + uno::Sequence<beans::PropertyValue> sPropertyValues; + CPPUNIT_ASSERT(xNA->getByName(names[0]) >>= sPropertyValues); + return sPropertyValues; +} + +void ScFunctionDescriptionObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScFunctionDescriptionObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scfunctionlistobj.cxx b/sc/qa/extras/scfunctionlistobj.cxx new file mode 100644 index 0000000000..940aba8c39 --- /dev/null +++ b/sc/qa/extras/scfunctionlistobj.cxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xfunctiondescriptions.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScFunctionListObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XFunctionDescriptions, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScFunctionListObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScFunctionListObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XFunctionDescriptions + CPPUNIT_TEST(testGetById); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScFunctionListObj::ScFunctionListObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get()) + , XIndexAccess(395) + , XNameAccess("IF") + , XServiceInfo("stardiv.StarCalc.ScFunctionListObj", "com.sun.star.sheet.FunctionDescriptions") +{ +} + +uno::Reference<uno::XInterface> ScFunctionListObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"); +} + +void ScFunctionListObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScFunctionListObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scheaderfieldsobj.cxx b/sc/qa/extras/scheaderfieldsobj.cxx new file mode 100644 index 0000000000..93b1629587 --- /dev/null +++ b/sc/qa/extras/scheaderfieldsobj.cxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScHeaderFieldsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XRefreshable +{ +public: + ScHeaderFieldsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScHeaderFieldsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + // We need a long living reference to css::text::XText to make the + // XElementAccess::hasElements() test work as ScHeaderFooterEditSource holds + // only (weak) references and they sometimes are gone. + static uno::Reference<text::XText> m_xText; +}; + +uno::Reference<text::XText> ScHeaderFieldsObj::m_xText; + +ScHeaderFieldsObj::ScHeaderFieldsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , ::apitest::XElementAccess(cppu::UnoType<text::XTextField>::get()) +{ +} + +uno::Reference<uno::XInterface> ScHeaderFieldsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA1(xNA->getByName("PageStyles"), uno::UNO_QUERY_THROW); + uno::Reference<style::XStyle> xStyle(xNA1->getByName("Default"), uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XHeaderFooterContent> xHFC( + xPropertySet->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW); + m_xText = xHFC->getLeftText(); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xTC(xMSF->createInstance("com.sun.star.text.TextField.Time"), + uno::UNO_QUERY_THROW); + m_xText->insertTextContent(m_xText->createTextCursor(), xTC, false); + xPropertySet->setPropertyValue("RightPageHeaderContent", uno::Any(xHFC)); + + uno::Reference<text::XTextFieldsSupplier> xTFS(m_xText, uno::UNO_QUERY_THROW); + return xTFS->getTextFields(); +} + +void ScHeaderFieldsObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScHeaderFieldsObj::tearDown() +{ + m_xText.clear(); + + UnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScHeaderFieldsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scheaderfootercontentobj.cxx b/sc/qa/extras/scheaderfootercontentobj.cxx new file mode 100644 index 0000000000..24efb2c56b --- /dev/null +++ b/sc/qa/extras/scheaderfootercontentobj.cxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/xheaderfootercontent.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScHeaderFooterContentObj : public UnoApiTest, public apitest::XHeaderFooterContent +{ +public: + ScHeaderFooterContentObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScHeaderFooterContentObj); + + // XHeaderFooterContent + CPPUNIT_TEST(testGetCenterText); + CPPUNIT_TEST(testGetLeftText); + CPPUNIT_TEST(testGetRightText); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScHeaderFooterContentObj::ScHeaderFooterContentObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScHeaderFooterContentObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamSupp(xDoc, UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xStyleFamiliesNames(xStyleFamSupp->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamiliesNames->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Any aDefaultStyle = xPageStyles->getByName("Default"); + uno::Reference<beans::XPropertySet> xProp(aDefaultStyle, UNO_QUERY_THROW); + + uno::Any aHFC = xProp->getPropertyValue("RightPageHeaderContent"); + uno::Reference<sheet::XHeaderFooterContent> xHFC(aHFC, UNO_QUERY_THROW); + + uno::Reference<text::XText> xTxtCenter = xHFC->getCenterText(); + uno::Reference<text::XText> xTxtLeft = xHFC->getLeftText(); + uno::Reference<text::XText> xTxtRight = xHFC->getRightText(); + + xTxtCenter->setString("CENTER"); + xTxtLeft->setString("LEFT"); + xTxtRight->setString("RIGHT"); + + xProp->setPropertyValue("RightPageHeaderContent", aHFC); + + return xHFC; +} + +void ScHeaderFooterContentObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScHeaderFooterContentObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scimportdescriptorbaseobj.cxx b/sc/qa/extras/scimportdescriptorbaseobj.cxx new file mode 100644 index 0000000000..764432ce3a --- /dev/null +++ b/sc/qa/extras/scimportdescriptorbaseobj.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/databaseimportdescriptor.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/util/XImportable.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScImportDescriptorBaseObj : public UnoApiTest, public apitest::DatabaseImportDescriptor +{ +public: + ScImportDescriptorBaseObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXImportable() override; + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScImportDescriptorBaseObj); + + // DatabaseImportDescriptor + CPPUNIT_TEST(testDatabaseImportDescriptorProperties); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScImportDescriptorBaseObj::ScImportDescriptorBaseObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScImportDescriptorBaseObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + return xSheet; +} + +uno::Reference<uno::XInterface> ScImportDescriptorBaseObj::getXImportable() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<util::XImportable> XImportable(xSheet, UNO_QUERY_THROW); + return XImportable; +} + +void ScImportDescriptorBaseObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScImportDescriptorBaseObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx b/sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx new file mode 100644 index 0000000000..e9e359513a --- /dev/null +++ b/sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_CellAnnotationsEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_CellAnnotationsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_CellAnnotationsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_CellAnnotationsEnumeration::ScIndexEnumeration_CellAnnotationsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_CellAnnotationsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetAnnotationsSupplier> xSAS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotations> xSA(xSAS->getAnnotations(), uno::UNO_SET_THROW); + xSA->insertNew(table::CellAddress(0, 5, 5), "Note"); + + uno::Reference<container::XEnumerationAccess> xEA(xSA, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumeration> xE(xEA->createEnumeration(), uno::UNO_SET_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_CellAnnotationsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_CellAnnotationsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_cellarealinksenumeration.cxx b/sc/qa/extras/scindexenumeration_cellarealinksenumeration.cxx new file mode 100644 index 0000000000..241f4b947c --- /dev/null +++ b/sc/qa/extras/scindexenumeration_cellarealinksenumeration.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XAreaLinks.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_CellAreaLinksEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_CellAreaLinksEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_CellAreaLinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_CellAreaLinksEnumeration::ScIndexEnumeration_CellAreaLinksEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_CellAreaLinksEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XAreaLinks> xAL; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("AreaLinks") >>= xAL); + xAL->insertAtPosition(table::CellAddress(1, 2, 3), + "ScIndexEnumeration_CellAreaLinksEnumeration.ods", "A2:B5", "", ""); + + uno::Reference<container::XEnumerationAccess> xEA(xAL, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_CellAreaLinksEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_CellAreaLinksEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_databaserangesenumeration.cxx b/sc/qa/extras/scindexenumeration_databaserangesenumeration.cxx new file mode 100644 index 0000000000..3a2b66d569 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_databaserangesenumeration.cxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DatabaseRangesEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DatabaseRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DatabaseRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_DatabaseRangesEnumeration::ScIndexEnumeration_DatabaseRangesEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DatabaseRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDatabaseRanges> xDR; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("DatabaseRanges") >>= xDR); + xDR->addNewByName("DatabaseRange", table::CellRangeAddress(0, 2, 4, 5, 6)); + + uno::Reference<container::XEnumerationAccess> xEA(xDR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DatabaseRangesEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DatabaseRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.cxx b/sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.cxx new file mode 100644 index 0000000000..def3a7f7b1 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotFieldsEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotFieldsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotFieldsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_DataPilotFieldsEnumeration::ScIndexEnumeration_DataPilotFieldsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DataPilotFieldsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < 4; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto x = 1; x < 4; ++x) + for (auto y = 1; y < 4; ++y) + xSheet0->getCellByPosition(x, y)->setValue(x * (y + 1)); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + uno::Reference<container::XEnumerationAccess> xEA(xDPD->getDataPilotFields(), + uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotFieldsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotFieldsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx b/sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx new file mode 100644 index 0000000000..628b916a70 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx @@ -0,0 +1,132 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotField.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotItemsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotItemsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotItemsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; +}; + +ScIndexEnumeration_DataPilotItemsEnumeration::ScIndexEnumeration_DataPilotItemsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DataPilotItemsEnumeration::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no document", xDoc.is()); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Any aValue; + uno::Reference<beans::XPropertySet> xPropertySet(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + aValue <<= sheet::DataPilotFieldOrientation_DATA; + xPropertySet->setPropertyValue("Orientation", aValue); + aValue <<= sheet::GeneralFunction_SUM; + xPropertySet->setPropertyValue("Function", aValue); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<sheet::XDataPilotField> xDPF(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xDPF->getItems(), uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotItemsEnumeration::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotItemsEnumeration); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx b/sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx new file mode 100644 index 0000000000..09731dd894 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotTablesEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotTablesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotTablesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_DataPilotTablesEnumeration::ScIndexEnumeration_DataPilotTablesEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DataPilotTablesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < 4; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto x = 1; x < 4; ++x) + for (auto y = 1; y < 4; ++y) + xSheet0->getCellByPosition(x, y)->setValue(x * (y + 1)); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + uno::Reference<container::XEnumerationAccess> xEA(xDPT, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotTablesEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotTablesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_ddelinksenumeration.cxx b/sc/qa/extras/scindexenumeration_ddelinksenumeration.cxx new file mode 100644 index 0000000000..74ae90b94e --- /dev/null +++ b/sc/qa/extras/scindexenumeration_ddelinksenumeration.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <sal/types.h> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DDELinksEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DDELinksEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DDELinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_DDELinksEnumeration::ScIndexEnumeration_DDELinksEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DDELinksEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(5, 5)->setFormula( + "=DDE(\"soffice\";\"ScDDELinksObj.ods\";\"Sheet1.A1\""); + xSheet0->getCellByPosition(1, 4)->setFormula( + "=DDE(\"soffice\";\"ScDDELinksObj.ods\";\"Sheet1.A1\""); + xSheet0->getCellByPosition(2, 0)->setFormula( + "=DDE(\"soffice\";\"ScDDELinksObj.ods\";\"Sheet1.A1\""); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + + uno::Reference<container::XEnumerationAccess> xEA(xPropertySet->getPropertyValue("DDELinks"), + uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DDELinksEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DDELinksEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_functiondescriptionenumeration.cxx b/sc/qa/extras/scindexenumeration_functiondescriptionenumeration.cxx new file mode 100644 index 0000000000..2fd0521078 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_functiondescriptionenumeration.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_FunctionDescriptionEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_FunctionDescriptionEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_FunctionDescriptionEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_FunctionDescriptionEnumeration:: + ScIndexEnumeration_FunctionDescriptionEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_FunctionDescriptionEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA( + xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"), uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_FunctionDescriptionEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_FunctionDescriptionEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx b/sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx new file mode 100644 index 0000000000..ff05feaaf3 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_LabelRangesEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_LabelRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_LabelRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_LabelRangesEnumeration::ScIndexEnumeration_LabelRangesEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_LabelRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XLabelRanges> xLR; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ColumnLabelRanges") >>= xLR); + + xLR->addNew(table::CellRangeAddress(0, 0, 1, 0, 6), table::CellRangeAddress(0, 0, 0, 0, 1)); + + uno::Reference<container::XEnumerationAccess> xEA(xLR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_LabelRangesEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_LabelRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx b/sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx new file mode 100644 index 0000000000..3fc9fe878c --- /dev/null +++ b/sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_NamedRangesEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_NamedRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_NamedRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_NamedRangesEnumeration::ScIndexEnumeration_NamedRangesEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_NamedRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XNamedRanges> xNR; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("NamedRanges") >>= xNR); + + table::CellRangeAddress aCellRangeAddr(0, 0, 0, 2, 2); + table::CellAddress aBaseAddr(aCellRangeAddr.Sheet, aCellRangeAddr.StartColumn, + aCellRangeAddr.StartRow); + xNR->addNewByName("ANamedRange", "A1:B2", aBaseAddr, 0); + xNR->outputList(table::CellAddress(0, 1, 1)); + + uno::Reference<container::XEnumerationAccess> xEA(xNR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_NamedRangesEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_NamedRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_scenariosenumeration.cxx b/sc/qa/extras/scindexenumeration_scenariosenumeration.cxx new file mode 100644 index 0000000000..0b99c2a1fe --- /dev/null +++ b/sc/qa/extras/scindexenumeration_scenariosenumeration.cxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XScenariosSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_ScenariosEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_ScenariosEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_ScenariosEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_ScenariosEnumeration::ScIndexEnumeration_ScenariosEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_ScenariosEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(5, 5)->setValue(15); + xSheet0->getCellByPosition(1, 4)->setValue(10); + xSheet0->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<sheet::XScenariosSupplier> xScenariosSupplier(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + xScenariosSupplier->getScenarios()->addNewByName("ScScenario", { xCRA->getRangeAddress() }, + "Range"); + uno::Reference<container::XEnumerationAccess> xEA(xScenariosSupplier->getScenarios(), + uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_ScenariosEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_ScenariosEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.cxx b/sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.cxx new file mode 100644 index 0000000000..b90c7f794e --- /dev/null +++ b/sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.cxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SheetCellRangesEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SheetCellRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SheetCellRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_SheetCellRangesEnumeration::ScIndexEnumeration_SheetCellRangesEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SheetCellRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR( + xMSF->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xNC(xSCR, uno::UNO_QUERY_THROW); + + uno::Any aRange; + + aRange <<= xSheet0->getCellRangeByName("C1:D4"); + xNC->insertByName("Range1", aRange); + aRange <<= xSheet0->getCellRangeByName("E2:F5"); + xNC->insertByName("Range2", aRange); + aRange <<= xSheet0->getCellRangeByName("G2:H3"); + xNC->insertByName("Range3", aRange); + aRange <<= xSheet0->getCellRangeByName("I7:J8"); + xNC->insertByName("Range4", aRange); + + for (auto x = 0; x < 10; ++x) + { + for (auto y = 0; y < 5; ++y) + { + xSheet0->getCellByPosition(x, y)->setFormula("a"); + } + } + for (auto x = 0; x < 10; ++x) + { + for (auto y = 5; y < 10; ++y) + { + xSheet0->getCellByPosition(x, y)->setValue(x + y); + } + } + uno::Reference<container::XEnumerationAccess> xEA(xSCR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SheetCellRangesEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SheetCellRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_sheetlinksenumeration.cxx b/sc/qa/extras/scindexenumeration_sheetlinksenumeration.cxx new file mode 100644 index 0000000000..3308d49cdb --- /dev/null +++ b/sc/qa/extras/scindexenumeration_sheetlinksenumeration.cxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/SheetLinkMode.hpp> +#include <com/sun/star/sheet/XSheetLinkable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SheetLinksEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SheetLinksEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SheetLinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_SheetLinksEnumeration::ScIndexEnumeration_SheetLinksEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SheetLinksEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetLinkable> xSL(xSheet0, uno::UNO_QUERY_THROW); + xSL->link("ScIndexEnumeration_SheetLinksEnumeration.ods", "Sheet1", "", "", + sheet::SheetLinkMode_VALUE); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xSheetLinks; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("SheetLinks") >>= xSheetLinks); + + uno::Reference<container::XEnumerationAccess> xEA(xSheetLinks, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SheetLinksEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SheetLinksEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_spreadsheetsenumeration.cxx b/sc/qa/extras/scindexenumeration_spreadsheetsenumeration.cxx new file mode 100644 index 0000000000..f0eb5c84e4 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_spreadsheetsenumeration.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SpreadsheetsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SpreadsheetsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SpreadsheetsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_SpreadsheetsEnumeration::ScIndexEnumeration_SpreadsheetsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SpreadsheetsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xSheets, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SpreadsheetsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SpreadsheetsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx b/sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx new file mode 100644 index 0000000000..c78af36e2a --- /dev/null +++ b/sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SpreadsheetViewPanesEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SpreadsheetViewPanesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SpreadsheetViewPanesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_SpreadsheetViewPanesEnumeration:: + ScIndexEnumeration_SpreadsheetViewPanesEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SpreadsheetViewPanesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<frame::XController> xController(xModel->getCurrentController(), + uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xController, uno::UNO_QUERY_THROW); + xIA->getByIndex(0); + + uno::Reference<container::XEnumerationAccess> xEA(xIA, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SpreadsheetViewPanesEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SpreadsheetViewPanesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.cxx b/sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.cxx new file mode 100644 index 0000000000..db8e08e3c9 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SubTotalFieldsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SubTotalFieldsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SubTotalFieldsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_SubTotalFieldsEnumeration::ScIndexEnumeration_SubTotalFieldsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SubTotalFieldsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSubTotalCalculatable> xSTC(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSubTotalDescriptor> xSTD(xSTC->createSubTotalDescriptor(true), + uno::UNO_SET_THROW); + + xSTD->addNew({ { 5, sheet::GeneralFunction_SUM } }, 1); + + uno::Reference<container::XIndexAccess> xIA_STD(xSTD, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xIA_STD, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SubTotalFieldsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SubTotalFieldsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx b/sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx new file mode 100644 index 0000000000..dcfb22e626 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableAutoFormatEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableAutoFormatEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableAutoFormatEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_TableAutoFormatEnumeration::ScIndexEnumeration_TableAutoFormatEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableAutoFormatEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableAutoFormatEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableAutoFormatEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx b/sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx new file mode 100644 index 0000000000..725aa2f982 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableChartsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableChartsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableChartsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_TableChartsEnumeration::ScIndexEnumeration_TableChartsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableChartsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(1, 0)->setFormula("JAN"); + xSheet0->getCellByPosition(2, 0)->setFormula("FEB"); + xSheet0->getCellByPosition(3, 0)->setFormula("MAR"); + xSheet0->getCellByPosition(4, 0)->setFormula("APR"); + xSheet0->getCellByPosition(5, 0)->setFormula("MAY"); + xSheet0->getCellByPosition(6, 0)->setFormula("JUN"); + xSheet0->getCellByPosition(7, 0)->setFormula("JUL"); + xSheet0->getCellByPosition(8, 0)->setFormula("AUG"); + xSheet0->getCellByPosition(9, 0)->setFormula("SEP"); + xSheet0->getCellByPosition(10, 0)->setFormula("OCT"); + xSheet0->getCellByPosition(11, 0)->setFormula("NOV"); + xSheet0->getCellByPosition(12, 0)->setFormula("DEC"); + xSheet0->getCellByPosition(13, 0)->setFormula("SUM"); + + xSheet0->getCellByPosition(0, 1)->setFormula("Smith"); + xSheet0->getCellByPosition(1, 1)->setValue(42); + xSheet0->getCellByPosition(2, 1)->setValue(58.9); + xSheet0->getCellByPosition(3, 1)->setValue(-66.5); + xSheet0->getCellByPosition(4, 1)->setValue(43.4); + xSheet0->getCellByPosition(5, 1)->setValue(44.5); + xSheet0->getCellByPosition(6, 1)->setValue(45.3); + xSheet0->getCellByPosition(7, 1)->setValue(-67.3); + xSheet0->getCellByPosition(8, 1)->setValue(30.5); + xSheet0->getCellByPosition(9, 1)->setValue(23.2); + xSheet0->getCellByPosition(10, 1)->setValue(-97.3); + xSheet0->getCellByPosition(11, 1)->setValue(22.4); + xSheet0->getCellByPosition(11, 1)->setValue(23.5); + xSheet0->getCellByPosition(13, 1)->setFormula("SUM(B2:M2"); + + xSheet0->getCellByPosition(0, 2)->setFormula("Jones"); + xSheet0->getCellByPosition(1, 2)->setValue(21); + xSheet0->getCellByPosition(2, 2)->setValue(40.9); + xSheet0->getCellByPosition(3, 2)->setValue(-57.5); + xSheet0->getCellByPosition(4, 2)->setValue(-23.4); + xSheet0->getCellByPosition(5, 2)->setValue(34.5); + xSheet0->getCellByPosition(6, 2)->setValue(59.3); + xSheet0->getCellByPosition(7, 2)->setValue(27.3); + xSheet0->getCellByPosition(8, 2)->setValue(-38.5); + xSheet0->getCellByPosition(9, 2)->setValue(43.2); + xSheet0->getCellByPosition(10, 2)->setValue(57.3); + xSheet0->getCellByPosition(11, 2)->setValue(25.4); + xSheet0->getCellByPosition(11, 2)->setValue(28.5); + xSheet0->getCellByPosition(13, 2)->setFormula("SUM(B3:M3"); + + xSheet0->getCellByPosition(0, 3)->setFormula("Brown"); + xSheet0->getCellByPosition(1, 3)->setValue(31.45); + xSheet0->getCellByPosition(2, 3)->setValue(-20.9); + xSheet0->getCellByPosition(3, 3)->setValue(-117.5); + xSheet0->getCellByPosition(4, 3)->setValue(23.4); + xSheet0->getCellByPosition(5, 3)->setValue(-114.5); + xSheet0->getCellByPosition(6, 3)->setValue(115.3); + xSheet0->getCellByPosition(7, 3)->setValue(-171.3); + xSheet0->getCellByPosition(8, 3)->setValue(89.5); + xSheet0->getCellByPosition(9, 3)->setValue(41.2); + xSheet0->getCellByPosition(10, 3)->setValue(71.3); + xSheet0->getCellByPosition(11, 3)->setValue(25.4); + xSheet0->getCellByPosition(11, 3)->setValue(38.5); + xSheet0->getCellByPosition(13, 3)->setFormula("SUM(A4:L4"); + + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableCharts> xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000), + { xCRA->getRangeAddress() }, true, false); + + uno::Reference<container::XEnumerationAccess> xEA(xTC, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableChartsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableChartsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tablecolumnsenumeration.cxx b/sc/qa/extras/scindexenumeration_tablecolumnsenumeration.cxx new file mode 100644 index 0000000000..7af615f1da --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablecolumnsenumeration.cxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableColumnsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableColumnsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableColumnsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_TableColumnsEnumeration::ScIndexEnumeration_TableColumnsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableColumnsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xNA->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference<table::XColumnRowRange> xColumnRowRange(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns(), + uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xTableColumns, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableColumnsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableColumnsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx b/sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx new file mode 100644 index 0000000000..e310b1a4f8 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <comphelper/propertyvalue.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableConditionalEntryEnumeration : public UnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableConditionalEntryEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableConditionalEntryEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_TableConditionalEntryEnumeration:: + ScIndexEnumeration_TableConditionalEntryEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableConditionalEntryEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(5, 5)->setValue(15); + xSheet0->getCellByPosition(1, 4)->setValue(10); + xSheet0->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Sequence<beans::PropertyValue> aConditions{ + comphelper::makePropertyValue("StyleName", OUString("Result2")), + comphelper::makePropertyValue("Formula1", OUString("$Sheet1.$B$5")), + comphelper::makePropertyValue("Formula2", OUString("")), + comphelper::makePropertyValue("Operator", sheet::ConditionOperator_EQUAL), + comphelper::makePropertyValue("SourcePosition", table::CellAddress(0, 1, 5)) + }; + + uno::Reference<beans::XPropertySet> xPropertySet(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntries> xSCE( + xPropertySet->getPropertyValue("ConditionalFormat"), uno::UNO_QUERY_THROW); + xSCE->addNew(aConditions); + + uno::Any aProperty; + aProperty <<= xSCE; + xPropertySet->setPropertyValue("ConditionalFormat", aProperty); + + uno::Reference<container::XEnumerationAccess> xEA(xSCE, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableConditionalEntryEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableConditionalEntryEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx b/sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx new file mode 100644 index 0000000000..76801b4bed --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableRowsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableRowsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableRowsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_TableRowsEnumeration::ScIndexEnumeration_TableRowsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableRowsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xNA->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + // limit the range the XEnumeration has to walk over (see fdo#45337). + uno::Reference<table::XCellRange> xCR(xSheet0->getCellRangeByName("A1:A4"), uno::UNO_SET_THROW); + + uno::Reference<table::XColumnRowRange> xColRowRange(xCR, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xTableRows(xColRowRange->getRows(), uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xTableRows, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableRowsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableRowsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_textfieldenumeration.cxx b/sc/qa/extras/scindexenumeration_textfieldenumeration.cxx new file mode 100644 index 0000000000..2e7b76d246 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_textfieldenumeration.cxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TextFieldEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TextFieldEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TextFieldEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScIndexEnumeration_TextFieldEnumeration::ScIndexEnumeration_TextFieldEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TextFieldEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextField> xTF(xMSF->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xTC(xTF, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell(xSheet0->getCellByPosition(2, 3), uno::UNO_SET_THROW); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + xText->insertTextContent(xText->createTextCursor(), xTC, true); + uno::Reference<text::XTextFieldsSupplier> xTFS(xCell, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xTFS->getTextFields(), uno::UNO_SET_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TextFieldEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TextFieldEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sclabelrangeobj.cxx b/sc/qa/extras/sclabelrangeobj.cxx new file mode 100644 index 0000000000..bd1492c606 --- /dev/null +++ b/sc/qa/extras/sclabelrangeobj.cxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/xlabelrange.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XLabelRange.hpp> +#include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScLabelRangeObj : public UnoApiTest, public apitest::XLabelRange +{ +public: + ScLabelRangeObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScLabelRangeObj); + + // XLabelRange + CPPUNIT_TEST(testGetSetDataArea); + CPPUNIT_TEST(testGetSetLabelArea); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScLabelRangeObj::ScLabelRangeObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScLabelRangeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xProp(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XLabelRanges> xLabelRanges(xProp->getPropertyValue("ColumnLabelRanges"), + uno::UNO_QUERY_THROW); + + table::CellRangeAddress aCellRanageAddr1(0, 0, 1, 0, 6); + table::CellRangeAddress aCellRanageAddr2(0, 0, 0, 0, 1); + xLabelRanges->addNew(aCellRanageAddr1, aCellRanageAddr2); + + uno::Reference<sheet::XLabelRange> xLabelRange(xLabelRanges->getByIndex(0), + uno::UNO_QUERY_THROW); + return xLabelRange; +} + +void ScLabelRangeObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScLabelRangeObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sclabelrangesobj.cxx b/sc/qa/extras/sclabelrangesobj.cxx new file mode 100644 index 0000000000..4204cab694 --- /dev/null +++ b/sc/qa/extras/sclabelrangesobj.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/xlabelranges.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XLabelRange.hpp> +#include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScLabelRangesObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XLabelRanges +{ +public: + ScLabelRangesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScLabelRangesObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XLabelRanges + CPPUNIT_TEST(testAddNew); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScLabelRangesObj::ScLabelRangesObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XLabelRange>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScLabelRangesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xProp(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XLabelRanges> xLabelRanges(xProp->getPropertyValue("ColumnLabelRanges"), + uno::UNO_QUERY_THROW); + + table::CellRangeAddress aCellRanageAddr1(0, 0, 1, 0, 6); + table::CellRangeAddress aCellRanageAddr2(0, 0, 0, 0, 1); + xLabelRanges->addNew(aCellRanageAddr1, aCellRanageAddr2); + + return xLabelRanges; +} + +void ScLabelRangesObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScLabelRangesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scmodelobj.cxx b/sc/qa/extras/scmodelobj.cxx new file mode 100644 index 0000000000..1c57effa3a --- /dev/null +++ b/sc/qa/extras/scmodelobj.cxx @@ -0,0 +1,116 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/document/xlinktargetsupplier.hxx> +#include <test/sheet/spreadsheetdocumentsettings.hxx> +#include <test/sheet/xcalculatable.hxx> +#include <test/sheet/xconsolidatable.hxx> +#include <test/sheet/xdocumentauditing.hxx> +#include <test/sheet/xgoalseek.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScModelObj : public UnoApiTest, + public apitest::SpreadsheetDocumentSettings, + public apitest::XCalculatable, + public apitest::XConsolidatable, + public apitest::XDocumentAuditing, + public apitest::XGoalSeek, + public apitest::XLinkTargetSupplier +{ +public: + virtual void setUp() override; + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Sequence<uno::Reference<table::XCell>> getXCells() override; + + ScModelObj(); + + CPPUNIT_TEST_SUITE(ScModelObj); + + // SpreadsheetDocumentSettings + CPPUNIT_TEST(testSpreadsheetDocumentSettingsProperties); + + // XCalculatable + CPPUNIT_TEST(testCalculate); + CPPUNIT_TEST(testCalculateAll); + CPPUNIT_TEST(testEnableAutomaticCalculation); + + // XConsolidatable + CPPUNIT_TEST(testCreateConsolidationDescriptor); + CPPUNIT_TEST(testConsolidate); + + // XDocumentAuditing + CPPUNIT_TEST(testRefreshArrows); + + // XGoalSeek + CPPUNIT_TEST(testSeekGoal); + + // XLinkTargetSupplier + CPPUNIT_TEST(testGetLinks); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Sequence<uno::Reference<table::XCell>> m_xCells; +}; + +ScModelObj::ScModelObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScModelObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<frame::XModel> xModel(xDoc, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + + m_xCells = { xSheet->getCellByPosition(4, 5), xSheet->getCellByPosition(5, 5), + xSheet->getCellByPosition(6, 5) }; + m_xCells[0]->setValue(15); + m_xCells[1]->setValue(10); + m_xCells[2]->setFormula("= E6 * F6"); + + return xModel; +} + +uno::Sequence<uno::Reference<table::XCell>> ScModelObj::getXCells() { return m_xCells; } + +void ScModelObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + loadFromFile(u"ScModelObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScModelObj); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scnamedrangeobj.cxx b/sc/qa/extras/scnamedrangeobj.cxx new file mode 100644 index 0000000000..95cbf1c42f --- /dev/null +++ b/sc/qa/extras/scnamedrangeobj.cxx @@ -0,0 +1,104 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/xnamedrange.hxx> +#include <test/sheet/xcellrangereferrer.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScNamedRangeObj : public UnoApiTest, + public apitest::XCellRangeReferrer, + public apitest::XNamed, + public apitest::XNamedRange +{ +public: + ScNamedRangeObj(); + + virtual void setUp() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< sheet::XNamedRange > getNamedRange(const OUString& rRangeName) override; + + CPPUNIT_TEST_SUITE(ScNamedRangeObj); + + // XCellRangeReferrer + CPPUNIT_TEST(testGetReferredCells); + + // XNamed + CPPUNIT_TEST(testSetName); + CPPUNIT_TEST(testGetName); + + // XNamedRange + CPPUNIT_TEST(testGetContent); + CPPUNIT_TEST(testSetContent); + CPPUNIT_TEST(testGetType); + CPPUNIT_TEST(testSetType); + CPPUNIT_TEST(testGetReferencePosition); + CPPUNIT_TEST(testSetReferencePosition); + + CPPUNIT_TEST_SUITE_END(); +private: + uno::Reference< sheet::XNamedRanges > init_impl(); +}; + +ScNamedRangeObj::ScNamedRangeObj(): + UnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XNamed("NamedRange") +{ +} + +uno::Reference< sheet::XNamedRanges > ScNamedRangeObj::init_impl() +{ + CPPUNIT_ASSERT_MESSAGE("no component loaded", mxComponent.is()); + + uno::Reference< beans::XPropertySet > xPropSet (mxComponent, UNO_QUERY_THROW); + uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xNamedRanges.is()); + + setCellRange(table::CellRangeAddress(0, 1, 7, 1, 7)); + + return xNamedRanges; +} + +uno::Reference< sheet::XNamedRange> ScNamedRangeObj::getNamedRange(const OUString& rRangeName) +{ + uno::Reference< container::XNameAccess > xNamedAccess(init_impl(), UNO_QUERY_THROW); + uno::Reference< sheet::XNamedRange > xNamedRange(xNamedAccess->getByName(rRangeName), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xNamedRange.is()); + + return xNamedRange; +} + +uno::Reference< uno::XInterface > ScNamedRangeObj::init() +{ + return getNamedRange("NamedRange"); +} + +void ScNamedRangeObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + loadFromFile(u"ScNamedRangeObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangeObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scnamedrangesobj.cxx b/sc/qa/extras/scnamedrangesobj.cxx new file mode 100644 index 0000000000..5ae53f42e0 --- /dev/null +++ b/sc/qa/extras/scnamedrangesobj.cxx @@ -0,0 +1,146 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/document/xactionlockable.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xnamedranges.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XNamedRange.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScNamedRangesObj : public UnoApiTest, + public apitest::XActionLockable, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNamedRanges, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScNamedRangesObj(); + + virtual void setUp() override; + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXNamedRanges(sal_Int32 nSheet = 0) override; + + CPPUNIT_TEST_SUITE(ScNamedRangesObj); + + // XActionLockable + CPPUNIT_TEST(testAddRemoveActionLock); + CPPUNIT_TEST(testSetResetActionLock); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNamedRanges + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNamedRanges + CPPUNIT_TEST(testAddNewByName); + CPPUNIT_TEST(testAddNewFromTitles); + //CPPUNIT_TEST_EXCEPTION(testRemoveByName, uno::RuntimeException); + CPPUNIT_TEST(testOutputList); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScNamedRangesObj::ScNamedRangesObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XNamedRange>::get()) + , XIndexAccess(4) + , XNameAccess("initial1") + , XServiceInfo("ScNamedRangesObj", "com.sun.star.sheet.NamedRanges") +{ +} + +uno::Reference<uno::XInterface> ScNamedRangesObj::init() +{ + uno::Reference<beans::XPropertySet> xPropSet(mxComponent, UNO_QUERY_THROW); + uno::Reference<sheet::XNamedRanges> xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), + UNO_QUERY_THROW); + + //set value from xnamedranges.hxx + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW); + xSheet.set(xIndexAccess->getByIndex(0), UNO_QUERY_THROW); + + return xNamedRanges; +} + +uno::Reference<uno::XInterface> ScNamedRangesObj::getXNamedRanges(sal_Int32 nSheet) +{ + uno::Reference<beans::XPropertySet> xPropSet(mxComponent, UNO_QUERY_THROW); + uno::Reference<sheet::XNamedRanges> xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), + UNO_QUERY_THROW); + + //set value from xnamedranges.hxx + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW); + xSheet.set(xIndexAccess->getByIndex(nSheet), UNO_QUERY_THROW); + + return xNamedRanges; +} + +void ScNamedRangesObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + loadFromFile(u"ScNamedRangeObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scoutlineobj.cxx b/sc/qa/extras/scoutlineobj.cxx new file mode 100644 index 0000000000..fd44259985 --- /dev/null +++ b/sc/qa/extras/scoutlineobj.cxx @@ -0,0 +1,73 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/sheet/xsheetoutline.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScOutlineObj : public UnoApiTest, public apitest::XSheetOutline +{ +public: + ScOutlineObj(); + + virtual void setUp() override; + + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScOutlineObj); + + // XSheetOutline + CPPUNIT_TEST(testHideDetail); + CPPUNIT_TEST(testShowDetail); + CPPUNIT_TEST(testShowLevel); + CPPUNIT_TEST(testUngroup); + CPPUNIT_TEST(testGroup); + //CPPUNIT_TEST(testAutoOutline); + CPPUNIT_TEST(testClearOutline); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScOutlineObj::ScOutlineObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScOutlineObj::init() +{ + // get the first sheet + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + return xSheet; +} + +void ScOutlineObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + loadFromFile(u"ScOutlineObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScOutlineObj); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scpdfexport.cxx b/sc/qa/extras/scpdfexport.cxx new file mode 100644 index 0000000000..bcca563ec9 --- /dev/null +++ b/sc/qa/extras/scpdfexport.cxx @@ -0,0 +1,583 @@ +/* -*- 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 <sal/config.h> +#include <config_oox.h> + +#include <test/unoapi_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <comphelper/propertysequence.hxx> +#include <unotools/tempfile.hxx> +#include <docsh.hxx> +#include <editutil.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/fontitem.hxx> +#include <osl/file.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> + +#include <vcl/filter/PDFiumLibrary.hxx> +#include <vcl/scheduler.hxx> + +#if USE_TLS_NSS +#include <nss.h> +#endif + +using namespace css::lang; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScPDFExportTest : public UnoApiTest +{ +public: + ScPDFExportTest(); + ~ScPDFExportTest(); + + // helpers +private: + void exportToPDF(const uno::Reference<frame::XModel>& xModel, const ScRange& range); + + void exportToPDFWithUnoCommands(const OUString& rRange); + + bool hasTextInPdf(const char* sText, bool& bFound); + + void setFont(ScFieldEditEngine& rEE, sal_Int32 nStart, sal_Int32 nEnd, + const OUString& rFontName); + + // unit tests +public: + void testExportRange_Tdf120161(); + void testExportFitToPage_Tdf103516(); + void testUnoCommands_Tdf120161(); + void testTdf64703_hiddenPageBreak(); + void testTdf143978(); + void testTdf120190(); + void testTdf84012(); + void testTdf78897(); + void testForcepoint97(); + + CPPUNIT_TEST_SUITE(ScPDFExportTest); + CPPUNIT_TEST(testExportRange_Tdf120161); + CPPUNIT_TEST(testExportFitToPage_Tdf103516); + CPPUNIT_TEST(testUnoCommands_Tdf120161); + CPPUNIT_TEST(testTdf64703_hiddenPageBreak); + CPPUNIT_TEST(testTdf143978); + CPPUNIT_TEST(testTdf120190); + CPPUNIT_TEST(testTdf84012); + CPPUNIT_TEST(testTdf78897); + CPPUNIT_TEST(testForcepoint97); + CPPUNIT_TEST_SUITE_END(); +}; + +ScPDFExportTest::ScPDFExportTest() + : UnoApiTest("sc/qa/extras/testdocuments/") +{ +} + +ScPDFExportTest::~ScPDFExportTest() +{ +#if USE_TLS_NSS + NSS_Shutdown(); +#endif +} + +bool ScPDFExportTest::hasTextInPdf(const char* sText, bool& bFound) +{ + SvStream* pStream = maTempFile.GetStream(StreamMode::STD_READ); + CPPUNIT_ASSERT(pStream); + + // get file size + const std::size_t nFileSize = pStream->TellEnd(); + if (nFileSize == 0) + return false; + + // read file content + char* pBuffer = new char[nFileSize]; + pStream->Seek(STREAM_SEEK_TO_BEGIN); + const std::size_t nRead = pStream->ReadBytes(pBuffer, nFileSize); + if (nRead == nFileSize) + { + const std::string haystack(pBuffer, pBuffer + nFileSize); + const std::string needle(sText); + const std::size_t n = haystack.find(needle); + bFound = (n != std::string::npos); + } + delete[] pBuffer; + + // close and return the status + pStream = nullptr; + maTempFile.CloseStream(); + return (nRead == nFileSize); +} + +void ScPDFExportTest::exportToPDF(const uno::Reference<frame::XModel>& xModel, const ScRange& range) +{ + // get XSpreadsheet + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + // select requested cells to print + // query for the XCellRange interface + uno::Reference<table::XCellRange> xCellRange = rSheet->getCellRangeByPosition( + range.aStart.Col(), range.aStart.Row(), range.aEnd.Col(), range.aEnd.Row()); + { + uno::Reference<frame::XController> xController = xModel->getCurrentController(); + CPPUNIT_ASSERT(xController.is()); + + uno::Reference<view::XSelectionSupplier> xSelection(xController, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xSelection.is()); + + uno::Any rCellRangeAny(xCellRange); + xSelection->select(rCellRangeAny); + } + + // init special pdf export params + css::uno::Sequence<css::beans::PropertyValue> aFilterData{ + comphelper::makePropertyValue("Selection", xCellRange), + comphelper::makePropertyValue("Printing", sal_Int32(2)), + comphelper::makePropertyValue("ViewPDFAfterExport", true) + }; + + // init set of params for storeToURL() call + css::uno::Sequence<css::beans::PropertyValue> seqArguments{ + comphelper::makePropertyValue("FilterData", aFilterData), + comphelper::makePropertyValue("FilterName", OUString("calc_pdf_Export")), + comphelper::makePropertyValue("URL", maTempFile.GetURL()) + }; + + // call storeToURL() + uno::Reference<lang::XComponent> xComponent(mxComponent, UNO_SET_THROW); + uno::Reference<css::frame::XStorable> xStorable(xComponent, UNO_QUERY); + xStorable->storeToURL(maTempFile.GetURL(), seqArguments); +} + +void ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange) +{ + uno::Sequence<beans::PropertyValue> aArgs + = comphelper::InitPropertySequence({ { "ToPoint", uno::Any(rRange) } }); + dispatchCommand(mxComponent, ".uno:GoToCell", aArgs); + + dispatchCommand(mxComponent, ".uno:DefinePrintArea", {}); + + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { { "ViewPDFAfterExport", uno::Any(true) }, { "Printing", uno::Any(sal_Int32(2)) } })); + + uno::Sequence<beans::PropertyValue> aDescriptor( + comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("calc_pdf_Export")) }, + { "FilterData", uno::Any(aFilterData) }, + { "URL", uno::Any(maTempFile.GetURL()) } })); + + dispatchCommand(mxComponent, ".uno:ExportToPDF", aDescriptor); +} + +void ScPDFExportTest::setFont(ScFieldEditEngine& rEE, sal_Int32 nStart, sal_Int32 nEnd, + const OUString& rFontName) +{ + ESelection aSel; + aSel.nStartPara = aSel.nEndPara = 0; + aSel.nStartPos = nStart; + aSel.nEndPos = nEnd; + + SfxItemSet aItemSet = rEE.GetEmptyItemSet(); + SvxFontItem aItem(FAMILY_MODERN, rFontName, "", PITCH_VARIABLE, RTL_TEXTENCODING_UTF8, + EE_CHAR_FONTINFO); + aItemSet.Put(aItem); + rEE.QuickSetAttribs(aItemSet, aSel); +} + +// Selection was not taken into account during export into PDF +void ScPDFExportTest::testExportRange_Tdf120161() +{ + // create test document + mxComponent = loadFromDesktop("private:factory/scalc"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("First Sheet", 0); + uno::Reference<sheet::XSpreadsheet> rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + // 2. Setup data + { + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xDocSh); + + // put some content into the first row with default font + ScDocument& rDoc = xDocSh->GetDocument(); + for (unsigned int r = 0; r < 1; ++r) + for (unsigned int c = 0; c < 14; ++c) + rDoc.SetValue(ScAddress(c, r, 0), (r + 1) * (c + 1)); + + // set "Text" to H1 cell with "DejaVuSans" font + ScFieldEditEngine& rEE = rDoc.GetEditEngine(); + rEE.Clear(); + rEE.SetTextCurrentDefaults("Text"); + setFont(rEE, 0, 4, "DejaVuSans"); // set font for first 4 chars + rDoc.SetEditText(ScAddress(7, 0, 0), rEE.CreateTextObject()); + } + + // A1:G1 + { + ScRange range1(0, 0, 0, 6, 0, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(false, bFound); + } + + // G1:H1 + { + ScRange range1(6, 0, 0, 7, 0, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // H1:I1 + { + ScRange range1(7, 0, 0, 8, 0, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testExportFitToPage_Tdf103516() +{ + // create test document + mxComponent = loadFromDesktop("private:factory/scalc"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("First Sheet", 0); + uno::Reference<sheet::XSpreadsheet> rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + // 2. Setup data + { + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xDocSh); + + // put some content into the table + ScDocument& rDoc = xDocSh->GetDocument(); + for (unsigned int r = 0; r < 80; ++r) + for (unsigned int c = 0; c < 12; ++c) + rDoc.SetValue(ScAddress(c, r, 0), (r + 1) * (c + 1)); + } + + // A1:G50: 2-page export + { + ScRange range1(0, 0, 0, 6, 49, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("/Count 2>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // A1:L80: 4-page export + { + ScRange range1(0, 0, 0, 11, 79, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("/Count 4>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // set fit to page: width=1 page, height=0 (automatic) + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamSupp(xDoc, UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xStyleFamiliesNames(xStyleFamSupp->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamiliesNames->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Any aDefaultStyle = xPageStyles->getByName("Default"); + uno::Reference<beans::XPropertySet> xProp(aDefaultStyle, UNO_QUERY_THROW); + + uno::Any aScaleX, aScaleY; + sal_Int16 nScale; + aScaleX <<= static_cast<sal_Int16>(1); + xProp->setPropertyValue("ScaleToPagesX", aScaleX); + aScaleX = xProp->getPropertyValue("ScaleToPagesX"); + aScaleX >>= nScale; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nScale); + + aScaleY = xProp->getPropertyValue("ScaleToPagesY"); + aScaleY >>= nScale; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nScale); + + // A1:G50 with fit to page width=1: slightly smaller zoom results only 1-page export + { + ScRange range1(0, 0, 0, 6, 49, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("/Count 1>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // A1:L80 with fit to page width=1: slightly smaller zoom results only 1-page export + { + ScRange range1(0, 0, 0, 11, 79, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("/Count 1>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testUnoCommands_Tdf120161() +{ + loadFromFile(u"tdf120161.ods"); + + // A1:G1 + { + exportToPDFWithUnoCommands("A1:G1"); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(false, bFound); + } + + // G1:H1 + { + exportToPDFWithUnoCommands("G1:H1"); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // H1:I1 + { + exportToPDFWithUnoCommands("H1:I1"); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testTdf64703_hiddenPageBreak() +{ + loadFromFile(u"tdf64703_hiddenPageBreak.ods"); + + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + + // A1:A11: 4-page export + { + ScRange range1(0, 0, 0, 0, 10, 0); + exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf("/Count 4>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testTdf143978() +{ + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + + loadFromFile(u"tdf143978.ods"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + + // A1:A2 + ScRange range1(0, 0, 0, 0, 1, 0); + exportToPDF(xModel, range1); + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage(); + + int nPageObjectCount = pPdfPage->getObjectCount(); + CPPUNIT_ASSERT_EQUAL(2, nPageObjectCount); + + // Without the fix in place, this test would have failed with + // - Expected: Dies ist viel zu viel Text + // - Actual : Dies ist vie + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject1 = pPdfPage->getObject(0); + OUString sText1 = pPageObject1->getText(pTextPage); + CPPUNIT_ASSERT_EQUAL(OUString("Dies ist viel zu viel Text"), sText1); + + // and it would also have failed with + // - Expected: 2021-11-17 + // - Actual : ### + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject2 = pPdfPage->getObject(1); + OUString sText2 = pPageObject2->getText(pTextPage); + CPPUNIT_ASSERT_EQUAL(OUString("2021-11-17"), sText2); +} + +void ScPDFExportTest::testTdf120190() +{ + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + + mxComponent = loadFromDesktop("private:factory/scalc"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(0, 0)->setFormula("=5&CHAR(10)&6"); + + uno::Sequence<beans::PropertyValue> aArgs + = comphelper::InitPropertySequence({ { "ToPoint", uno::Any(OUString("A1")) } }); + dispatchCommand(mxComponent, ".uno:GoToCell", aArgs); + + dispatchCommand(mxComponent, ".uno:ConvertFormulaToValue", {}); + + // A1 + ScRange range1(0, 0, 0, 0, 0, 0); + exportToPDF(xModel, range1); + + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage(); + + int nPageObjectCount = pPdfPage->getObjectCount(); + CPPUNIT_ASSERT_EQUAL(5, nPageObjectCount); + + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject1 = pPdfPage->getObject(0); + OUString sText1 = pPageObject1->getText(pTextPage); + CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), sText1); + + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject2 = pPdfPage->getObject(1); + OUString sText2 = pPageObject2->getText(pTextPage); + CPPUNIT_ASSERT_EQUAL(OUString("Page "), sText2); + + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject3 = pPdfPage->getObject(2); + OUString sText3 = pPageObject3->getText(pTextPage); + CPPUNIT_ASSERT_EQUAL(OUString("1"), sText3); + + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject4 = pPdfPage->getObject(3); + OUString sText4 = pPageObject4->getText(pTextPage); + + // Without the fix in place, this test would have failed with + // - Expected: 5 + // - Actual : 56 + CPPUNIT_ASSERT_EQUAL(OUString("5"), sText4); + + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject5 = pPdfPage->getObject(4); + OUString sText5 = pPageObject5->getText(pTextPage); + CPPUNIT_ASSERT_EQUAL(OUString("6"), sText5); +} + +void ScPDFExportTest::testTdf84012() +{ + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + + loadFromFile(u"tdf84012.ods"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + + // A1 + ScRange range1(0, 0, 0, 0, 0, 0); + exportToPDF(xModel, range1); + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage(); + + int nChars = pTextPage->countChars(); + std::vector<sal_uInt32> aChars(nChars); + for (int i = 0; i < nChars; i++) + aChars[i] = pTextPage->getUnicode(i); + OUString aActualText(aChars.data(), aChars.size()); + + // Without the fix in place, this test would have failed with + // - Expected: Blah blah (blah, blah) + // - Actual : Blah blah + CPPUNIT_ASSERT_EQUAL(OUString("Blah blah (blah, blah)"), aActualText); +} + +void ScPDFExportTest::testTdf78897() +{ + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + + loadFromFile(u"tdf78897.xls"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + + // C3:D3 + ScRange range1(2, 2, 0, 3, 2, 0); + exportToPDF(xModel, range1); + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage(); + + int nChars = pTextPage->countChars(); + std::vector<sal_uInt32> aChars(nChars); + for (int i = 0; i < nChars; i++) + aChars[i] = pTextPage->getUnicode(i); + OUString aActualText(aChars.data(), aChars.size()); + + // Without the fix in place, this test would have failed with + // - Expected: 11.00 11.00 + // - Actual : 11.00 ### + CPPUNIT_ASSERT_EQUAL(OUString(" 11.00 11.00 "), aActualText); +} + +// just needs to not crash on export to pdf +void ScPDFExportTest::testForcepoint97() +{ + loadFromFile(u"forcepoint97.xlsx"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + + // A1:H81 + ScRange range1(0, 0, 0, 7, 81, 0); + exportToPDF(xModel, range1); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScPDFExportTest); +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/screcentfunctionsobj.cxx b/sc/qa/extras/screcentfunctionsobj.cxx new file mode 100644 index 0000000000..77aa095bc8 --- /dev/null +++ b/sc/qa/extras/screcentfunctionsobj.cxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/xrecentfunctions.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScRecentFunctionsObj : public UnoApiTest, public apitest::XRecentFunctions +{ +public: + ScRecentFunctionsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScRecentFunctionsObj); + + // XRecentFunctions + CPPUNIT_TEST(testGetRecentFunctionIds); + CPPUNIT_TEST(testSetRecentFunctionIds); + CPPUNIT_TEST(testGetMaxRecentFunctions); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScRecentFunctionsObj::ScRecentFunctionsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScRecentFunctionsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.RecentFunctions"); +} + +void ScRecentFunctionsObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScRecentFunctionsObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/screcordchanges.cxx b/sc/qa/extras/screcordchanges.cxx new file mode 100644 index 0000000000..9e95e37d78 --- /dev/null +++ b/sc/qa/extras/screcordchanges.cxx @@ -0,0 +1,103 @@ +/* -*- 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 <test/unoapi_test.hxx> + +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <rtl/ustring.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +/* Implementation of calc Record Changes test */ + +class ScRecordChangesTest : public UnoApiTest +{ +public: + ScRecordChangesTest(); + + void testSetRecordChanges(); + void testCheckRecordChangesProtection(); + + CPPUNIT_TEST_SUITE(ScRecordChangesTest); + CPPUNIT_TEST(testSetRecordChanges); + CPPUNIT_TEST(testCheckRecordChangesProtection); + CPPUNIT_TEST_SUITE_END(); +}; + +void ScRecordChangesTest::testSetRecordChanges() +{ + mxComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xDocSettingsPropSet(xDoc, UNO_QUERY_THROW); + + bool recordChangesValue = true; + bool protectionValue = true; + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") + >>= protectionValue); + + CPPUNIT_ASSERT_MESSAGE("a new document does not record changes", !recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("a new document does not protect record changes", !protectionValue); + + // now activate recording + uno::Any aValue; + aValue <<= true; + xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue); + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the document should record changes", recordChangesValue); +} + +void ScRecordChangesTest::testCheckRecordChangesProtection() +{ + // test with protected changes + loadFromFile(u"RecordChangesProtected.ods"); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xDocSettingsPropSet(xDoc, UNO_QUERY_THROW); + + bool recordChangesValue = false; + bool protectionValue = false; + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") + >>= protectionValue); + + CPPUNIT_ASSERT_MESSAGE("the document should be recording changes", recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the protection should be active", protectionValue); + + // try to de-activate recording + uno::Any aValue; + aValue <<= false; + xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue); + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") + >>= protectionValue); + + // this document should still record changes as protection is set + CPPUNIT_ASSERT_MESSAGE("the document should still be recording changes", recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the protection should still be active", protectionValue); +} + +ScRecordChangesTest::ScRecordChangesTest() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScRecordChangesTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scscenariosobj.cxx b/sc/qa/extras/scscenariosobj.cxx new file mode 100644 index 0000000000..744954aec2 --- /dev/null +++ b/sc/qa/extras/scscenariosobj.cxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xscenarios.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XScenario.hpp> +#include <com/sun/star/sheet/XScenariosSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <cppu/unotype.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScScenariosObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XNameAccess, + public apitest::XIndexAccess, + public apitest::XScenarios, + public apitest::XServiceInfo +{ +public: + ScScenariosObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScScenariosObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XScenarios + CPPUNIT_TEST(testAddNewByName); + CPPUNIT_TEST(testRemoveByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScScenariosObj::ScScenariosObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XScenario>::get()) + , XNameAccess("ScScenarios") + , XIndexAccess(1) + , XServiceInfo("ScScenariosObj", "com.sun.star.sheet.Scenarios") +{ +} + +uno::Reference<uno::XInterface> ScScenariosObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<table::XCellRange> xCellRange(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange2 = xCellRange->getCellRangeByName("A1:N4"); + uno::Reference<sheet::XCellRangeAddressable> xCRAddressable(xCellRange2, uno::UNO_QUERY_THROW); + table::CellRangeAddress aCellRangeAddr = xCRAddressable->getRangeAddress(); + + uno::Reference<sheet::XScenariosSupplier> xSupplier(xSheet, uno::UNO_QUERY_THROW); + xSupplier->getScenarios()->addNewByName("ScScenarios", { aCellRangeAddr }, "Range"); + + return xSupplier->getScenarios(); +} + +void ScScenariosObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScScenariosObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scshapeobj.cxx b/sc/qa/extras/scshapeobj.cxx new file mode 100644 index 0000000000..6500ff87a2 --- /dev/null +++ b/sc/qa/extras/scshapeobj.cxx @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/drawing/xgluepointssupplier.hxx> +#include <test/drawing/xshape.hxx> +#include <test/drawing/xshapedescriptor.hxx> +#include <test/lang/xcomponent.hxx> +#include <test/sheet/shape.hxx> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScShapeObj : public UnoApiTest, + public apitest::Shape, + public apitest::XComponent, + public apitest::XGluePointsSupplier, + public apitest::XShape, + public apitest::XShapeDescriptor +{ +public: + ScShapeObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSheetDocument() override; + virtual void triggerDesktopTerminate() override{}; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScShapeObj); + + // Shape + CPPUNIT_TEST(testShapePropertiesAnchor); + CPPUNIT_TEST(testShapePropertiesPosition); + + // XComponent + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testDispose); + CPPUNIT_TEST(testRemoveEventListener); + + // XGluePointsSupplier + CPPUNIT_TEST(testGetGluePoints); + + // XShape + CPPUNIT_TEST(testGetSetPosition); + CPPUNIT_TEST(testGetSetSize); + + // XShapeDescriptor + CPPUNIT_TEST(testGetShapeType); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScShapeObj::ScShapeObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XShapeDescriptor("com.sun.star.drawing.RectangleShape") +{ +} + +uno::Reference<uno::XInterface> ScShapeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape( + xMSF->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY_THROW); + xShape->setPosition(awt::Point(5000, 3500)); + xShape->setSize(awt::Size(7500, 5000)); + + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDrawPages = xDPS->getDrawPages(); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShapes> xShapes(xDrawPage, uno::UNO_QUERY_THROW); + xShapes->add(xShape); + + for (auto i = 0; i < 10; i++) + { + xShape->setPosition(awt::Point(5000, 3500)); + xShape->setSize(awt::Size(7510 + 10 * i, 5010 + 10 * i)); + xShapes->add(xShape); + } + + return xShape; +} + +uno::Reference<uno::XInterface> ScShapeObj::getXSheetDocument() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + return xDoc; +} + +void ScShapeObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScShapeObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsheetlinkobj.cxx b/sc/qa/extras/scsheetlinkobj.cxx new file mode 100644 index 0000000000..ca0482bc6c --- /dev/null +++ b/sc/qa/extras/scsheetlinkobj.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/sheetlink.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/SheetLinkMode.hpp> +#include <com/sun/star/sheet/XSheetLinkable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSheetLinkObj : public UnoApiTest, + public apitest::SheetLink, + public apitest::XNamed, + public apitest::XRefreshable +{ +public: + ScSheetLinkObj(); + + virtual uno::Reference<uno::XInterface> init() override; + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScSheetLinkObj); + + // SheetLink + CPPUNIT_TEST(testSheetLinkProperties); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetNameByScSheetLinkObj); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScSheetLinkObj::ScSheetLinkObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XNamed(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/ScSheetLinkObj.ods")) +{ +} + +uno::Reference<uno::XInterface> ScSheetLinkObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetLinkable> xSL(xSheet, uno::UNO_QUERY_THROW); + xSL->link(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/ScSheetLinkObj.ods"), + "Sheet1", "", "", sheet::SheetLinkMode_VALUE); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> sheetLinks; + CPPUNIT_ASSERT(xPropSet->getPropertyValue("SheetLinks") >>= sheetLinks); + CPPUNIT_ASSERT(sheetLinks.is()); + + uno::Any aAny = sheetLinks->getByName(sheetLinks->getElementNames()[0]); + uno::Reference<beans::XPropertySet> sheetLink; + aAny >>= sheetLink; + return sheetLink; +} + +void ScSheetLinkObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSheetLinkObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsheetlinksobj.cxx b/sc/qa/extras/scsheetlinksobj.cxx new file mode 100644 index 0000000000..7504eaaa99 --- /dev/null +++ b/sc/qa/extras/scsheetlinksobj.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <cppu/unotype.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/SheetLinkMode.hpp> +#include <com/sun/star/sheet/XSheetLinkable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSheetLinksObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScSheetLinksObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScSheetLinksObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScSheetLinksObj::ScSheetLinksObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(1) + , XNameAccess(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/ScSheetLinksObj.ods")) + , XServiceInfo("ScSheetLinksObj", "com.sun.star.sheet.SheetLinks") +{ +} + +uno::Reference<uno::XInterface> ScSheetLinksObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetLinkable> xSL(xSheet0, uno::UNO_QUERY_THROW); + OUString aFileURL = createFileURL(u"ScSheetLinksObj.ods"); + xSL->link(aFileURL, "Sheet1", "", "", sheet::SheetLinkMode_VALUE); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("SheetLinks") >>= xNA); + + return xNA; +} + +void ScSheetLinksObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSheetLinksObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsortdescriptorbaseobj.cxx b/sc/qa/extras/scsortdescriptorbaseobj.cxx new file mode 100644 index 0000000000..ed845aaa26 --- /dev/null +++ b/sc/qa/extras/scsortdescriptorbaseobj.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/sheetsortdescriptor2.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/util/XSortable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSortDescriptorBaseObj : public UnoApiTest, public apitest::SheetSortDescriptor2 +{ +public: + ScSortDescriptorBaseObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScSortDescriptorBaseObj); + + // SheetSortDescriptor2 + CPPUNIT_TEST(testSheetSortDescriptor2Properties); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScSortDescriptorBaseObj::ScSortDescriptorBaseObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScSortDescriptorBaseObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<util::XSortable> xSortable(xSheet, UNO_QUERY_THROW); + return xSortable; +} + +void ScSortDescriptorBaseObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSortDescriptorBaseObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scspreadsheetsettings.cxx b/sc/qa/extras/scspreadsheetsettings.cxx new file mode 100644 index 0000000000..14d6843098 --- /dev/null +++ b/sc/qa/extras/scspreadsheetsettings.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/globalsheetsettings.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSpreadsheetSettings : public UnoApiTest, + public apitest::GlobalSheetSettings, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScSpreadsheetSettings(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScSpreadsheetSettings); + + // GlobalSheetSettings + CPPUNIT_TEST(testGlobalSheetSettingsProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScSpreadsheetSettings::ScSpreadsheetSettings() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "LinkUpdateMode", "UsePrinterMetrics", "UserLists" }) + , XServiceInfo("stardiv.StarCalc.ScSpreadsheetSettings", + "com.sun.star.sheet.GlobalSheetSettings") +{ +} + +uno::Reference<uno::XInterface> ScSpreadsheetSettings::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.GlobalSheetSettings"); +} + +void ScSpreadsheetSettings::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSpreadsheetSettings); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scspreadsheetsettingsobj.cxx b/sc/qa/extras/scspreadsheetsettingsobj.cxx new file mode 100644 index 0000000000..9173a80ba1 --- /dev/null +++ b/sc/qa/extras/scspreadsheetsettingsobj.cxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/sheet/spreadsheetdocumentsettings.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSpreadsheetSettingsObj : public UnoApiTest, + public apitest::SpreadsheetDocumentSettings, + public apitest::XPropertySet +{ +public: + ScSpreadsheetSettingsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScSpreadsheetSettingsObj); + + // SpreadsheetDocumentSettings + CPPUNIT_TEST(testSpreadsheetDocumentSettingsProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScSpreadsheetSettingsObj::ScSpreadsheetSettingsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "AreaLinks", "CharLocale", "CharLocaleAsian", "CharLocaleComplex", + "ColumnLabelRanges", "DDELinks", "DatabaseRanges", "ExternalDocLinks", + "InteropGrabBag", "NamedRanges", "NullDate", "RowLabelRanges", "SheetLinks", + "Theme" }) +{ +} + +uno::Reference<uno::XInterface> ScSpreadsheetSettingsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + return xDoc; +} + +void ScSpreadsheetSettingsObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSpreadsheetSettingsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scstylefamiliesobj.cxx b/sc/qa/extras/scstylefamiliesobj.cxx new file mode 100644 index 0000000000..72fb135bd5 --- /dev/null +++ b/sc/qa/extras/scstylefamiliesobj.cxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/style/xstyleloader.hxx> + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScStyleFamiliesObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XStyleLoader +{ +public: + ScStyleFamiliesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<sheet::XSpreadsheetDocument> getTargetDoc() override; + virtual uno::Reference<lang::XComponent> getSourceComponent() override; + virtual OUString getTestURL() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScStyleFamiliesObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XStyleLoader + CPPUNIT_TEST(testLoadStylesFromDocument); + CPPUNIT_TEST(testLoadStylesFromStream); + CPPUNIT_TEST(testLoadStylesFromURL); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xSrcComponent; +}; + +ScStyleFamiliesObj::ScStyleFamiliesObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNameContainer>::get()) + , XIndexAccess(3) + , XNameAccess("CellStyles") + , XServiceInfo("ScStyleFamiliesObj", "com.sun.star.style.StyleFamilies") +{ +} + +uno::Reference<uno::XInterface> ScStyleFamiliesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + + return xNA; +} + +uno::Reference<sheet::XSpreadsheetDocument> ScStyleFamiliesObj::getTargetDoc() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + return xDoc; +} + +uno::Reference<lang::XComponent> ScStyleFamiliesObj::getSourceComponent() +{ + return m_xSrcComponent; +} + +OUString ScStyleFamiliesObj::getTestURL() { return createFileURL(u"ScStyleFamiliesObj.ods"); } + +void ScStyleFamiliesObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); + + m_xSrcComponent = loadFromDesktop(getTestURL()); +} + +void ScStyleFamiliesObj::tearDown() +{ + m_xSrcComponent->dispose(); + m_xSrcComponent.clear(); + + UnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleFamiliesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scstylefamilyobj.cxx b/sc/qa/extras/scstylefamilyobj.cxx new file mode 100644 index 0000000000..627e755cad --- /dev/null +++ b/sc/qa/extras/scstylefamilyobj.cxx @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/container/xnamereplace.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScStyleFamilyObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XNameReplace, + public apitest::XServiceInfo +{ +public: + ScStyleFamilyObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScStyleFamilyObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameDuplicate); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XNameReplace + CPPUNIT_TEST(testReplaceByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +/* TODO: this c/should be derived/defined from the real style count, default + * implemented plus sc/res/xml/styles.xml */ +constexpr sal_Int32 kScStyleFamilyObjCount = 20; + +ScStyleFamilyObj::ScStyleFamilyObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<style::XStyle>::get()) + , XIndexAccess(kScStyleFamilyObjCount) + , XNameAccess("ScStyleFamilyObj") + , XNameContainer("ScStyleFamilyObj") + , XNameReplace("ScStyleFamilyObj") + , XServiceInfo("ScStyleFamilyObj", "com.sun.star.style.StyleFamily") +{ +} + +uno::Reference<uno::XInterface> ScStyleFamilyObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xNA, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_SF(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xCS(xMSF->createInstance("com.sun.star.style.CellStyle"), + uno::UNO_SET_THROW); + // XNameContainer + XNameContainer::setElement(uno::Any(xMSF->createInstance("com.sun.star.style.CellStyle"))); + // XNameReplace + XNameReplace::setElement(uno::Any(xMSF->createInstance("com.sun.star.style.CellStyle"))); + + uno::Reference<container::XNameContainer> xNC(xNA_SF, uno::UNO_QUERY_THROW); + xNC->insertByName("ScStyleFamilyObj", uno::Any(xCS)); + + return xNA_SF; +} + +void ScStyleFamilyObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleFamilyObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scstyleobj.cxx b/sc/qa/extras/scstyleobj.cxx new file mode 100644 index 0000000000..12b3b0ebde --- /dev/null +++ b/sc/qa/extras/scstyleobj.cxx @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScStyleObj : public UnoApiTest, public apitest::XNamed, public apitest::XPropertySet +{ +public: + ScStyleObj(); + + virtual void setUp() override; + + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScStyleObj); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScStyleObj::ScStyleObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("ScStyleObj") + , XPropertySet({ "BottomBorder", + "BottomBorder2", + "BottomBorderComplexColor", + "CellProtection", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "CharPosture", + "CharPostureAsian", + "CharPostureComplex", + "DiagonalBLTR", + "DiagonalBLTR2", + "DiagonalTLBR", + "DiagonalTLBR2", + "HoriJustify", + "LeftBorder", + "LeftBorder2", + "LeftBorderComplexColor", + "NumberFormat", + "Orientation", + "RightBorder", + "RightBorder2", + "RightBorderComplexColor", + "ShadowFormat", + "TableBorder", + "TopBorder", + "TopBorder2", + "TopBorderComplexColor", + "UserDefinedAttributes", + "CellBackgroundComplexColor" }) +{ +} + +uno::Reference<uno::XInterface> ScStyleObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_StyleFamilies(xSFS->getStyleFamilies(), + uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA_StyleFamilies(xNA_StyleFamilies, + uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_StyleFamily(xIA_StyleFamilies->getByIndex(0), + uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<style::XStyle> xStyle(xMSF->createInstance("com.sun.star.style.CellStyle"), + uno::UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xNC(xNA_StyleFamily, uno::UNO_QUERY_THROW); + if (xNC->hasByName("ScStyleObj")) + { + xNC->removeByName("ScStyleObj"); + } + xNC->insertByName("ScStyleObj", uno::Any(xStyle)); + + uno::Reference<container::XIndexAccess> xIA_sheets(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA_sheets->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet0->getCellByPosition(2, 3); + uno::Reference<beans::XPropertySet> xPS(xCell, uno::UNO_QUERY_THROW); + xPS->setPropertyValue("CellStyle", uno::Any(xStyle->getName())); + + return xStyle; +} + +void ScStyleObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsubtotaldescriptorbase.cxx b/sc/qa/extras/scsubtotaldescriptorbase.cxx new file mode 100644 index 0000000000..90f656060e --- /dev/null +++ b/sc/qa/extras/scsubtotaldescriptorbase.cxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/subtotaldescriptor.hxx> +#include <test/sheet/xsubtotaldescriptor.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/sheet/XSubTotalField.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSubTotalDescriptorBase : public UnoApiTest, + public apitest::SubTotalDescriptor, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XSubTotalDescriptor +{ +public: + ScSubTotalDescriptorBase(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScSubTotalDescriptorBase); + + // SubTotalDescriptor + CPPUNIT_TEST(testSubTotalDescriptorProperties); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XSubTotalDescriptor + CPPUNIT_TEST(testAddNew); + CPPUNIT_TEST(testClear); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScSubTotalDescriptorBase::ScSubTotalDescriptorBase() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSubTotalField>::get()) + , XIndexAccess(1) + , XServiceInfo("ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor") +{ +} + +uno::Reference<uno::XInterface> ScSubTotalDescriptorBase::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSubTotalCalculatable> xSTC(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSubTotalDescriptor> xSTD = xSTC->createSubTotalDescriptor(true); + + uno::Sequence<sheet::SubTotalColumn> xCols{ { /* Column */ 5, + /* Function */ sheet::GeneralFunction_SUM } }; + xSTD->addNew(xCols, 10); + + return xSTD; +} + +void ScSubTotalDescriptorBase::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSubTotalDescriptorBase); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsubtotalfieldobj.cxx b/sc/qa/extras/scsubtotalfieldobj.cxx new file mode 100644 index 0000000000..bb40eb0e9e --- /dev/null +++ b/sc/qa/extras/scsubtotalfieldobj.cxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/xsubtotalfield.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/sheet/XSubTotalField.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSubTotalFieldObj : public UnoApiTest, public apitest::XSubTotalField +{ +public: + ScSubTotalFieldObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScSubTotalFieldObj); + + // XSubTotalField + CPPUNIT_TEST(testGetSetGroupColumn); + CPPUNIT_TEST(testGetSetTotalColumns); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScSubTotalFieldObj::ScSubTotalFieldObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScSubTotalFieldObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSubTotalCalculatable> xSubTotalCalc(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSubTotalDescriptor> xSubTotalDesc + = xSubTotalCalc->createSubTotalDescriptor(true); + + uno::Sequence<sheet::SubTotalColumn> xCols{ { /* Column */ 5, + /* Function */ sheet::GeneralFunction_SUM } }; + xSubTotalDesc->addNew(xCols, 1); + + uno::Reference<container::XIndexAccess> xDescIndex(xSubTotalDesc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSubTotalField> xSTF(xDescIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + return xSTF; +} + +void ScSubTotalFieldObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSubTotalFieldObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablecolumnobj.cxx b/sc/qa/extras/sctablecolumnobj.cxx new file mode 100644 index 0000000000..fffc29518d --- /dev/null +++ b/sc/qa/extras/sctablecolumnobj.cxx @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/tablecolumn.hxx> +#include <test/table/xcellrange.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScTableColumnObj : public UnoApiTest, + public apitest::TableColumn, + public apitest::XCellRange, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScTableColumnObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTableColumnObj); + + // TableColumn + CPPUNIT_TEST(testTableColumnProperties); + + // XCellRange + CPPUNIT_TEST(testGetCellByPosition); + CPPUNIT_TEST(testGetCellRangeByName); + CPPUNIT_TEST(testGetCellRangeByPosition); + + // XNamed + CPPUNIT_TEST(testGetName); + // because TableColumnNames are fixed, test for an exception + CPPUNIT_TEST(testSetNameThrowsException); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTableColumnObj::ScTableColumnObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XCellRange("K1:K1") + , XNamed("K") + , XPropertySet({ + "BottomBorder", + "BottomBorder2", + "BottomBorderComplexColor", + "CellProtection", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "CharPosture", + "CharPostureAsian", + "CharPostureComplex", + "ConditionalFormat", + "ConditionalFormatLocal", + "ConditionalFormatXML", + "DiagonalBLTR", + "DiagonalBLTR2", + "DiagonalTLBR", + "DiagonalTLBR2", + "HoriJustify", + "LeftBorder", + "LeftBorder2", + "LeftBorderComplexColor", + "NumberingRules", + "Orientation", + "RightBorder", + "RightBorder2", + "RightBorderComplexColor", + "ShadowFormat", + "TableBorder", + "TableBorder2", + "TopBorder", + "TopBorder2", + "TopBorderComplexColor", + "UserDefinedAttributes", + "Validation", + "ValidationLocal", + "ValidationXML", + "WritingMode", + }) + , XServiceInfo("ScTableColumnObj", "com.sun.star.table.TableColumn") +{ +} + +uno::Reference<uno::XInterface> ScTableColumnObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + setSpreadsheet(xSheet0); + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableColumns> xTC(xCRR->getColumns(), uno::UNO_SET_THROW); + + uno::Reference<container::XIndexAccess> xIA_TC(xTC, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xIA_TC->getByIndex(10), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScTableColumnObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableColumnObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablecolumnsobj.cxx b/sc/qa/extras/sctablecolumnsobj.cxx new file mode 100644 index 0000000000..d7140480db --- /dev/null +++ b/sc/qa/extras/sctablecolumnsobj.cxx @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/xtablecolumns.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <sheetlimits.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScTableColumnsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XTableColumns +{ +public: + ScTableColumnsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTableColumnsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableColumns + CPPUNIT_TEST(testInsertByIndex); + CPPUNIT_TEST(testInsertByIndexWithNegativeIndex); + CPPUNIT_TEST(testInsertByIndexWithNoColumn); + CPPUNIT_TEST(testInsertByIndexWithOutOfBoundIndex); + CPPUNIT_TEST(testRemoveByIndex); + CPPUNIT_TEST(testRemoveByIndexWithNegativeIndex); + CPPUNIT_TEST(testRemoveByIndexWithNoColumn); + CPPUNIT_TEST(testRemoveByIndexWithOutOfBoundIndex); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTableColumnsObj::ScTableColumnsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCellRange>::get()) + , XIndexAccess(ScSheetLimits::CreateDefault().GetMaxColCount()) + , XNameAccess("ABC") + , XServiceInfo("ScTableColumnsObj", "com.sun.star.table.TableColumns") +{ +} + +uno::Reference<uno::XInterface> ScTableColumnsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableColumns> xTC(xCRR->getColumns(), uno::UNO_SET_THROW); + setXSpreadsheet(xSheet0); + + uno::Reference<table::XCellRange> xCR(xSheet0, uno::UNO_QUERY_THROW); + for (auto i = 0; i < xTC->getCount() - 1 && i < 3; ++i) + { + uno::Reference<text::XSimpleText> xST0(xCR->getCellByPosition(i, 0), uno::UNO_QUERY_THROW); + xST0->setString(OUString::number(i) + "a"); + uno::Reference<text::XSimpleText> xST1(xCR->getCellByPosition(i, 1), uno::UNO_QUERY_THROW); + xST1->setString(OUString::number(i) + "b"); + } + for (auto i = 3; i < xTC->getCount() - 1 && i < 10; ++i) + { + uno::Reference<text::XSimpleText> xST0(xCR->getCellByPosition(i, 0), uno::UNO_QUERY_THROW); + xST0->setString(""); + uno::Reference<text::XSimpleText> xST1(xCR->getCellByPosition(i, 1), uno::UNO_QUERY_THROW); + xST1->setString(""); + } + return xTC; +} + +void ScTableColumnsObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableColumnsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctableconditionalentryobj.cxx b/sc/qa/extras/sctableconditionalentryobj.cxx new file mode 100644 index 0000000000..8954937934 --- /dev/null +++ b/sc/qa/extras/sctableconditionalentryobj.cxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/sheet/xsheetconditionalentry.hxx> +#include <test/sheet/xsheetcondition.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> + +#include <unonames.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +#include <comphelper/propertyvalue.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableConditionalEntryObj : public UnoApiTest, + public apitest::XSheetConditionalEntry, + public apitest::XSheetCondition +{ +public: + ScTableConditionalEntryObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTableConditionalEntryObj); + + // XSheetConditionalEntry + CPPUNIT_TEST(testGetSetStyleName); + + // XSheetCondition + CPPUNIT_TEST(testGetSetFormula1); + CPPUNIT_TEST(testGetSetFormula2); + CPPUNIT_TEST(testGetSetOperator); + CPPUNIT_TEST(testGetSetSourcePosition); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTableConditionalEntryObj::ScTableConditionalEntryObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScTableConditionalEntryObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries; + xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT), + uno::UNO_QUERY_THROW); + + uno::Sequence<beans::PropertyValue> aPropValue{ + comphelper::makePropertyValue(SC_UNONAME_STYLENAME, OUString("Result2")), + comphelper::makePropertyValue(SC_UNONAME_FORMULA1, OUString("$Sheet1.$B$5")), + comphelper::makePropertyValue(SC_UNONAME_FORMULA2, OUString("")), + comphelper::makePropertyValue(SC_UNONAME_OPERATOR, sheet::ConditionOperator_EQUAL), + comphelper::makePropertyValue(SC_UNONAME_SOURCEPOS, table::CellAddress(0, 1, 5)) + }; + xSheetConditionalEntries->addNew(aPropValue); + + uno::Reference<sheet::XSheetConditionalEntry> xSheetConditionalEntry( + xSheetConditionalEntries->getByIndex(0), uno::UNO_QUERY_THROW); + return xSheetConditionalEntry; +} + +void ScTableConditionalEntryObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalEntryObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctableconditionalformat.cxx b/sc/qa/extras/sctableconditionalformat.cxx new file mode 100644 index 0000000000..7d752c3acb --- /dev/null +++ b/sc/qa/extras/sctableconditionalformat.cxx @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xsheetconditionalentries.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <unonames.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <comphelper/propertyvalue.hxx> +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableConditionalFormat : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XSheetConditionalEntries +{ +public: + ScTableConditionalFormat(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Sequence<beans::PropertyValue> createCondition(const sal_Int32 nr) override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTableConditionalFormat); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetConditionalEntries + CPPUNIT_TEST(testAddNew); + CPPUNIT_TEST(testClear); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTableConditionalFormat::ScTableConditionalFormat() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSheetConditionalEntry>::get()) + , XIndexAccess(2) + , XNameAccess("Entry1") + , XServiceInfo("ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat") +{ +} + +uno::Reference<uno::XInterface> ScTableConditionalFormat::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries; + xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT), + uno::UNO_QUERY_THROW); + + xSheetConditionalEntries->addNew(createCondition(5)); + xSheetConditionalEntries->addNew(createCondition(2)); + + return xSheetConditionalEntries; +} + +uno::Sequence<beans::PropertyValue> ScTableConditionalFormat::createCondition(const sal_Int32 nr) +{ + uno::Sequence<beans::PropertyValue> aPropValue{ + comphelper::makePropertyValue(SC_UNONAME_STYLENAME, OUString("Result2")), + comphelper::makePropertyValue(SC_UNONAME_FORMULA1, "$Sheet1.$B$" + OUString::number(nr)), + comphelper::makePropertyValue(SC_UNONAME_FORMULA2, OUString("")), + comphelper::makePropertyValue(SC_UNONAME_OPERATOR, sheet::ConditionOperator_EQUAL), + comphelper::makePropertyValue(SC_UNONAME_SOURCEPOS, table::CellAddress(0, 1, 5)) + }; + + return aPropValue; +} + +void ScTableConditionalFormat::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalFormat); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablerowobj.cxx b/sc/qa/extras/sctablerowobj.cxx new file mode 100644 index 0000000000..4f03cde4dd --- /dev/null +++ b/sc/qa/extras/sctablerowobj.cxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/tablerow.hxx> +#include <test/table/xcellrange.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScTableRowObj : public UnoApiTest, + public apitest::TableRow, + public apitest::XCellRange, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScTableRowObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTableRowObj); + + // TableRow + CPPUNIT_TEST(testTableRowProperties); + + // XCellRange + CPPUNIT_TEST(testGetCellByPosition); + CPPUNIT_TEST(testGetCellRangeByName); + CPPUNIT_TEST(testGetCellRangeByPosition); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTableRowObj::ScTableRowObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XCellRange("A7:A7") + , XPropertySet({ "BottomBorder", + "BottomBorder2", + "BottomBorderComplexColor", + "CellProtection", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "CharPosture", + "CharPostureAsian", + "CharPostureComplex", + "ConditionalFormat", + "ConditionalFormatLocal", + "ConditionalFormatXML", + "DiagonalBLTR", + "DiagonalBLTR2", + "DiagonalTLBR", + "DiagonalTLBR2", + "HoriJustify", + "LeftBorder", + "LeftBorder2", + "LeftBorderComplexColor", + "NumberingRules", + "Orientation", + "RightBorder", + "RightBorder2", + "RightBorderComplexColor", + "ShadowFormat", + "TableBorder", + "TableBorder2", + "TopBorder", + "TopBorder2", + "TopBorderComplexColor", + "UserDefinedAttributes", + "Validation", + "ValidationLocal", + "ValidationXML", + "WritingMode" }) + , XServiceInfo("ScTableRowObj", "com.sun.star.table.TableRow") +{ +} + +uno::Reference<uno::XInterface> ScTableRowObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xTR(xCRR->getRows(), uno::UNO_SET_THROW); + + uno::Reference<container::XIndexAccess> xIA_TR(xTR, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xIA_TR->getByIndex(6), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScTableRowObj::setUp() +{ + UnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableRowObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablerowsobj.cxx b/sc/qa/extras/sctablerowsobj.cxx new file mode 100644 index 0000000000..6b491d8235 --- /dev/null +++ b/sc/qa/extras/sctablerowsobj.cxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/xtablerows.hxx> + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +#include <sheetlimits.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTableRowsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo, + public apitest::XTableRows +{ +public: + ScTableRowsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXCellRange() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTableRowsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableRows + CPPUNIT_TEST(testInsertByIndex); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTableRowsObj::ScTableRowsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCellRange>::get()) + , XIndexAccess(ScSheetLimits::CreateDefault().GetMaxRowCount()) + , XServiceInfo("ScTableRowsObj", "com.sun.star.table.TableRows") +{ +} + +uno::Reference<uno::XInterface> ScTableRowsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xSheets->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xTR(xCRR->getRows(), uno::UNO_SET_THROW); + + return xTR; +} + +uno::Reference<uno::XInterface> ScTableRowsObj::getXCellRange() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xSheets->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCR(xSheet0, uno::UNO_QUERY_THROW); + return xCR; +} + +void ScTableRowsObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableRowsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablesheetobj.cxx b/sc/qa/extras/sctablesheetobj.cxx new file mode 100644 index 0000000000..1c4543af95 --- /dev/null +++ b/sc/qa/extras/sctablesheetobj.cxx @@ -0,0 +1,366 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/sheet/scenario.hxx> +#include <test/sheet/sheetcellrange.hxx> +#include <test/sheet/spreadsheet.hxx> +#include <test/sheet/xarrayformularange.hxx> +#include <test/sheet/xcellformatrangessupplier.hxx> +#include <test/sheet/xcellrangeaddressable.hxx> +#include <test/sheet/xcellrangedata.hxx> +#include <test/sheet/xcellrangeformula.hxx> +#include <test/sheet/xcellrangemovement.hxx> +#include <test/sheet/xcellseries.hxx> +#include <test/sheet/xdatapilottablessupplier.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xmultipleoperation.hxx> +#include <test/sheet/xprintareas.hxx> +#include <test/sheet/xscenario.hxx> +#include <test/sheet/xscenarioenhanced.hxx> +#include <test/sheet/xscenariossupplier.hxx> +#include <test/sheet/xsheetannotationssupplier.hxx> +#include <test/sheet/xsheetauditing.hxx> +#include <test/sheet/xsheetcellrange.hxx> +#include <test/sheet/xsheetfilterable.hxx> +#include <test/sheet/xsheetfilterableex.hxx> +#include <test/sheet/xsheetlinkable.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/sheet/xsheetpagebreak.hxx> +#include <test/sheet/xspreadsheet.hxx> +#include <test/sheet/xsubtotalcalculatable.hxx> +#include <test/sheet/xuniquecellformatrangessupplier.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/table/xtablechartssupplier.hxx> +#include <test/util/xindent.hxx> +#include <test/util/xmergeable.hxx> +#include <test/util/xreplaceable.hxx> +#include <test/util/xsearchable.hxx> + +#include <com/sun/star/sheet/XScenariosSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <sheetlimits.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ + +class ScTableSheetObj : public UnoApiTest, public apitest::Scenario, + public apitest::SheetCellRange, + public apitest::Spreadsheet, + public apitest::XArrayFormulaRange, + public apitest::XCellFormatRangesSupplier, + public apitest::XCellRangeAddressable, + public apitest::XCellRangeData, + public apitest::XCellRangeFormula, + public apitest::XCellRangeMovement, + public apitest::XCellSeries, + public apitest::XColumnRowRange, + public apitest::XDataPilotTablesSupplier, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XMergeable, + public apitest::XMultipleOperation, + public apitest::XPrintAreas, + public apitest::XReplaceable, + public apitest::XScenario, + public apitest::XScenarioEnhanced, + public apitest::XScenariosSupplier, + public apitest::XSearchable, + public apitest::XSheetAnnotationsSupplier, + public apitest::XSheetAuditing, + public apitest::XSheetCellRange, + public apitest::XSheetFilterable, + public apitest::XSheetFilterableEx, + public apitest::XSheetLinkable, + public apitest::XSheetOperation, + public apitest::XSheetPageBreak, + public apitest::XSpreadsheet, + public apitest::XSubTotalCalculatable, + public apitest::XTableChartsSupplier, + public apitest::XUniqueCellFormatRangesSupplier +{ +public: + ScTableSheetObj(); + + virtual void setUp() override; + + virtual OUString getFileURL() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > getXCellRangeData() override; + virtual uno::Reference< uno::XInterface > getXSpreadsheetDocument() override; + virtual uno::Reference< uno::XInterface > getXSpreadsheet() override; + virtual uno::Reference< uno::XInterface > getScenarioSpreadsheet() override; + + CPPUNIT_TEST_SUITE(ScTableSheetObj); + + // Scenario + CPPUNIT_TEST(testScenarioProperties); + + // SheetCellRange + CPPUNIT_TEST(testSheetCellRangeProperties); + + // Spreadsheet + CPPUNIT_TEST(testSpreadsheetProperties); + + // XArrayFormulaRange +#if 0 // disable, because it makes no sense to set an ArrayFormula over the whole sheet + CPPUNIT_TEST(testGetSetArrayFormula); +#endif + + // XCellFormatRangesSupplier + CPPUNIT_TEST(testGetCellFormatRanges); + + // XCellRangeAddressable + CPPUNIT_TEST(testGetRangeAddress); + + // XCellRangeData + CPPUNIT_TEST(testGetDataArrayOnTableSheet); + CPPUNIT_TEST(testSetDataArrayOnTableSheet); + + // XCellRangeFormula +#if 0 // disable, because it makes no sense to set a FormulaArray over the whole sheet + CPPUNIT_TEST(testGetSetFormulaArray); +#endif + + // XCellRangeMovement + CPPUNIT_TEST(testInsertCells); + CPPUNIT_TEST(testCopyRange); + CPPUNIT_TEST(testMoveRange); + CPPUNIT_TEST(testRemoveRange); + + // XCellSeries + CPPUNIT_TEST(testFillAuto); + CPPUNIT_TEST(testFillSeries); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XDataPilotTablesSupplier + CPPUNIT_TEST(testGetDataPilotTables); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XMergeable + CPPUNIT_TEST(testGetIsMergedMerge); + + // XSearchable + CPPUNIT_TEST(testFindAll); + CPPUNIT_TEST(testFindNext); + CPPUNIT_TEST(testFindFirst); + + // XMultipleOperation +#if 0 // disable, because test never finishes (see i87863) + CPPUNIT_TEST(testSetTableOperation); +#endif + + // XPrintAreas + CPPUNIT_TEST(testSetAndGetPrintTitleColumns); + CPPUNIT_TEST(testSetAndGetPrintTitleRows); + + // XReplaceable + CPPUNIT_TEST(testReplaceAll); + CPPUNIT_TEST(testCreateReplaceDescriptor); + + // XScenario + // test was disabled in qadevOOo/tests/java/ifc/sheet/_XScenario.java + CPPUNIT_TEST(testScenario); + + // XScenarioEnhanced + CPPUNIT_TEST(testGetRanges); + + // XScenariosSupplier + CPPUNIT_TEST(testGetScenarios); + + // XSheetAnnotationsSupplier + CPPUNIT_TEST(testGetAnnotations); + + // XSheetAuditing + CPPUNIT_TEST(testShowHideDependents); + CPPUNIT_TEST(testShowHidePrecedents); + CPPUNIT_TEST(testClearArrows); + CPPUNIT_TEST(testShowErrors); + CPPUNIT_TEST(testShowInvalid); + + // XSheetCellRange + CPPUNIT_TEST(testGetSpreadsheet); + + // XSheetFilterable + CPPUNIT_TEST(testCreateFilterDescriptor); + CPPUNIT_TEST(testFilter); + + // XSheetFilterableEx +#if 0 // temporarily disabled, takes too long (see i87876) + CPPUNIT_TEST(testCreateFilterDescriptorByObject); +#endif + + // XSheetLinkable + CPPUNIT_TEST(testSheetLinkable); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + // XSheetPageBreak + CPPUNIT_TEST(testGetColumnPageBreaks); + CPPUNIT_TEST(testGetRowPageBreaks); + CPPUNIT_TEST(testRemoveAllManualPageBreaks); + + // XSpreadsheet + CPPUNIT_TEST(testCreateCursor); + CPPUNIT_TEST(testCreateCursorByRange); + + // XSubTotalCalculatable + CPPUNIT_TEST(testCreateSubTotalDescriptor); + CPPUNIT_TEST(testApplyRemoveSubTotals); + + // XTableChartsSupplier + CPPUNIT_TEST(testGetCharts); + + // XUniqueCellFormatRangesSupplier + CPPUNIT_TEST(testGetUniqueCellFormatRanges); + + CPPUNIT_TEST_SUITE_END(); + +private: + OUString maFileURL; +}; + +ScTableSheetObj::ScTableSheetObj(): + UnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XCellSeries(1, 0), + apitest::XFormulaQuery( + table::CellRangeAddress(0, 0, 0, ScSheetLimits::CreateDefault().MaxCol(), ScSheetLimits::CreateDefault().MaxRow()), + table::CellRangeAddress(0, 0, 0, ScSheetLimits::CreateDefault().MaxCol(), ScSheetLimits::CreateDefault().MaxRow()), + 0, 0), + apitest::XReplaceable("searchReplaceString", "replaceReplaceString"), + apitest::XSearchable("test", 4) +{ +} + +uno::Reference< uno::XInterface > ScTableSheetObj::init() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + xSheet->getCellByPosition(5 ,5)->setValue(15); + xSheet->getCellByPosition(2 ,0)->setValue(-5.15); + xSheet->getCellByPosition(2 ,0)->setFormula("= B5 + C1"); + + xSheet->getCellByPosition(6, 6)->setValue(3); + xSheet->getCellByPosition(7, 6)->setValue(3); + xSheet->getCellByPosition(8, 6)->setFormula("= SUM(G7:H7)"); + xSheet->getCellByPosition(9, 6)->setFormula("= G7*I7"); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr { { 0, 0, 0, 10, 10 } }; + + uno::Reference<sheet::XScenariosSupplier> xScence(xSheet, UNO_QUERY_THROW); + xScence->getScenarios()->addNewByName("Scenario", aCellRangeAddr, "Comment"); + xSheets->getByName("Scenario"); + + return xSheet; +} + +uno::Reference< uno::XInterface > ScTableSheetObj::getXCellRangeData() +{ + return init(); +} + +uno::Reference<uno::XInterface> ScTableSheetObj::getXSpreadsheetDocument() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + return xDoc; +} + +uno::Reference<uno::XInterface> ScTableSheetObj::getScenarioSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + xSheet->getCellByPosition(5 ,5)->setValue(15); + xSheet->getCellByPosition(2 ,0)->setValue(-5.15); + xSheet->getCellByPosition(2 ,0)->setFormula("= B5 + C1"); + + xSheet->getCellByPosition(6, 6)->setValue(3); + xSheet->getCellByPosition(7, 6)->setValue(3); + xSheet->getCellByPosition(8, 6)->setFormula("= SUM(G7:H7)"); + xSheet->getCellByPosition(9, 6)->setFormula("= G7*I7"); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr { { 0, 0, 0, 10, 10 } }; + + uno::Reference<sheet::XScenariosSupplier> xScence(xSheet, UNO_QUERY_THROW); + xScence->getScenarios()->addNewByName("Scenario", aCellRangeAddr, "Comment"); + uno::Reference<sheet::XSpreadsheet> sSheet(xSheets->getByName("Scenario"), UNO_QUERY_THROW); + + return sSheet; +} + +uno::Reference< uno::XInterface > ScTableSheetObj::getXSpreadsheet() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + xSheet->getCellByPosition(5 ,5)->setValue(15); + xSheet->getCellByPosition(2 ,0)->setValue(-5.15); + xSheet->getCellByPosition(2 ,0)->setFormula("= B5 + C1"); + + xSheet->getCellByPosition(6, 6)->setValue(3); + xSheet->getCellByPosition(7, 6)->setValue(3); + xSheet->getCellByPosition(8, 6)->setFormula("= SUM(G7:H7)"); + xSheet->getCellByPosition(9, 6)->setFormula("= G7*I7"); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr { {0, 0, 0, 10, 10} }; + uno::Reference<sheet::XScenariosSupplier> xScence(xSheet, UNO_QUERY_THROW); + xScence->getScenarios()->addNewByName("Scenario", aCellRangeAddr, "Comment"); + xSheets->getByName("Scenario"); + + setXCell(xSheet->getCellByPosition(15, 15)); + return xSheet; +} + +OUString ScTableSheetObj::getFileURL() +{ + return maFileURL; +} + +void ScTableSheetObj::setUp() +{ + UnoApiTest::setUp(); + maFileURL = loadFromFile(u"ScTableSheetObj.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableSheetObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sctablesheetsobj.cxx b/sc/qa/extras/sctablesheetsobj.cxx new file mode 100644 index 0000000000..9fcd6d31e1 --- /dev/null +++ b/sc/qa/extras/sctablesheetsobj.cxx @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/container/xnamereplace.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xspreadsheets.hxx> +#include <test/sheet/xspreadsheets2.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTableSheetsObj : public UnoApiTest, + public ::apitest::XElementAccess, + public ::apitest::XEnumerationAccess, + public ::apitest::XIndexAccess, + public ::apitest::XNameAccess, + public ::apitest::XNameContainer, + public ::apitest::XNameReplace, + public ::apitest::XServiceInfo, + public ::apitest::XSpreadsheets, + public ::apitest::XSpreadsheets2 +{ +public: + ScTableSheetsObj(); + + virtual void setUp() override; + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScTableSheetsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testInsertByNameDuplicate); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XNameReplace + CPPUNIT_TEST(testReplaceByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSpreadsheets + CPPUNIT_TEST(testInsertNewByName); + CPPUNIT_TEST(testInsertNewByNameBadName); + CPPUNIT_TEST(testCopyByName); + CPPUNIT_TEST(testMoveByName); + + // XSpreadsheets2 + CPPUNIT_TEST(testImportedSheetNameAndIndex); + CPPUNIT_TEST(testImportString); + CPPUNIT_TEST(testImportValue); + CPPUNIT_TEST(testImportFormulaBasicMath); + CPPUNIT_TEST(testImportFormulaWithNamedRange); + CPPUNIT_TEST(testImportOverExistingNamedRange); + CPPUNIT_TEST(testImportNamedRangeDefinedInSource); + CPPUNIT_TEST(testImportNamedRangeRedefinedInSource); + CPPUNIT_TEST(testImportNewNamedRange); + CPPUNIT_TEST(testImportCellStyle); + CPPUNIT_TEST(testLastAfterInsertCopy); + + CPPUNIT_TEST_SUITE_END(); + + virtual uno::Reference<lang::XComponent> loadFromDesktop(const OUString& rFileBase) override; +}; + +ScTableSheetsObj::ScTableSheetsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , ::apitest::XElementAccess(cppu::UnoType<sheet::XSpreadsheet>::get()) + , ::apitest::XIndexAccess(3) + , ::apitest::XNameAccess("Sheet1") + , ::apitest::XNameContainer("Sheet2") + , ::apitest::XNameReplace("Sheet2") + , ::apitest::XServiceInfo("ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets") +{ +} + +uno::Reference<lang::XComponent> ScTableSheetsObj::loadFromDesktop(const OUString& rFileBase) +{ + OUString aString = createFileURL(rFileBase); + return UnoApiTest::loadFromDesktop(aString); +} + +uno::Reference<uno::XInterface> ScTableSheetsObj::init() +{ + xDocument.set(mxComponent, UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xDocument->getSheets(), UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY_THROW); + XNameContainer::setElement(uno::Any(xMSF->createInstance("com.sun.star.sheet.Spreadsheet"))); + // XNameReplace + XNameReplace::setElement(uno::Any(xMSF->createInstance("com.sun.star.sheet.Spreadsheet"))); + + return xReturn; +} + +void ScTableSheetsObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + loadFromFile(u"rangenamessrc.ods"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableSheetsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablevalidationobj.cxx b/sc/qa/extras/sctablevalidationobj.cxx new file mode 100644 index 0000000000..72b4930983 --- /dev/null +++ b/sc/qa/extras/sctablevalidationobj.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/tablevalidation.hxx> +#include <test/sheet/xsheetcondition.hxx> +#include <test/sheet/xmultiformulatokens.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetCondition.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableValidationObj : public UnoApiTest, + public apitest::TableValidation, + public apitest::XMultiFormulaTokens, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XSheetCondition +{ +public: + ScTableValidationObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTableValidationObj); + + // TableValidation + CPPUNIT_TEST(testTableValidationProperties); + + // XMultiFormulaTokens + CPPUNIT_TEST(testGetCount); + CPPUNIT_TEST(testGetSetTokens); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetCondition + CPPUNIT_TEST(testGetSetFormula1); + CPPUNIT_TEST(testGetSetFormula2); + CPPUNIT_TEST(testGetSetOperator); + CPPUNIT_TEST(testGetSetSourcePosition); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTableValidationObj::ScTableValidationObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "Type", "ErrorAlertStyle" }) + , XServiceInfo("ScTableValidationObj", "com.sun.star.sheet.TableValidation") +{ +} + +uno::Reference<uno::XInterface> ScTableValidationObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCondition> xSheetCondition; + CPPUNIT_ASSERT(xPropSet->getPropertyValue("Validation") >>= xSheetCondition); + + return xSheetCondition; +} + +void ScTableValidationObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableValidationObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctabviewobj.cxx b/sc/qa/extras/sctabviewobj.cxx new file mode 100644 index 0000000000..7e10f46da7 --- /dev/null +++ b/sc/qa/extras/sctabviewobj.cxx @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/spreadsheetviewsettings.hxx> +#include <test/sheet/xactivationbroadcaster.hxx> +#include <test/sheet/xcellrangereferrer.hxx> +#include <test/sheet/xspreadsheetview.hxx> +#include <test/sheet/xviewfreezable.hxx> +#include <test/sheet/xviewsplitable.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XViewPane.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTabViewObj : public UnoApiTest, + public apitest::SpreadsheetViewSettings, + public apitest::XActivationBroadcaster, + public apitest::XCellRangeReferrer, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XSpreadsheetView, + public apitest::XViewFreezable, + public apitest::XViewSplitable +{ +public: + ScTabViewObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet(const sal_Int16 nNumber = 0) override; + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScTabViewObj); + + // SpreadsheetViewSettings + CPPUNIT_TEST(testSpreadsheetViewSettingsProperties); + + // XActivationBroadcaster + CPPUNIT_TEST(testAddRemoveActivationEventListener); + + // XCellRangeReferrer + //Disabled till it's clear why it fails on some machines. + //CPPUNIT_TEST(testGetReferredCells); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XSpreadsheetView + CPPUNIT_TEST(testGetSetActiveSheet); + + // XViewFreezable + CPPUNIT_TEST(testFreeze); + + // XViewSplitable + CPPUNIT_TEST(testSplit); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScTabViewObj::ScTabViewObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XViewPane>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScTabViewObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY_THROW); + + setCellRange(table::CellRangeAddress(0, 0, 0, 6, 23)); + + return xModel->getCurrentController(); +} + +uno::Reference<uno::XInterface> ScTabViewObj::getXSpreadsheet(const sal_Int16 nNumber) +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + xSheets->insertNewByName("Sheet2", 2); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(nNumber), UNO_QUERY_THROW); + + return xSheet; +} + +void ScTabViewObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTabViewObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scuniquecellformatsenumeration.cxx b/sc/qa/extras/scuniquecellformatsenumeration.cxx new file mode 100644 index 0000000000..b295b244b8 --- /dev/null +++ b/sc/qa/extras/scuniquecellformatsenumeration.cxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <sal/types.h> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +namespace +{ +struct RGBColor +{ + int m_nRed; + int m_nGreen; + int m_nBlue; + + RGBColor(int nRed, int nGreen, int nBlue) + : m_nRed(nRed) + , m_nGreen(nGreen) + , m_nBlue(nBlue) + { + } + + sal_Int32 hashCode() const { return (255 << 24) | (m_nRed << 16) | (m_nGreen << 8) | m_nBlue; } +}; +} + +class ScUniqueCellFormatsEnumeration : public UnoApiTest, public apitest::XEnumeration +{ +public: + ScUniqueCellFormatsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScUniqueCellFormatsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + void changeColor(const uno::Reference<sheet::XSpreadsheet>& xSheet, const OUString& sRangeName, + const RGBColor& rgb); +}; + +ScUniqueCellFormatsEnumeration::ScUniqueCellFormatsEnumeration() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScUniqueCellFormatsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + changeColor(xSheet0, "A1:A5", RGBColor(0, 255, 0)); + changeColor(xSheet0, "A6:B10", RGBColor(255, 0, 0)); + changeColor(xSheet0, "B1:B6", RGBColor(0, 0, 255)); + changeColor(xSheet0, "B7", RGBColor(0, 255, 0)); + changeColor(xSheet0, "B8:B10", RGBColor(0, 0, 255)); + changeColor(xSheet0, "C1:C10", RGBColor(0, 0, 255)); + changeColor(xSheet0, "D1:D10", RGBColor(0, 255, 0)); + + uno::Reference<sheet::XUniqueCellFormatRangesSupplier> xUCFRS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xUCFRS->getUniqueCellFormatRanges(), + uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScUniqueCellFormatsEnumeration::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScUniqueCellFormatsEnumeration::changeColor(const uno::Reference<sheet::XSpreadsheet>& xSheet, + const OUString& sRangeName, const RGBColor& rgb) +{ + uno::Reference<table::XCellRange> xCellRange(xSheet->getCellRangeByName(sRangeName), + uno::UNO_SET_THROW); + uno::Reference<beans::XPropertySet> xPropertySet(xCellRange, uno::UNO_QUERY_THROW); + + sal_Int32 nColor = 16777216 + rgb.hashCode(); + uno::Any aValue; + aValue <<= nColor; + xPropertySet->setPropertyValue("CellBackColor", aValue); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScUniqueCellFormatsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scuniquecellformatsobj.cxx b/sc/qa/extras/scuniquecellformatsobj.cxx new file mode 100644 index 0000000000..f3470d16e5 --- /dev/null +++ b/sc/qa/extras/scuniquecellformatsobj.cxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScUniqueCellFormatsObj : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScUniqueCellFormatsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScUniqueCellFormatsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScUniqueCellFormatsObj::ScUniqueCellFormatsObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSheetCellRangeContainer>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScUniqueCellFormatsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XUniqueCellFormatRangesSupplier> xUCFRS(xSheet0, uno::UNO_QUERY_THROW); + return xUCFRS->getUniqueCellFormatRanges(); +} + +void ScUniqueCellFormatsObj::setUp() +{ + UnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScUniqueCellFormatsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scviewpaneobj.cxx b/sc/qa/extras/scviewpaneobj.cxx new file mode 100644 index 0000000000..5f2da19260 --- /dev/null +++ b/sc/qa/extras/scviewpaneobj.cxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xcellrangereferrer.hxx> +#include <test/sheet/xviewpane.hxx> +#include <test/view/xcontrolaccess.hxx> +#include <test/view/xformlayeraccess.hxx> +#include <test/helper/form.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/form/XForm.hpp> +#include <com/sun/star/form/XFormsSupplier.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XViewPane.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScViewPaneObj : public UnoApiTest, + public apitest::XCellRangeReferrer, + public apitest::XControlAccess, + public apitest::XFormLayerAccess, + public apitest::XServiceInfo, + public apitest::XViewPane +{ +public: + ScViewPaneObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXComponent() override; + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(ScViewPaneObj); + + // XCellRangeReferrer + CPPUNIT_TEST(testGetReferredCells); + + // XControlAccess + CPPUNIT_TEST(testGetControl); + + // XFormLayerAccess + CPPUNIT_TEST(testGetFormController); + CPPUNIT_TEST(testIsFormDesignMode); + CPPUNIT_TEST(testSetFormDesignMode); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XViewPane + CPPUNIT_TEST(testFirstVisibleColumn); + CPPUNIT_TEST(testFirstVisibleRow); + CPPUNIT_TEST(testVisibleRange); + + CPPUNIT_TEST_SUITE_END(); +}; + +ScViewPaneObj::ScViewPaneObj() + : UnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScViewPaneObj", "com.sun.star.sheet.SpreadsheetViewPane") +{ +} + +uno::Reference<uno::XInterface> ScViewPaneObj::getXComponent() { return mxComponent; } + +uno::Reference<uno::XInterface> ScViewPaneObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<frame::XController> xController(xModel->getCurrentController(), + uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xController, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XViewPane> xViewPane(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + xDP->insertNewByIndex(1); + xDP->insertNewByIndex(2); + + uno::Reference<drawing::XDrawPage> xDrawPage(xDP->getByIndex(0), uno::UNO_QUERY_THROW); + xDrawPage->add( + apitest::helper::form::createCommandButton(mxComponent, 15000, 10000, 3000, 4500)); + + uno::Reference<form::XFormsSupplier> xFS(xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xNC(xFS->getForms(), uno::UNO_SET_THROW); + + // XFormLayerAccess + uno::Reference<form::XForm> xForm(xNC->getByName("Form"), uno::UNO_QUERY_THROW); + setForm(xForm); + // XCellRangeReferrer + setCellRange(xViewPane->getVisibleRange()); + + return xViewPane; +} + +void ScViewPaneObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScViewPaneObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/testdocuments/AutoFilter.xls b/sc/qa/extras/testdocuments/AutoFilter.xls Binary files differnew file mode 100644 index 0000000000..1a8e5e5e99 --- /dev/null +++ b/sc/qa/extras/testdocuments/AutoFilter.xls diff --git a/sc/qa/extras/testdocuments/BGR-RGBTest.xls b/sc/qa/extras/testdocuments/BGR-RGBTest.xls Binary files differnew file mode 100644 index 0000000000..e2bf43fb0e --- /dev/null +++ b/sc/qa/extras/testdocuments/BGR-RGBTest.xls diff --git a/sc/qa/extras/testdocuments/BaseForHTMLExport.ods b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods Binary files differnew file mode 100644 index 0000000000..025b1e4806 --- /dev/null +++ b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods diff --git a/sc/qa/extras/testdocuments/CalcFont.xls b/sc/qa/extras/testdocuments/CalcFont.xls Binary files differnew file mode 100644 index 0000000000..86304063c4 --- /dev/null +++ b/sc/qa/extras/testdocuments/CalcFont.xls diff --git a/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls b/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls Binary files differnew file mode 100644 index 0000000000..14cf152af3 --- /dev/null +++ b/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls diff --git a/sc/qa/extras/testdocuments/ForEachInSelection.ods b/sc/qa/extras/testdocuments/ForEachInSelection.ods Binary files differnew file mode 100644 index 0000000000..8706bfa8cb --- /dev/null +++ b/sc/qa/extras/testdocuments/ForEachInSelection.ods diff --git a/sc/qa/extras/testdocuments/GeneratedEventTest.xls b/sc/qa/extras/testdocuments/GeneratedEventTest.xls Binary files differnew file mode 100644 index 0000000000..9325de32d7 --- /dev/null +++ b/sc/qa/extras/testdocuments/GeneratedEventTest.xls diff --git a/sc/qa/extras/testdocuments/KeyShortcut.xlsm b/sc/qa/extras/testdocuments/KeyShortcut.xlsm Binary files differnew file mode 100644 index 0000000000..d684d2a482 --- /dev/null +++ b/sc/qa/extras/testdocuments/KeyShortcut.xlsm diff --git a/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods b/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods Binary files differnew file mode 100644 index 0000000000..35e2b985b8 --- /dev/null +++ b/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods diff --git a/sc/qa/extras/testdocuments/MiscControlTests.xls b/sc/qa/extras/testdocuments/MiscControlTests.xls Binary files differnew file mode 100644 index 0000000000..3503795b02 --- /dev/null +++ b/sc/qa/extras/testdocuments/MiscControlTests.xls diff --git a/sc/qa/extras/testdocuments/MiscRangeTests.xls b/sc/qa/extras/testdocuments/MiscRangeTests.xls Binary files differnew file mode 100644 index 0000000000..c6dffd4754 --- /dev/null +++ b/sc/qa/extras/testdocuments/MiscRangeTests.xls diff --git a/sc/qa/extras/testdocuments/MultiDocumentCopyPaste.xlsm b/sc/qa/extras/testdocuments/MultiDocumentCopyPaste.xlsm Binary files differnew file mode 100644 index 0000000000..4f24cf4e66 --- /dev/null +++ b/sc/qa/extras/testdocuments/MultiDocumentCopyPaste.xlsm diff --git a/sc/qa/extras/testdocuments/Names.xls b/sc/qa/extras/testdocuments/Names.xls Binary files differnew file mode 100644 index 0000000000..fcacf9bbde --- /dev/null +++ b/sc/qa/extras/testdocuments/Names.xls diff --git a/sc/qa/extras/testdocuments/NamesSheetLocal.xls b/sc/qa/extras/testdocuments/NamesSheetLocal.xls Binary files differnew file mode 100644 index 0000000000..9086d62a1f --- /dev/null +++ b/sc/qa/extras/testdocuments/NamesSheetLocal.xls diff --git a/sc/qa/extras/testdocuments/PageBreaks.xls b/sc/qa/extras/testdocuments/PageBreaks.xls Binary files differnew file mode 100644 index 0000000000..4e6ac0a42b --- /dev/null +++ b/sc/qa/extras/testdocuments/PageBreaks.xls diff --git a/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods Binary files differnew file mode 100644 index 0000000000..5d7b1a4c27 --- /dev/null +++ b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods diff --git a/sc/qa/extras/testdocuments/Ranges-2.xls b/sc/qa/extras/testdocuments/Ranges-2.xls Binary files differnew file mode 100644 index 0000000000..84fdc45c0d --- /dev/null +++ b/sc/qa/extras/testdocuments/Ranges-2.xls diff --git a/sc/qa/extras/testdocuments/Ranges-3.xls b/sc/qa/extras/testdocuments/Ranges-3.xls Binary files differnew file mode 100644 index 0000000000..f96620f218 --- /dev/null +++ b/sc/qa/extras/testdocuments/Ranges-3.xls diff --git a/sc/qa/extras/testdocuments/Ranges.xls b/sc/qa/extras/testdocuments/Ranges.xls Binary files differnew file mode 100644 index 0000000000..7a513de258 --- /dev/null +++ b/sc/qa/extras/testdocuments/Ranges.xls diff --git a/sc/qa/extras/testdocuments/RecordChangesProtected.ods b/sc/qa/extras/testdocuments/RecordChangesProtected.ods Binary files differnew file mode 100644 index 0000000000..fac012d84c --- /dev/null +++ b/sc/qa/extras/testdocuments/RecordChangesProtected.ods diff --git a/sc/qa/extras/testdocuments/ScAnnotationObj.ods b/sc/qa/extras/testdocuments/ScAnnotationObj.ods Binary files differnew file mode 100644 index 0000000000..bed0680b95 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScAnnotationObj.ods diff --git a/sc/qa/extras/testdocuments/ScCellCursorObj.ods b/sc/qa/extras/testdocuments/ScCellCursorObj.ods Binary files differnew file mode 100644 index 0000000000..46d8090ec5 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScCellCursorObj.ods diff --git a/sc/qa/extras/testdocuments/ScDDELinksObj.ods b/sc/qa/extras/testdocuments/ScDDELinksObj.ods Binary files differnew file mode 100644 index 0000000000..01c11e339a --- /dev/null +++ b/sc/qa/extras/testdocuments/ScDDELinksObj.ods diff --git a/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods b/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods Binary files differnew file mode 100644 index 0000000000..e160f5edd3 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods diff --git a/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods b/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods Binary files differnew file mode 100644 index 0000000000..48f001ccdb --- /dev/null +++ b/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods diff --git a/sc/qa/extras/testdocuments/ScModelObj.ods b/sc/qa/extras/testdocuments/ScModelObj.ods Binary files differnew file mode 100644 index 0000000000..56a25329cb --- /dev/null +++ b/sc/qa/extras/testdocuments/ScModelObj.ods diff --git a/sc/qa/extras/testdocuments/ScNamedRangeObj.ods b/sc/qa/extras/testdocuments/ScNamedRangeObj.ods Binary files differnew file mode 100644 index 0000000000..6bd563623f --- /dev/null +++ b/sc/qa/extras/testdocuments/ScNamedRangeObj.ods diff --git a/sc/qa/extras/testdocuments/ScOutlineObj.ods b/sc/qa/extras/testdocuments/ScOutlineObj.ods Binary files differnew file mode 100644 index 0000000000..bc4642a33a --- /dev/null +++ b/sc/qa/extras/testdocuments/ScOutlineObj.ods diff --git a/sc/qa/extras/testdocuments/ScSheetLinkObj.ods b/sc/qa/extras/testdocuments/ScSheetLinkObj.ods Binary files differnew file mode 100644 index 0000000000..7f09e0d978 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScSheetLinkObj.ods diff --git a/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods b/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods Binary files differnew file mode 100644 index 0000000000..0cc718c98b --- /dev/null +++ b/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods diff --git a/sc/qa/extras/testdocuments/ScTableSheetObj.ods b/sc/qa/extras/testdocuments/ScTableSheetObj.ods Binary files differnew file mode 100644 index 0000000000..a18b1e7d5a --- /dev/null +++ b/sc/qa/extras/testdocuments/ScTableSheetObj.ods diff --git a/sc/qa/extras/testdocuments/Shapes.xls b/sc/qa/extras/testdocuments/Shapes.xls Binary files differnew file mode 100644 index 0000000000..dbccf3da33 --- /dev/null +++ b/sc/qa/extras/testdocuments/Shapes.xls diff --git a/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm Binary files differnew file mode 100644 index 0000000000..684480c3ff --- /dev/null +++ b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm diff --git a/sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm b/sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm Binary files differnew file mode 100644 index 0000000000..6c71c75b34 --- /dev/null +++ b/sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm diff --git a/sc/qa/extras/testdocuments/StarBasic.ods b/sc/qa/extras/testdocuments/StarBasic.ods Binary files differnew file mode 100644 index 0000000000..6b94f0684e --- /dev/null +++ b/sc/qa/extras/testdocuments/StarBasic.ods diff --git a/sc/qa/extras/testdocuments/TestAddress.xls b/sc/qa/extras/testdocuments/TestAddress.xls Binary files differnew file mode 100644 index 0000000000..629645c41c --- /dev/null +++ b/sc/qa/extras/testdocuments/TestAddress.xls diff --git a/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls b/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls Binary files differnew file mode 100644 index 0000000000..9c00f5522c --- /dev/null +++ b/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls diff --git a/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls b/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls Binary files differnew file mode 100644 index 0000000000..409459df64 --- /dev/null +++ b/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls diff --git a/sc/qa/extras/testdocuments/TestIntersection.xls b/sc/qa/extras/testdocuments/TestIntersection.xls Binary files differnew file mode 100644 index 0000000000..5872be7ca1 --- /dev/null +++ b/sc/qa/extras/testdocuments/TestIntersection.xls diff --git a/sc/qa/extras/testdocuments/TestUnion.xls b/sc/qa/extras/testdocuments/TestUnion.xls Binary files differnew file mode 100644 index 0000000000..bde207e746 --- /dev/null +++ b/sc/qa/extras/testdocuments/TestUnion.xls diff --git a/sc/qa/extras/testdocuments/VariousTestMacros.xlsm b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm Binary files differnew file mode 100644 index 0000000000..455dad654e --- /dev/null +++ b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm diff --git a/sc/qa/extras/testdocuments/Window.xls b/sc/qa/extras/testdocuments/Window.xls Binary files differnew file mode 100644 index 0000000000..3daebfb99b --- /dev/null +++ b/sc/qa/extras/testdocuments/Window.xls diff --git a/sc/qa/extras/testdocuments/Workbooks.xls b/sc/qa/extras/testdocuments/Workbooks.xls Binary files differnew file mode 100644 index 0000000000..2e8a7e78b4 --- /dev/null +++ b/sc/qa/extras/testdocuments/Workbooks.xls diff --git a/sc/qa/extras/testdocuments/bytearraystring.xls b/sc/qa/extras/testdocuments/bytearraystring.xls Binary files differnew file mode 100644 index 0000000000..22da6de484 --- /dev/null +++ b/sc/qa/extras/testdocuments/bytearraystring.xls diff --git a/sc/qa/extras/testdocuments/cond_format_merge.ods b/sc/qa/extras/testdocuments/cond_format_merge.ods Binary files differnew file mode 100644 index 0000000000..43b676d220 --- /dev/null +++ b/sc/qa/extras/testdocuments/cond_format_merge.ods diff --git a/sc/qa/extras/testdocuments/default-styles.ods b/sc/qa/extras/testdocuments/default-styles.ods Binary files differnew file mode 100644 index 0000000000..d2167ed202 --- /dev/null +++ b/sc/qa/extras/testdocuments/default-styles.ods diff --git a/sc/qa/extras/testdocuments/forcepoint97.xlsx b/sc/qa/extras/testdocuments/forcepoint97.xlsx Binary files differnew file mode 100644 index 0000000000..152fbbc45a --- /dev/null +++ b/sc/qa/extras/testdocuments/forcepoint97.xlsx diff --git a/sc/qa/extras/testdocuments/macro-button-form-control.xlsm b/sc/qa/extras/testdocuments/macro-button-form-control.xlsm Binary files differnew file mode 100644 index 0000000000..e4e76b13ff --- /dev/null +++ b/sc/qa/extras/testdocuments/macro-button-form-control.xlsm diff --git a/sc/qa/extras/testdocuments/new_cond_format_api.ods b/sc/qa/extras/testdocuments/new_cond_format_api.ods Binary files differnew file mode 100644 index 0000000000..06bb1d7592 --- /dev/null +++ b/sc/qa/extras/testdocuments/new_cond_format_api.ods diff --git a/sc/qa/extras/testdocuments/pagesetup.xls b/sc/qa/extras/testdocuments/pagesetup.xls Binary files differnew file mode 100644 index 0000000000..db1033af79 --- /dev/null +++ b/sc/qa/extras/testdocuments/pagesetup.xls diff --git a/sc/qa/extras/testdocuments/range-4.xls b/sc/qa/extras/testdocuments/range-4.xls Binary files differnew file mode 100644 index 0000000000..67d1ad7aa6 --- /dev/null +++ b/sc/qa/extras/testdocuments/range-4.xls diff --git a/sc/qa/extras/testdocuments/rangenamessrc.ods b/sc/qa/extras/testdocuments/rangenamessrc.ods Binary files differnew file mode 100644 index 0000000000..d22702bda2 --- /dev/null +++ b/sc/qa/extras/testdocuments/rangenamessrc.ods diff --git a/sc/qa/extras/testdocuments/scarealinkobj.ods b/sc/qa/extras/testdocuments/scarealinkobj.ods Binary files differnew file mode 100644 index 0000000000..7f09e0d978 --- /dev/null +++ b/sc/qa/extras/testdocuments/scarealinkobj.ods diff --git a/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods b/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods Binary files differnew file mode 100644 index 0000000000..8ba12e6385 --- /dev/null +++ b/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods diff --git a/sc/qa/extras/testdocuments/tdf104902.ods b/sc/qa/extras/testdocuments/tdf104902.ods Binary files differnew file mode 100644 index 0000000000..8524522fdc --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf104902.ods diff --git a/sc/qa/extras/testdocuments/tdf105558.ods b/sc/qa/extras/testdocuments/tdf105558.ods Binary files differnew file mode 100644 index 0000000000..0ea77ee668 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf105558.ods diff --git a/sc/qa/extras/testdocuments/tdf107885.xlsm b/sc/qa/extras/testdocuments/tdf107885.xlsm Binary files differnew file mode 100644 index 0000000000..f16d8b1b38 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf107885.xlsm diff --git a/sc/qa/extras/testdocuments/tdf107902.xlsm b/sc/qa/extras/testdocuments/tdf107902.xlsm Binary files differnew file mode 100644 index 0000000000..f5333959b0 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf107902.xlsm diff --git a/sc/qa/extras/testdocuments/tdf114427.ods b/sc/qa/extras/testdocuments/tdf114427.ods Binary files differnew file mode 100644 index 0000000000..656398661b --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf114427.ods diff --git a/sc/qa/extras/testdocuments/tdf118247.xlsm b/sc/qa/extras/testdocuments/tdf118247.xlsm Binary files differnew file mode 100644 index 0000000000..73de66a0d4 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf118247.xlsm diff --git a/sc/qa/extras/testdocuments/tdf120161.ods b/sc/qa/extras/testdocuments/tdf120161.ods Binary files differnew file mode 100644 index 0000000000..4b2c6e3ce6 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf120161.ods diff --git a/sc/qa/extras/testdocuments/tdf125800.ods b/sc/qa/extras/testdocuments/tdf125800.ods Binary files differnew file mode 100644 index 0000000000..91f000d749 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf125800.ods diff --git a/sc/qa/extras/testdocuments/tdf128218.ods b/sc/qa/extras/testdocuments/tdf128218.ods Binary files differnew file mode 100644 index 0000000000..9fa3e8b4ec --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf128218.ods diff --git a/sc/qa/extras/testdocuments/tdf130307.ods b/sc/qa/extras/testdocuments/tdf130307.ods Binary files differnew file mode 100644 index 0000000000..fc354cf2cb --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf130307.ods diff --git a/sc/qa/extras/testdocuments/tdf131296_legacy.ods b/sc/qa/extras/testdocuments/tdf131296_legacy.ods Binary files differnew file mode 100644 index 0000000000..43ebdeb24f --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf131296_legacy.ods diff --git a/sc/qa/extras/testdocuments/tdf131296_new.ods b/sc/qa/extras/testdocuments/tdf131296_new.ods Binary files differnew file mode 100644 index 0000000000..9c0161c40c --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf131296_new.ods diff --git a/sc/qa/extras/testdocuments/tdf131562.xlsm b/sc/qa/extras/testdocuments/tdf131562.xlsm Binary files differnew file mode 100644 index 0000000000..e56576ba45 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf131562.xlsm diff --git a/sc/qa/extras/testdocuments/tdf133887.ods b/sc/qa/extras/testdocuments/tdf133887.ods Binary files differnew file mode 100644 index 0000000000..92d135f583 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf133887.ods diff --git a/sc/qa/extras/testdocuments/tdf133889.ods b/sc/qa/extras/testdocuments/tdf133889.ods Binary files differnew file mode 100644 index 0000000000..db87da6129 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf133889.ods diff --git a/sc/qa/extras/testdocuments/tdf138646.ods b/sc/qa/extras/testdocuments/tdf138646.ods Binary files differnew file mode 100644 index 0000000000..9faa95a543 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf138646.ods diff --git a/sc/qa/extras/testdocuments/tdf142033.ods b/sc/qa/extras/testdocuments/tdf142033.ods Binary files differnew file mode 100644 index 0000000000..da49b73234 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf142033.ods diff --git a/sc/qa/extras/testdocuments/tdf142391.ods b/sc/qa/extras/testdocuments/tdf142391.ods Binary files differnew file mode 100644 index 0000000000..aa62239ebe --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf142391.ods diff --git a/sc/qa/extras/testdocuments/tdf143582.ods b/sc/qa/extras/testdocuments/tdf143582.ods Binary files differnew file mode 100644 index 0000000000..1375bf5b95 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf143582.ods diff --git a/sc/qa/extras/testdocuments/tdf143978.ods b/sc/qa/extras/testdocuments/tdf143978.ods Binary files differnew file mode 100644 index 0000000000..25a79defc6 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf143978.ods diff --git a/sc/qa/extras/testdocuments/tdf144085.ods b/sc/qa/extras/testdocuments/tdf144085.ods Binary files differnew file mode 100644 index 0000000000..2493695768 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf144085.ods diff --git a/sc/qa/extras/testdocuments/tdf144970.ods b/sc/qa/extras/testdocuments/tdf144970.ods Binary files differnew file mode 100644 index 0000000000..860521a520 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf144970.ods diff --git a/sc/qa/extras/testdocuments/tdf146742.ods b/sc/qa/extras/testdocuments/tdf146742.ods Binary files differnew file mode 100644 index 0000000000..18ede8a040 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf146742.ods diff --git a/sc/qa/extras/testdocuments/tdf149531.xls b/sc/qa/extras/testdocuments/tdf149531.xls Binary files differnew file mode 100644 index 0000000000..e79c16b009 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf149531.xls diff --git a/sc/qa/extras/testdocuments/tdf43003.ods b/sc/qa/extras/testdocuments/tdf43003.ods Binary files differnew file mode 100644 index 0000000000..3c40deefa4 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf43003.ods diff --git a/sc/qa/extras/testdocuments/tdf46119.ods b/sc/qa/extras/testdocuments/tdf46119.ods Binary files differnew file mode 100644 index 0000000000..953f75d648 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf46119.ods diff --git a/sc/qa/extras/testdocuments/tdf52602.xls b/sc/qa/extras/testdocuments/tdf52602.xls Binary files differnew file mode 100644 index 0000000000..1770b15fb4 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf52602.xls diff --git a/sc/qa/extras/testdocuments/tdf57113.ods b/sc/qa/extras/testdocuments/tdf57113.ods Binary files differnew file mode 100644 index 0000000000..9768e0de07 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf57113.ods diff --git a/sc/qa/extras/testdocuments/tdf64639.ods b/sc/qa/extras/testdocuments/tdf64639.ods Binary files differnew file mode 100644 index 0000000000..0b2e708d78 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf64639.ods diff --git a/sc/qa/extras/testdocuments/tdf64703_hiddenPageBreak.ods b/sc/qa/extras/testdocuments/tdf64703_hiddenPageBreak.ods Binary files differnew file mode 100644 index 0000000000..87f110915d --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf64703_hiddenPageBreak.ods diff --git a/sc/qa/extras/testdocuments/tdf75263.xlsm b/sc/qa/extras/testdocuments/tdf75263.xlsm Binary files differnew file mode 100644 index 0000000000..5a09ed677b --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf75263.xlsm diff --git a/sc/qa/extras/testdocuments/tdf78897.xls b/sc/qa/extras/testdocuments/tdf78897.xls Binary files differnew file mode 100644 index 0000000000..e2177fc785 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf78897.xls diff --git a/sc/qa/extras/testdocuments/tdf84012.ods b/sc/qa/extras/testdocuments/tdf84012.ods Binary files differnew file mode 100644 index 0000000000..c2f30e0f49 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf84012.ods diff --git a/sc/qa/extras/testdocuments/tdf89920.ods b/sc/qa/extras/testdocuments/tdf89920.ods Binary files differnew file mode 100644 index 0000000000..216a5cc75d --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf89920.ods diff --git a/sc/qa/extras/testdocuments/tdf90278.xls b/sc/qa/extras/testdocuments/tdf90278.xls Binary files differnew file mode 100644 index 0000000000..2d79455566 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf90278.xls diff --git a/sc/qa/extras/testdocuments/testTypePassword.ods b/sc/qa/extras/testdocuments/testTypePassword.ods Binary files differnew file mode 100644 index 0000000000..d75c17ace5 --- /dev/null +++ b/sc/qa/extras/testdocuments/testTypePassword.ods diff --git a/sc/qa/extras/testdocuments/vba.xls b/sc/qa/extras/testdocuments/vba.xls Binary files differnew file mode 100644 index 0000000000..22bee379ca --- /dev/null +++ b/sc/qa/extras/testdocuments/vba.xls diff --git a/sc/qa/extras/testdocuments/vba_endFunction.xls b/sc/qa/extras/testdocuments/vba_endFunction.xls Binary files differnew file mode 100644 index 0000000000..af7fa86256 --- /dev/null +++ b/sc/qa/extras/testdocuments/vba_endFunction.xls diff --git a/sc/qa/extras/testdocuments/vba_findFunction.xls b/sc/qa/extras/testdocuments/vba_findFunction.xls Binary files differnew file mode 100644 index 0000000000..bb0f450b1a --- /dev/null +++ b/sc/qa/extras/testdocuments/vba_findFunction.xls diff --git a/sc/qa/extras/testdocuments/window2.xls b/sc/qa/extras/testdocuments/window2.xls Binary files differnew file mode 100644 index 0000000000..d1822fa366 --- /dev/null +++ b/sc/qa/extras/testdocuments/window2.xls diff --git a/sc/qa/extras/testdocuments/xcellrangesquery.ods b/sc/qa/extras/testdocuments/xcellrangesquery.ods Binary files differnew file mode 100644 index 0000000000..494d79d369 --- /dev/null +++ b/sc/qa/extras/testdocuments/xcellrangesquery.ods diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx new file mode 100644 index 0000000000..5dc6157b43 --- /dev/null +++ b/sc/qa/extras/vba-macro-test.cxx @@ -0,0 +1,888 @@ +/* -*- 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <osl/file.hxx> +#include <sal/log.hxx> +#include <vcl/filter/pdfdocument.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> +#include <vcl/scheduler.hxx> +#include <vcl/svapp.hxx> +#include <viewdata.hxx> +#include <tabvwsh.hxx> + +#include <docsh.hxx> +#include <document.hxx> +#include <attrib.hxx> +#include <scitems.hxx> +#include <sortparam.hxx> + +#include <com/sun/star/frame/DispatchResultEvent.hpp> +#include <com/sun/star/frame/DispatchResultState.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XPrintAreas.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/ui/XUIConfigurationManager.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> + +#include <ooo/vba/excel/XlSpecialCellsValue.hpp> + +#include <comphelper/propertysequence.hxx> + +using namespace css; +using namespace ooo::vba; + +class VBAMacroTest : public UnoApiTest +{ +public: + VBAMacroTest() + : UnoApiTest("/sc/qa/extras/testdocuments") + { + } +}; + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testSimpleCopyAndPaste) +{ + // Copy-paste values in the same sheet + + // Range(Cells(4, 3), Cells(6, 3)).Copy + // Cells(4, 2).Activate + // ActiveCell.PasteSpecial xlValues + loadFromFile(u"SimpleCopyPaste.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + // Check state + CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(2, 3, 0))); + CPPUNIT_ASSERT_EQUAL(20.0, rDoc.GetValue(ScAddress(2, 4, 0))); + CPPUNIT_ASSERT_EQUAL(30.0, rDoc.GetValue(ScAddress(2, 5, 0))); + + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 3, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 4, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 5, 0))); + + executeMacro("vnd.sun.Star.script:VBAProject.Module1.test?language=Basic&location=document"); + + // Copy from C4-C6 + CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(2, 3, 0))); + CPPUNIT_ASSERT_EQUAL(20.0, rDoc.GetValue(ScAddress(2, 4, 0))); + CPPUNIT_ASSERT_EQUAL(30.0, rDoc.GetValue(ScAddress(2, 5, 0))); + + // Paste to B4-B6 + CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(1, 3, 0))); + CPPUNIT_ASSERT_EQUAL(20.0, rDoc.GetValue(ScAddress(1, 4, 0))); + CPPUNIT_ASSERT_EQUAL(30.0, rDoc.GetValue(ScAddress(1, 5, 0))); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testMultiDocumentCopyAndPaste) +{ + // Creates a new workbook (document) and copy-pastes values + // between the documents. + + // Set CurrentWB = ActiveWorkbook + // Workbooks.Add + // Set NewWB = ActiveWorkbook + // Cells(3, 2).Value = 200 + // Cells(4, 2).Value = 100 + // Range(Cells(3, 2), Cells(4, 2)).Copy + // CurrentWB.Activate + // Cells(2, 2).Activate + // ActiveCell.PasteSpecial xlValues + // ... + loadFromFile(u"MultiDocumentCopyPaste.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 1, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 2, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 3, 0))); + + executeMacro("vnd.sun.Star.script:VBAProject.Module1.test?language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(200.0, rDoc.GetValue(ScAddress(1, 1, 0))); + CPPUNIT_ASSERT_EQUAL(100.0, rDoc.GetValue(ScAddress(1, 2, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 3, 0))); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testSheetAndColumnSelectAndHide) +{ + loadFromFile(u"SheetAndColumnSelectAndHide.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& rViewData = pView->GetViewData(); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 2)); + + executeMacro( + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testHide?language=Basic&location=document"); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(4, 2)); + + CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); + + executeMacro( + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testUnhide?language=Basic&location=document"); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 2)); + + CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testPrintArea) +{ + // Sets the print area to A1:B5 + // ActiveSheet.PageSetup.PrintArea = "$A$1:$B$5" + loadFromFile(u"VariousTestMacros.xlsm"); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XPrintAreas> xPrintAreas(xSheet, uno::UNO_QUERY_THROW); + + { + const uno::Sequence<table::CellRangeAddress> aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(false, aSequence.hasElements()); + } + + executeMacro("vnd.sun.Star.script:VBAProject.ThisWorkbook.testPrintArea?language=Basic&" + "location=document"); + + { + const uno::Sequence<table::CellRangeAddress> aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(true, aSequence.hasElements()); + } +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testSelectAllChaged) +{ + // Columns("A:A").Select + // Range(Selection, Selection.End(xlToRight)).Select + loadFromFile(u"VariousTestMacros.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + CPPUNIT_ASSERT_EQUAL(ScRange(), pViewData.GetMarkData().GetMarkArea()); + + executeMacro("vnd.sun.Star.script:VBAProject.ThisWorkbook.testSelectAll?language=Basic&" + "location=document"); + + // A1:E1048576 + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 4, MAXROW, 0), pViewData.GetMarkData().GetMarkArea()); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testRangeSelect) +{ + // Range("B2").Select + // Range(Selection, Selection.End(xlToRight)).Select + loadFromFile(u"VariousTestMacros.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + CPPUNIT_ASSERT_EQUAL(ScRange(), pViewData.GetMarkData().GetMarkArea()); + + executeMacro("vnd.sun.Star.script:VBAProject.ThisWorkbook.testRangeSelect?language=Basic&" + "location=document"); + + // B2:E5 + CPPUNIT_ASSERT_EQUAL(ScRange(1, 1, 0, 4, 1, 0), pViewData.GetMarkData().GetMarkArea()); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testWindowState) +{ + // Application.WindowState = xlMinimized + // Application.WindowState = xlMaximized + // Application.WindowState = xlNormal + loadFromFile(u"VariousTestMacros.xlsm"); + + executeMacro("vnd.sun.Star.script:VBAProject.ThisWorkbook.testWindowState?language=Basic&" + "location=document"); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testScroll) +{ + // ActiveWindow.ScrollColumn = 30 + // ActiveWindow.ScrollRow = 100 + + loadFromFile(u"VariousTestMacros.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& rViewData = pView->GetViewData(); + + CPPUNIT_ASSERT_EQUAL(ScSplitPos::SC_SPLIT_BOTTOMLEFT, rViewData.GetActivePart()); + CPPUNIT_ASSERT_EQUAL(SCCOL(0), rViewData.GetPosX(ScHSplitPos::SC_SPLIT_LEFT)); + CPPUNIT_ASSERT_EQUAL(SCROW(0), rViewData.GetPosY(ScVSplitPos::SC_SPLIT_BOTTOM)); + + executeMacro( + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testScroll?language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(ScSplitPos::SC_SPLIT_BOTTOMLEFT, rViewData.GetActivePart()); + CPPUNIT_ASSERT_EQUAL(SCCOL(29), rViewData.GetPosX(ScHSplitPos::SC_SPLIT_LEFT)); + CPPUNIT_ASSERT_EQUAL(SCROW(99), rViewData.GetPosY(ScVSplitPos::SC_SPLIT_BOTTOM)); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testMacroKeyBinding) +{ + // key_U() -> CTRL+U + // key_T() -> CTRL+T + loadFromFile(u"KeyShortcut.xlsm"); + + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel.is()); + + uno::Reference<ui::XUIConfigurationManagerSupplier> xConfigSupplier(xModel, uno::UNO_QUERY); + CPPUNIT_ASSERT(xConfigSupplier.is()); + uno::Reference<ui::XUIConfigurationManager> xConfigManager + = xConfigSupplier->getUIConfigurationManager(); + uno::Reference<ui::XAcceleratorConfiguration> xAccelerator + = xConfigManager->getShortCutManager(); + + awt::KeyEvent aCtrlU; + aCtrlU.KeyCode = css::awt::Key::U; + aCtrlU.Modifiers = css::awt::KeyModifier::MOD1; + + CPPUNIT_ASSERT_EQUAL( + OUString( + "vnd.sun.star.script:VBAProject.ThisWorkbook.key_U?language=Basic&location=document"), + xAccelerator->getCommandByKeyEvent(aCtrlU)); + + awt::KeyEvent aCtrlT; + aCtrlT.KeyCode = css::awt::Key::T; + aCtrlT.Modifiers = css::awt::KeyModifier::MOD1; + + CPPUNIT_ASSERT_EQUAL( + OUString( + "vnd.sun.star.script:VBAProject.ThisWorkbook.key_T?language=Basic&location=document"), + xAccelerator->getCommandByKeyEvent(aCtrlT)); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testVba) +{ + TestMacroInfo testInfo[] = { + { OUString("TestAddress.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { + OUString("vba.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.Modul1.Modul1?language=Basic&location=document"), + }, + { OUString("MiscRangeTests.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("bytearraystring.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacro.test?language=Basic&location=document") }, + { OUString("AutoFilter.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("CalcFont.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestIntersection.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestUnion.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("range-4.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, +// FIXME: sometimes it fails on Windows with +// Failed: : Test change event for Range.Clear set: +// Failed: : Test change event for Range.ClearContents set: +// Failed: : Test change event for Range.Replace: +// Failed: : Test change event for Range.FillRight: +// Tests passed: 4 +// Tests failed: 4 +#if !defined(_WIN32) + { OUString("Ranges-3.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, +#endif + { OUString("TestCalc_Rangetest.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestCalc_Rangetest2.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Ranges-2.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("pagesetup.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Window.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("window2.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("PageBreaks.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Shapes.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Ranges.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("CheckOptionToggleValue.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("GeneratedEventTest.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("MiscControlTests.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Workbooks.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Names.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("NamesSheetLocal.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("vba_endFunction.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("vba_findFunction.xls"), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("BGR-RGBTest.xls"), + OUString("vnd.sun.Star.script:VBAProject.Module1.test?language=Basic&location=document") } + }; + OUString sTempDir; + OUString sTempDirURL; + osl::FileBase::getTempDirURL(sTempDirURL); + osl::FileBase::getSystemPathFromFileURL(sTempDirURL, sTempDir); + sTempDir += OUStringChar(SAL_PATHDELIMITER); + OUString sTestFileName("My Test WorkBook.xls"); + uno::Sequence<uno::Any> aParams; + for (const auto& rTestInfo : testInfo) + { + OUString aFileName = loadFromFile(rTestInfo.sFileBaseName); + + // process all events such as OnLoad events etc. otherwise they tend + // to arrive later at a random time - while processing other StarBasic + // methods. + Scheduler::ProcessEventsToIdle(); + + bool bWorkbooksHandling = rTestInfo.sFileBaseName == "Workbooks.xls" && !sTempDir.isEmpty(); + + if (bWorkbooksHandling) + { + aParams = { uno::Any(sTempDir), uno::Any(sTestFileName) }; + } + + SAL_INFO("sc.qa", "about to invoke vba test in " << aFileName << " with url " + << rTestInfo.sMacroUrl); + + uno::Any aRet = executeMacro(rTestInfo.sMacroUrl, aParams); + OUString aStringRes; + aRet >>= aStringRes; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + OUString("script reported failure in file " + rTestInfo.sFileBaseName) + .toUtf8() + .getStr(), + OUString("OK"), aStringRes); + + if (bWorkbooksHandling) + { + OUString sFileUrl; + OUString sFilePath = sTempDir + sTestFileName; + osl::FileBase::getFileURLFromSystemPath(sFilePath, sFileUrl); + if (!sFileUrl.isEmpty()) + osl::File::remove(sFileUrl); + } + } +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf149579) +{ + mxComponent = loadFromDesktop("private:factory/scalc"); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, uno::UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName("TestModule", + uno::Any(OUString("Option VBASupport 1\n" + "Sub TestTdf149579\n" + "Range(\"A1\").Sort Key1:=Range(\"A1\")\n" + "End Sub\n"))); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + ScDocument& rDoc = pDocSh->GetDocument(); + + rDoc.SetValue(ScAddress(0, 0, 0), 5.0); + rDoc.SetValue(ScAddress(0, 1, 0), 10.0); + rDoc.SetValue(ScAddress(0, 2, 0), 1.0); + + // Without the fix in place, this call would have crashed in debug builds with failed assertion + executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestTdf149579?language=Basic&location=" + "document"); + // Without the fix in place, this test would have failed with + // - Expected: 1 + // - Actual : 5 + CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(5.0, rDoc.GetValue(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(0, 2, 0))); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testVbaRangeSort) +{ + mxComponent = loadFromDesktop("private:factory/scalc"); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, uno::UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName("TestModule", + uno::Any(OUString("Option VBASupport 1\n" + "Sub TestRangeSort\n" + " Range(Cells(1, 1), Cells(3, 1)).Select\n" + " Selection.Sort Key1:=Range(\"A1\"), Header:=False\n" + "End Sub\n"))); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + ScDocument& rDoc = pDocSh->GetDocument(); + + rDoc.SetValue(ScAddress(0, 0, 0), 1.0); + rDoc.SetValue(ScAddress(0, 1, 0), 0.5); + rDoc.SetValue(ScAddress(0, 2, 0), 2.0); + + // Without the fix in place, this call would have crashed in debug builds with failed assertion + executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestRangeSort?language=Basic&location=" + "document"); + + CPPUNIT_ASSERT_EQUAL(0.5, rDoc.GetValue(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(2.0, rDoc.GetValue(ScAddress(0, 2, 0))); + + // Change sheet's first param sorting order + ScSortParam aParam; + rDoc.GetSortParam(aParam, 0); + aParam.maKeyState[0].bAscending = false; + rDoc.SetSortParam(aParam, 0); + + executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestRangeSort?language=Basic&location=" + "document"); + + // Without the fix in place, this test would have failed in non-debug builds with + // - Expected: 2 + // - Actual : 0.5 + CPPUNIT_ASSERT_EQUAL(2.0, rDoc.GetValue(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(0.5, rDoc.GetValue(ScAddress(0, 2, 0))); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf107885) +{ + loadFromFile(u"tdf107885.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT(!rDoc.RowHidden(1, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(2, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(4, 0)); + + // Call auto filter macro using a string condition + executeMacro( + "vnd.sun.Star.script:VBAProject.Module1.AFString?language=Basic&location=document"); + + //Without the fix in place, all rows in autofilter would have been hidden + CPPUNIT_ASSERT(rDoc.RowHidden(1, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(2, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(4, 0)); + + // Call auto filter macro using a numeric condition without any locale + executeMacro( + "vnd.sun.Star.script:VBAProject.Module1.AFNumeric?language=Basic&location=document"); + + CPPUNIT_ASSERT(rDoc.RowHidden(1, 0)); + CPPUNIT_ASSERT(rDoc.RowHidden(2, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(4, 0)); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf131562) +{ + loadFromFile(u"tdf131562.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), rDoc.GetString(ScAddress(0, 3, 0))); + + executeMacro( + "vnd.sun.Star.script:VBAProject.Munka1.numberconcat?language=Basic&location=document"); + + //Without the fix in place, the macro wouldn't have concatenated 1 and " ." + CPPUNIT_ASSERT_EQUAL(OUString("1 ."), rDoc.GetString(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1 .cat"), rDoc.GetString(ScAddress(0, 3, 0))); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf52602) +{ + loadFromFile(u"tdf52602.xls"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + //Without the fix in place, it would have failed with 'Unexpected dialog: Error: BASIC runtime error.' + executeMacro("vnd.sun.Star.script:VBAProject.Modul1.Test_NumberFormat_DateTime?language=Basic&" + "location=document"); + + CPPUNIT_ASSERT_EQUAL(OUString("15:20"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("15:20"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("03/01/2012 15:20"), rDoc.GetString(ScAddress(1, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("03/01/2012 15:20"), rDoc.GetString(ScAddress(1, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("03/01/2012 15:20:00"), rDoc.GetString(ScAddress(2, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("03/01/2012 15:20:00"), rDoc.GetString(ScAddress(2, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1/3/12 15:20"), rDoc.GetString(ScAddress(3, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1/3/12 15:20"), rDoc.GetString(ScAddress(3, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1/ March 2012"), rDoc.GetString(ScAddress(4, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1/ March 2012"), rDoc.GetString(ScAddress(4, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1/ Mar 2012"), rDoc.GetString(ScAddress(5, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1/ Mar 2012"), rDoc.GetString(ScAddress(5, 1, 0))); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf107902) +{ + loadFromFile(u"tdf107902.xlsm"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + //Without the fix in place, it would have failed with 'Unexpected dialog: Error: BASIC runtime error.' + executeMacro("vnd.sun.Star.script:VBAProject.Module1.AF?language=Basic&location=document"); + + //Check the autofilter was created + const ScPatternAttr* pPattern = rDoc.GetPattern(0, 0, 0); + CPPUNIT_ASSERT(pPattern); + + const ScMergeFlagAttr& rAttr = pPattern->GetItem(ATTR_MERGE_FLAG); + CPPUNIT_ASSERT_MESSAGE("Autofilter was not created", rAttr.HasAutoFilter()); + + //Check the last row is hidden + CPPUNIT_ASSERT(!rDoc.RowHidden(0, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(1, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(2, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3, 0)); + CPPUNIT_ASSERT(rDoc.RowHidden(4, 0)); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf90278) +{ + loadFromFile(u"tdf90278.xls"); + + // Without the fix in place, changing the border weight + // would cause a Basic exception/error in the following script. + uno::Any aRet = executeMacro( + "vnd.sun.Star.script:VBAProject.Module1.BorderWeight?language=Basic&location=document"); + + // Check the border weight of the corresponding cell in the test document + sal_Int32 aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReturnValue); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf149531) +{ + loadFromFile(u"tdf149531.xls"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + for (sal_Int32 i = 0; i < 5; ++i) + { + // Without the fix in place, this test would have crashed + // also check the test doesn't crash when the macro is executed a few times in a row + executeMacro("vnd.sun.Star.script:VBAProject.Module1.SetColumnWidth?language=Basic&" + "location=document"); + } + + sal_uInt16 nWidth + = o3tl::convert(rDoc.GetColWidth(0, 0), o3tl::Length::twip, o3tl::Length::mm100); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(25749), nWidth); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf118247) +{ + loadFromFile(u"tdf118247.xlsm"); + + uno::Any aRet = executeMacro( + "vnd.sun.Star.script:VBAProject.Module1.testXlSpecialCellsValuesConstantsEmpty?" + "language=Basic&location=document"); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(OUString("$A$1:$A$3"), aReturnValue); + + const std::vector<std::pair<sal_Int32, OUString>> aTestParams( + { { excel::XlSpecialCellsValue::xlNumbers, "$A$1:$A$2" }, + { excel::XlSpecialCellsValue::xlTextValues, "$A$3" }, + { excel::XlSpecialCellsValue::xlLogical, "$A$1:$A$2" }, + { excel::XlSpecialCellsValue::xlErrors, "$A$1:$A$4" } }); + + for (auto & [ nXlSpecialCellsValue, sRange ] : aTestParams) + { + uno::Sequence<uno::Any> aParams = { uno::Any(nXlSpecialCellsValue) }; + aRet = executeMacro( + "vnd.sun.Star.script:VBAProject.Module1.testXlSpecialCellsValuesConstants?" + "language=Basic&location=document", + aParams); + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sRange, aReturnValue); + } +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf126457) +{ + auto xComponent = loadFromDesktop("private:factory/scalc"); + + // Save a copy of the file to get its URL + uno::Reference<frame::XStorable> xDocStorable(xComponent, uno::UNO_QUERY); + utl::TempFileNamed aTempFile(u"testWindowsActivate", true, u".ods"); + aTempFile.EnableKillingFile(); + uno::Sequence<beans::PropertyValue> descSaveAs( + comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("calc8")) } })); + xDocStorable->storeAsURL(aTempFile.GetURL(), descSaveAs); + + // Insert initial library + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(xComponent, uno::UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any(OUString("Option VBASupport 1\n" + "Function TestWindowsActivate\n" + " dirName = Workbooks(1).Path\n" + " workbookName = Workbooks(1).Name\n" + " fileName = dirName + Application.PathSeparator + workbookName\n" + " Workbooks.Open Filename := fileName\n" + " On Error Goto handler\n" + // activate window using its URL + " Windows(fileName).Activate\n" + // activate window using its caption name + " Windows(workbookName).Activate\n" + // activate window using a newly generated window caption + " newCaption = \"New Window Caption\"\n" + " Windows(fileName).Caption = newCaption\n" + " Windows(newCaption).Activate\n" + " TestWindowsActivate = 0\n" + " Exit Function\n" + "handler:\n" + " TestWindowsActivate = 1\n" + "End Function\n"))); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + ErrCode result + = SfxObjectShell::CallXScript(xComponent, + "vnd.sun.Star.script:TestLibrary.TestModule." + "TestWindowsActivate?language=Basic&location=document", + {}, aRet, aOutParamIndex, aOutParam); + + // Without the fix in place, the windows could not be activated in the macro + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, result); + sal_Int16 nReturnValue; + aRet >>= nReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nReturnValue); + + pDocSh->DoClose(); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testVbaPDFExport) +{ + mxComponent = loadFromDesktop("private:factory/scalc"); + + // Save a copy of the file to get its URL + uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY); + utl::TempFileNamed aTempFile(u"testVBA_PDF_Export", true, u".ods"); + aTempFile.EnableKillingFile(); + uno::Sequence<beans::PropertyValue> descSaveAs( + comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("calc8")) } })); + xDocStorable->storeAsURL(aTempFile.GetURL(), descSaveAs); + + utl::TempFileNamed aTempPdfFile(u"exportedfile", true, u".pdf"); + aTempPdfFile.EnableKillingFile(); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, uno::UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + OUString sMacro = "Option VBASupport 1\n" + "Sub ExportAsPDF\n" + " fileName = \"" + + aTempPdfFile.GetFileName() + + "\"\n ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, " + "FileName:=fileName, Quality:=xlQualityStandard, " + "IncludeDocProperties:=True, OpenAfterPublish:=False\n" + "End Sub\n"; + xLibrary->insertByName("TestModule", uno::Any(sMacro)); + + executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.ExportAsPDF?language=Basic&location=" + "document"); + + // Parse the export result. + vcl::filter::PDFDocument aDocument; + SvFileStream aStream(aTempPdfFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT_MESSAGE("Failed to get the pdf document", aDocument.Read(aStream)); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testForEachInSelection) +{ + loadFromFile(u"ForEachInSelection.ods"); + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("foo"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("bar"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("baz"), rDoc.GetString(ScAddress(0, 2, 0))); + + // tdf#153724: without the fix, this would fail with + // assertion failed + // - Expression: false + // - Unexpected dialog: Error: BASIC runtime error. + // '13' + // Data type mismatch. + executeMacro("vnd.sun.Star.script:Standard.Module1.TestForEachInSelection?" + "language=Basic&location=document"); + + CPPUNIT_ASSERT_EQUAL(OUString("oof"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("rab"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("zab"), rDoc.GetString(ScAddress(0, 2, 0))); +} + +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testNonAsciiMacroIRI) +{ + loadFromFile(u"ForEachInSelection.ods"); + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("foo"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("bar"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("baz"), rDoc.GetString(ScAddress(0, 2, 0))); + + auto ret + = dispatchCommand(mxComponent, u"macro://./Standard.Module1.NonAsciiName_αβγ"_ustr, {}); + css::frame::DispatchResultEvent retEvent; + CPPUNIT_ASSERT(ret >>= retEvent); + // tdf#153752: without the fix, this would fail with + // equality assertion failed + // - Expected: 1 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(css::frame::DispatchResultState::SUCCESS, retEvent.State); + + CPPUNIT_ASSERT_EQUAL(OUString("oof"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("rab"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("zab"), rDoc.GetString(ScAddress(0, 2, 0))); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |