From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sc/qa/extras/anchor.cxx | 426 +++++++ sc/qa/extras/check_data_pilot_field.cxx | 190 +++ sc/qa/extras/check_data_pilot_table.cxx | 188 +++ sc/qa/extras/check_xcell_ranges_query.cxx | 186 +++ sc/qa/extras/htmlexporttest.cxx | 108 ++ sc/qa/extras/macros-test.cxx | 1346 ++++++++++++++++++++ sc/qa/extras/new_cond_format.cxx | 465 +++++++ sc/qa/extras/recordchanges-test.cxx | 109 ++ sc/qa/extras/regression-test.cxx | 114 ++ sc/qa/extras/scannotationobj.cxx | 147 +++ sc/qa/extras/scannotationshapeobj.cxx | 162 +++ sc/qa/extras/scannotationsobj.cxx | 124 ++ sc/qa/extras/scarealinkobj.cxx | 115 ++ sc/qa/extras/scarealinksobj.cxx | 108 ++ sc/qa/extras/scautoformatobj.cxx | 127 ++ sc/qa/extras/scautoformatsobj.cxx | 139 ++ sc/qa/extras/sccellcursorobj.cxx | 226 ++++ sc/qa/extras/sccellfieldsobj.cxx | 111 ++ sc/qa/extras/sccellformatsenumeration.cxx | 90 ++ sc/qa/extras/sccellformatsobj.cxx | 103 ++ sc/qa/extras/sccellobj.cxx | 152 +++ sc/qa/extras/sccellrangeobj.cxx | 269 ++++ sc/qa/extras/sccellrangesobj.cxx | 155 +++ sc/qa/extras/sccellsearchobj.cxx | 111 ++ sc/qa/extras/sccellsenumeration.cxx | 103 ++ sc/qa/extras/sccellsobj.cxx | 110 ++ sc/qa/extras/scchartobj.cxx | 190 +++ sc/qa/extras/scchartsobj.cxx | 194 +++ sc/qa/extras/scconsolidationdescriptorobj.cxx | 89 ++ sc/qa/extras/scdatabaserangeobj.cxx | 121 ++ sc/qa/extras/scdatabaserangesobj.cxx | 125 ++ sc/qa/extras/scdatapilotfieldgroupitemobj.cxx | 192 +++ sc/qa/extras/scdatapilotfieldgroupobj.cxx | 217 ++++ sc/qa/extras/scdatapilotfieldgroupsobj.cxx | 222 ++++ sc/qa/extras/scdatapilotfieldobj.cxx | 134 ++ sc/qa/extras/scdatapilotfieldsobj.cxx | 139 ++ sc/qa/extras/scdatapilotitemobj.cxx | 140 ++ sc/qa/extras/scdatapilotitemsobj.cxx | 164 +++ sc/qa/extras/scdatapilottableobj.cxx | 155 +++ sc/qa/extras/scdatapilottablesobj.cxx | 152 +++ sc/qa/extras/scddelinkobj.cxx | 145 +++ sc/qa/extras/scddelinksobj.cxx | 143 +++ sc/qa/extras/scdocumentconfigurationobj.cxx | 78 ++ sc/qa/extras/scdrawpageobj.cxx | 130 ++ sc/qa/extras/scdrawpagesobj.cxx | 110 ++ sc/qa/extras/sceditfieldobj-cell.cxx | 213 ++++ sc/qa/extras/sceditfieldobj-header.cxx | 173 +++ sc/qa/extras/scfilterdescriptorbase.cxx | 122 ++ sc/qa/extras/scfunctiondescriptionobj.cxx | 90 ++ sc/qa/extras/scfunctionlistobj.cxx | 117 ++ sc/qa/extras/scheaderfieldsobj.cxx | 122 ++ sc/qa/extras/scheaderfootercontentobj.cxx | 104 ++ sc/qa/extras/scimportdescriptorbaseobj.cxx | 98 ++ ...indexenumeration_cellannotationsenumeration.cxx | 96 ++ ...scindexenumeration_cellarealinksenumeration.cxx | 89 ++ ...cindexenumeration_databaserangesenumeration.cxx | 88 ++ ...indexenumeration_datapilotfieldsenumeration.cxx | 110 ++ ...cindexenumeration_datapilotitemsenumeration.cxx | 141 ++ ...indexenumeration_datapilottablesenumeration.cxx | 109 ++ .../scindexenumeration_ddelinksenumeration.cxx | 98 ++ ...xenumeration_functiondescriptionenumeration.cxx | 84 ++ .../scindexenumeration_labelrangesenumeration.cxx | 90 ++ .../scindexenumeration_namedrangesenumeration.cxx | 95 ++ .../scindexenumeration_scenariosenumeration.cxx | 103 ++ ...indexenumeration_sheetcellrangesenumeration.cxx | 121 ++ .../scindexenumeration_sheetlinksenumeration.cxx | 99 ++ .../scindexenumeration_spreadsheetsenumeration.cxx | 82 ++ ...enumeration_spreadsheetviewpanesenumeration.cxx | 90 ++ ...cindexenumeration_subtotalfieldsenumeration.cxx | 98 ++ ...indexenumeration_tableautoformatenumeration.cxx | 83 ++ .../scindexenumeration_tablechartsenumeration.cxx | 162 +++ .../scindexenumeration_tablecolumnsenumeration.cxx | 93 ++ ...numeration_tableconditionalentryenumeration.cxx | 118 ++ .../scindexenumeration_tablerowsenumeration.cxx | 95 ++ .../scindexenumeration_textfieldenumeration.cxx | 101 ++ sc/qa/extras/sclabelrangeobj.cxx | 91 ++ sc/qa/extras/sclabelrangesobj.cxx | 111 ++ sc/qa/extras/scmodelobj.cxx | 129 ++ sc/qa/extras/scnamedrangeobj.cxx | 114 ++ sc/qa/extras/scnamedrangesobj.cxx | 158 +++ sc/qa/extras/scoutlineobj.cxx | 85 ++ sc/qa/extras/scpdfexport.cxx | 578 +++++++++ sc/qa/extras/screcentfunctionsobj.cxx | 79 ++ sc/qa/extras/scscenariosobj.cxx | 138 ++ sc/qa/extras/scshapeobj.cxx | 135 ++ sc/qa/extras/scsheetlinkobj.cxx | 111 ++ sc/qa/extras/scsheetlinksobj.cxx | 125 ++ sc/qa/extras/scsortdescriptorbaseobj.cxx | 84 ++ sc/qa/extras/scspreadsheetsettings.cxx | 97 ++ sc/qa/extras/scspreadsheetsettingsobj.cxx | 98 ++ sc/qa/extras/scstylefamiliesobj.cxx | 145 +++ sc/qa/extras/scstylefamilyobj.cxx | 143 +++ sc/qa/extras/scstyleobj.cxx | 128 ++ sc/qa/extras/scsubtotaldescriptorbase.cxx | 136 ++ sc/qa/extras/scsubtotalfieldobj.cxx | 99 ++ sc/qa/extras/sctablecolumnobj.cxx | 157 +++ sc/qa/extras/sctablecolumnsobj.cxx | 149 +++ sc/qa/extras/sctableconditionalentryobj.cxx | 121 ++ sc/qa/extras/sctableconditionalformat.cxx | 157 +++ sc/qa/extras/sctablerowobj.cxx | 146 +++ sc/qa/extras/sctablerowsobj.cxx | 136 ++ sc/qa/extras/sctablesheetobj.cxx | 375 ++++++ sc/qa/extras/sctablesheetsobj.cxx | 172 +++ sc/qa/extras/sctablevalidationobj.cxx | 124 ++ sc/qa/extras/sctabviewobj.cxx | 143 +++ sc/qa/extras/scuniquecellformatsenumeration.cxx | 134 ++ sc/qa/extras/scuniquecellformatsobj.cxx | 101 ++ sc/qa/extras/scviewpaneobj.cxx | 140 ++ sc/qa/extras/testdocuments/AutoFilter.xls | Bin 0 -> 13824 bytes sc/qa/extras/testdocuments/BaseForHTMLExport.ods | Bin 0 -> 10933 bytes sc/qa/extras/testdocuments/CalcFont.xls | Bin 0 -> 55296 bytes .../testdocuments/CheckOptionToggleValue.xls | Bin 0 -> 45568 bytes sc/qa/extras/testdocuments/ForEachInSelection.ods | Bin 0 -> 9819 bytes sc/qa/extras/testdocuments/GeneratedEventTest.xls | Bin 0 -> 31232 bytes sc/qa/extras/testdocuments/KeyShortcut.xlsm | Bin 0 -> 12947 bytes .../testdocuments/MasterScriptProviderProblem.ods | Bin 0 -> 8967 bytes sc/qa/extras/testdocuments/MiscControlTests.xls | Bin 0 -> 63488 bytes sc/qa/extras/testdocuments/MiscRangeTests.xls | Bin 0 -> 121344 bytes .../testdocuments/MultiDocumentCopyPaste.xlsm | Bin 0 -> 18647 bytes sc/qa/extras/testdocuments/Names.xls | Bin 0 -> 46592 bytes sc/qa/extras/testdocuments/NamesSheetLocal.xls | Bin 0 -> 41472 bytes sc/qa/extras/testdocuments/PageBreaks.xls | Bin 0 -> 55296 bytes .../testdocuments/ProtectedArrayInCustomType.ods | Bin 0 -> 14327 bytes sc/qa/extras/testdocuments/Ranges-2.xls | Bin 0 -> 2190848 bytes sc/qa/extras/testdocuments/Ranges-3.xls | Bin 0 -> 50688 bytes sc/qa/extras/testdocuments/Ranges.xls | Bin 0 -> 2237952 bytes .../testdocuments/RecordChangesProtected.ods | Bin 0 -> 14217 bytes sc/qa/extras/testdocuments/ScAnnotationObj.ods | Bin 0 -> 9253 bytes sc/qa/extras/testdocuments/ScCellCursorObj.ods | Bin 0 -> 7639 bytes sc/qa/extras/testdocuments/ScDataPilotTableObj.ods | Bin 0 -> 12639 bytes sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods | Bin 0 -> 8652 bytes sc/qa/extras/testdocuments/ScModelObj.ods | Bin 0 -> 7599 bytes sc/qa/extras/testdocuments/ScNamedRangeObj.ods | Bin 0 -> 10519 bytes sc/qa/extras/testdocuments/ScOutlineObj.ods | Bin 0 -> 7964 bytes sc/qa/extras/testdocuments/ScSheetLinkObj.ods | Bin 0 -> 6906 bytes sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods | Bin 0 -> 12488 bytes sc/qa/extras/testdocuments/ScTableSheetObj.ods | Bin 0 -> 8640 bytes sc/qa/extras/testdocuments/Shapes.xls | Bin 0 -> 66048 bytes .../testdocuments/SheetAndColumnSelectAndHide.xlsm | Bin 0 -> 17286 bytes sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm | Bin 0 -> 16139 bytes sc/qa/extras/testdocuments/StarBasic.ods | Bin 0 -> 9802 bytes sc/qa/extras/testdocuments/TestAddress.xls | Bin 0 -> 40448 bytes sc/qa/extras/testdocuments/TestCalc_Rangetest.xls | Bin 0 -> 74240 bytes sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls | Bin 0 -> 58368 bytes sc/qa/extras/testdocuments/TestIntersection.xls | Bin 0 -> 35328 bytes sc/qa/extras/testdocuments/TestUnion.xls | Bin 0 -> 31232 bytes sc/qa/extras/testdocuments/VariousTestMacros.xlsm | Bin 0 -> 18110 bytes sc/qa/extras/testdocuments/Window.xls | Bin 0 -> 58880 bytes sc/qa/extras/testdocuments/Workbooks.xls | Bin 0 -> 29184 bytes sc/qa/extras/testdocuments/bytearraystring.xls | Bin 0 -> 45568 bytes sc/qa/extras/testdocuments/cond_format_merge.ods | Bin 0 -> 8428 bytes sc/qa/extras/testdocuments/forcepoint97.xlsx | Bin 0 -> 21127 bytes .../testdocuments/macro-button-form-control.xlsm | Bin 0 -> 15969 bytes sc/qa/extras/testdocuments/new_cond_format_api.ods | Bin 0 -> 8138 bytes sc/qa/extras/testdocuments/pagesetup.xls | Bin 0 -> 57856 bytes sc/qa/extras/testdocuments/range-4.xls | Bin 0 -> 2162176 bytes sc/qa/extras/testdocuments/rangenamessrc.ods | Bin 0 -> 9089 bytes sc/qa/extras/testdocuments/scarealinkobj.ods | Bin 0 -> 6906 bytes sc/qa/extras/testdocuments/scdatapilotfieldobj.ods | Bin 0 -> 10545 bytes sc/qa/extras/testdocuments/tdf104902.ods | Bin 0 -> 9448 bytes sc/qa/extras/testdocuments/tdf105558.ods | Bin 0 -> 9459 bytes sc/qa/extras/testdocuments/tdf107885.xlsm | Bin 0 -> 15021 bytes sc/qa/extras/testdocuments/tdf107902.xlsm | Bin 0 -> 13948 bytes sc/qa/extras/testdocuments/tdf114427.ods | Bin 0 -> 9173 bytes sc/qa/extras/testdocuments/tdf120161.ods | Bin 0 -> 8192 bytes sc/qa/extras/testdocuments/tdf125800.ods | Bin 0 -> 14245 bytes sc/qa/extras/testdocuments/tdf128218.ods | Bin 0 -> 8232 bytes sc/qa/extras/testdocuments/tdf130307.ods | Bin 0 -> 8277 bytes sc/qa/extras/testdocuments/tdf131296_legacy.ods | Bin 0 -> 15932 bytes sc/qa/extras/testdocuments/tdf131296_new.ods | Bin 0 -> 16734 bytes sc/qa/extras/testdocuments/tdf131562.xlsm | Bin 0 -> 13203 bytes sc/qa/extras/testdocuments/tdf133887.ods | Bin 0 -> 8465 bytes sc/qa/extras/testdocuments/tdf133889.ods | Bin 0 -> 8202 bytes sc/qa/extras/testdocuments/tdf138646.ods | Bin 0 -> 13577 bytes sc/qa/extras/testdocuments/tdf142033.ods | Bin 0 -> 8833 bytes sc/qa/extras/testdocuments/tdf143582.ods | Bin 0 -> 8982 bytes sc/qa/extras/testdocuments/tdf143978.ods | Bin 0 -> 9179 bytes sc/qa/extras/testdocuments/tdf144085.ods | Bin 0 -> 10899 bytes sc/qa/extras/testdocuments/tdf144970.ods | Bin 0 -> 13380 bytes sc/qa/extras/testdocuments/tdf146742.ods | Bin 0 -> 10382 bytes sc/qa/extras/testdocuments/tdf43003.ods | Bin 0 -> 12604 bytes sc/qa/extras/testdocuments/tdf46119.ods | Bin 0 -> 17398 bytes sc/qa/extras/testdocuments/tdf57113.ods | Bin 0 -> 14140 bytes sc/qa/extras/testdocuments/tdf64639.ods | Bin 0 -> 10569 bytes .../testdocuments/tdf64703_hiddenPageBreak.ods | Bin 0 -> 9783 bytes sc/qa/extras/testdocuments/tdf75263.xlsm | Bin 0 -> 6643 bytes sc/qa/extras/testdocuments/tdf78897.xls | Bin 0 -> 11264 bytes sc/qa/extras/testdocuments/tdf84012.ods | Bin 0 -> 12777 bytes sc/qa/extras/testdocuments/tdf90278.xls | Bin 0 -> 31744 bytes sc/qa/extras/testdocuments/testTypePassword.ods | Bin 0 -> 31223 bytes sc/qa/extras/testdocuments/vba.xls | Bin 0 -> 33280 bytes sc/qa/extras/testdocuments/vba_endFunction.xls | Bin 0 -> 2286592 bytes sc/qa/extras/testdocuments/vba_findFunction.xls | Bin 0 -> 38400 bytes sc/qa/extras/testdocuments/window2.xls | Bin 0 -> 69120 bytes sc/qa/extras/testdocuments/xcellrangesquery.ods | Bin 0 -> 9519 bytes sc/qa/extras/vba-macro-test.cxx | 806 ++++++++++++ 196 files changed, 17253 insertions(+) create mode 100644 sc/qa/extras/anchor.cxx create mode 100644 sc/qa/extras/check_data_pilot_field.cxx create mode 100644 sc/qa/extras/check_data_pilot_table.cxx create mode 100644 sc/qa/extras/check_xcell_ranges_query.cxx create mode 100644 sc/qa/extras/htmlexporttest.cxx create mode 100644 sc/qa/extras/macros-test.cxx create mode 100644 sc/qa/extras/new_cond_format.cxx create mode 100644 sc/qa/extras/recordchanges-test.cxx create mode 100644 sc/qa/extras/regression-test.cxx create mode 100644 sc/qa/extras/scannotationobj.cxx create mode 100644 sc/qa/extras/scannotationshapeobj.cxx create mode 100644 sc/qa/extras/scannotationsobj.cxx create mode 100644 sc/qa/extras/scarealinkobj.cxx create mode 100644 sc/qa/extras/scarealinksobj.cxx create mode 100644 sc/qa/extras/scautoformatobj.cxx create mode 100644 sc/qa/extras/scautoformatsobj.cxx create mode 100644 sc/qa/extras/sccellcursorobj.cxx create mode 100644 sc/qa/extras/sccellfieldsobj.cxx create mode 100644 sc/qa/extras/sccellformatsenumeration.cxx create mode 100644 sc/qa/extras/sccellformatsobj.cxx create mode 100644 sc/qa/extras/sccellobj.cxx create mode 100644 sc/qa/extras/sccellrangeobj.cxx create mode 100644 sc/qa/extras/sccellrangesobj.cxx create mode 100644 sc/qa/extras/sccellsearchobj.cxx create mode 100644 sc/qa/extras/sccellsenumeration.cxx create mode 100644 sc/qa/extras/sccellsobj.cxx create mode 100644 sc/qa/extras/scchartobj.cxx create mode 100644 sc/qa/extras/scchartsobj.cxx create mode 100644 sc/qa/extras/scconsolidationdescriptorobj.cxx create mode 100644 sc/qa/extras/scdatabaserangeobj.cxx create mode 100644 sc/qa/extras/scdatabaserangesobj.cxx create mode 100644 sc/qa/extras/scdatapilotfieldgroupitemobj.cxx create mode 100644 sc/qa/extras/scdatapilotfieldgroupobj.cxx create mode 100644 sc/qa/extras/scdatapilotfieldgroupsobj.cxx create mode 100644 sc/qa/extras/scdatapilotfieldobj.cxx create mode 100644 sc/qa/extras/scdatapilotfieldsobj.cxx create mode 100644 sc/qa/extras/scdatapilotitemobj.cxx create mode 100644 sc/qa/extras/scdatapilotitemsobj.cxx create mode 100644 sc/qa/extras/scdatapilottableobj.cxx create mode 100644 sc/qa/extras/scdatapilottablesobj.cxx create mode 100644 sc/qa/extras/scddelinkobj.cxx create mode 100644 sc/qa/extras/scddelinksobj.cxx create mode 100644 sc/qa/extras/scdocumentconfigurationobj.cxx create mode 100644 sc/qa/extras/scdrawpageobj.cxx create mode 100644 sc/qa/extras/scdrawpagesobj.cxx create mode 100644 sc/qa/extras/sceditfieldobj-cell.cxx create mode 100644 sc/qa/extras/sceditfieldobj-header.cxx create mode 100644 sc/qa/extras/scfilterdescriptorbase.cxx create mode 100644 sc/qa/extras/scfunctiondescriptionobj.cxx create mode 100644 sc/qa/extras/scfunctionlistobj.cxx create mode 100644 sc/qa/extras/scheaderfieldsobj.cxx create mode 100644 sc/qa/extras/scheaderfootercontentobj.cxx create mode 100644 sc/qa/extras/scimportdescriptorbaseobj.cxx create mode 100644 sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_cellarealinksenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_databaserangesenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_ddelinksenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_functiondescriptionenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_scenariosenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_sheetlinksenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_spreadsheetsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_tablecolumnsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx create mode 100644 sc/qa/extras/scindexenumeration_textfieldenumeration.cxx create mode 100644 sc/qa/extras/sclabelrangeobj.cxx create mode 100644 sc/qa/extras/sclabelrangesobj.cxx create mode 100644 sc/qa/extras/scmodelobj.cxx create mode 100644 sc/qa/extras/scnamedrangeobj.cxx create mode 100644 sc/qa/extras/scnamedrangesobj.cxx create mode 100644 sc/qa/extras/scoutlineobj.cxx create mode 100644 sc/qa/extras/scpdfexport.cxx create mode 100644 sc/qa/extras/screcentfunctionsobj.cxx create mode 100644 sc/qa/extras/scscenariosobj.cxx create mode 100644 sc/qa/extras/scshapeobj.cxx create mode 100644 sc/qa/extras/scsheetlinkobj.cxx create mode 100644 sc/qa/extras/scsheetlinksobj.cxx create mode 100644 sc/qa/extras/scsortdescriptorbaseobj.cxx create mode 100644 sc/qa/extras/scspreadsheetsettings.cxx create mode 100644 sc/qa/extras/scspreadsheetsettingsobj.cxx create mode 100644 sc/qa/extras/scstylefamiliesobj.cxx create mode 100644 sc/qa/extras/scstylefamilyobj.cxx create mode 100644 sc/qa/extras/scstyleobj.cxx create mode 100644 sc/qa/extras/scsubtotaldescriptorbase.cxx create mode 100644 sc/qa/extras/scsubtotalfieldobj.cxx create mode 100644 sc/qa/extras/sctablecolumnobj.cxx create mode 100644 sc/qa/extras/sctablecolumnsobj.cxx create mode 100644 sc/qa/extras/sctableconditionalentryobj.cxx create mode 100644 sc/qa/extras/sctableconditionalformat.cxx create mode 100644 sc/qa/extras/sctablerowobj.cxx create mode 100644 sc/qa/extras/sctablerowsobj.cxx create mode 100644 sc/qa/extras/sctablesheetobj.cxx create mode 100644 sc/qa/extras/sctablesheetsobj.cxx create mode 100644 sc/qa/extras/sctablevalidationobj.cxx create mode 100644 sc/qa/extras/sctabviewobj.cxx create mode 100644 sc/qa/extras/scuniquecellformatsenumeration.cxx create mode 100644 sc/qa/extras/scuniquecellformatsobj.cxx create mode 100644 sc/qa/extras/scviewpaneobj.cxx create mode 100644 sc/qa/extras/testdocuments/AutoFilter.xls create mode 100644 sc/qa/extras/testdocuments/BaseForHTMLExport.ods create mode 100644 sc/qa/extras/testdocuments/CalcFont.xls create mode 100644 sc/qa/extras/testdocuments/CheckOptionToggleValue.xls create mode 100644 sc/qa/extras/testdocuments/ForEachInSelection.ods create mode 100644 sc/qa/extras/testdocuments/GeneratedEventTest.xls create mode 100644 sc/qa/extras/testdocuments/KeyShortcut.xlsm create mode 100644 sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods create mode 100644 sc/qa/extras/testdocuments/MiscControlTests.xls create mode 100644 sc/qa/extras/testdocuments/MiscRangeTests.xls create mode 100644 sc/qa/extras/testdocuments/MultiDocumentCopyPaste.xlsm create mode 100644 sc/qa/extras/testdocuments/Names.xls create mode 100644 sc/qa/extras/testdocuments/NamesSheetLocal.xls create mode 100644 sc/qa/extras/testdocuments/PageBreaks.xls create mode 100644 sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods create mode 100644 sc/qa/extras/testdocuments/Ranges-2.xls create mode 100644 sc/qa/extras/testdocuments/Ranges-3.xls create mode 100644 sc/qa/extras/testdocuments/Ranges.xls create mode 100644 sc/qa/extras/testdocuments/RecordChangesProtected.ods create mode 100644 sc/qa/extras/testdocuments/ScAnnotationObj.ods create mode 100644 sc/qa/extras/testdocuments/ScCellCursorObj.ods create mode 100644 sc/qa/extras/testdocuments/ScDataPilotTableObj.ods create mode 100644 sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods create mode 100644 sc/qa/extras/testdocuments/ScModelObj.ods create mode 100644 sc/qa/extras/testdocuments/ScNamedRangeObj.ods create mode 100644 sc/qa/extras/testdocuments/ScOutlineObj.ods create mode 100644 sc/qa/extras/testdocuments/ScSheetLinkObj.ods create mode 100644 sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods create mode 100644 sc/qa/extras/testdocuments/ScTableSheetObj.ods create mode 100644 sc/qa/extras/testdocuments/Shapes.xls create mode 100644 sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm create mode 100644 sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm create mode 100644 sc/qa/extras/testdocuments/StarBasic.ods create mode 100644 sc/qa/extras/testdocuments/TestAddress.xls create mode 100644 sc/qa/extras/testdocuments/TestCalc_Rangetest.xls create mode 100644 sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls create mode 100644 sc/qa/extras/testdocuments/TestIntersection.xls create mode 100644 sc/qa/extras/testdocuments/TestUnion.xls create mode 100644 sc/qa/extras/testdocuments/VariousTestMacros.xlsm create mode 100644 sc/qa/extras/testdocuments/Window.xls create mode 100644 sc/qa/extras/testdocuments/Workbooks.xls create mode 100644 sc/qa/extras/testdocuments/bytearraystring.xls create mode 100644 sc/qa/extras/testdocuments/cond_format_merge.ods create mode 100644 sc/qa/extras/testdocuments/forcepoint97.xlsx create mode 100644 sc/qa/extras/testdocuments/macro-button-form-control.xlsm create mode 100644 sc/qa/extras/testdocuments/new_cond_format_api.ods create mode 100644 sc/qa/extras/testdocuments/pagesetup.xls create mode 100644 sc/qa/extras/testdocuments/range-4.xls create mode 100644 sc/qa/extras/testdocuments/rangenamessrc.ods create mode 100644 sc/qa/extras/testdocuments/scarealinkobj.ods create mode 100644 sc/qa/extras/testdocuments/scdatapilotfieldobj.ods create mode 100644 sc/qa/extras/testdocuments/tdf104902.ods create mode 100644 sc/qa/extras/testdocuments/tdf105558.ods create mode 100644 sc/qa/extras/testdocuments/tdf107885.xlsm create mode 100644 sc/qa/extras/testdocuments/tdf107902.xlsm create mode 100644 sc/qa/extras/testdocuments/tdf114427.ods create mode 100644 sc/qa/extras/testdocuments/tdf120161.ods create mode 100644 sc/qa/extras/testdocuments/tdf125800.ods create mode 100644 sc/qa/extras/testdocuments/tdf128218.ods create mode 100644 sc/qa/extras/testdocuments/tdf130307.ods create mode 100644 sc/qa/extras/testdocuments/tdf131296_legacy.ods create mode 100644 sc/qa/extras/testdocuments/tdf131296_new.ods create mode 100644 sc/qa/extras/testdocuments/tdf131562.xlsm create mode 100644 sc/qa/extras/testdocuments/tdf133887.ods create mode 100644 sc/qa/extras/testdocuments/tdf133889.ods create mode 100644 sc/qa/extras/testdocuments/tdf138646.ods create mode 100644 sc/qa/extras/testdocuments/tdf142033.ods create mode 100644 sc/qa/extras/testdocuments/tdf143582.ods create mode 100644 sc/qa/extras/testdocuments/tdf143978.ods create mode 100644 sc/qa/extras/testdocuments/tdf144085.ods create mode 100644 sc/qa/extras/testdocuments/tdf144970.ods create mode 100644 sc/qa/extras/testdocuments/tdf146742.ods create mode 100644 sc/qa/extras/testdocuments/tdf43003.ods create mode 100644 sc/qa/extras/testdocuments/tdf46119.ods create mode 100644 sc/qa/extras/testdocuments/tdf57113.ods create mode 100644 sc/qa/extras/testdocuments/tdf64639.ods create mode 100644 sc/qa/extras/testdocuments/tdf64703_hiddenPageBreak.ods create mode 100644 sc/qa/extras/testdocuments/tdf75263.xlsm create mode 100644 sc/qa/extras/testdocuments/tdf78897.xls create mode 100644 sc/qa/extras/testdocuments/tdf84012.ods create mode 100644 sc/qa/extras/testdocuments/tdf90278.xls create mode 100644 sc/qa/extras/testdocuments/testTypePassword.ods create mode 100644 sc/qa/extras/testdocuments/vba.xls create mode 100644 sc/qa/extras/testdocuments/vba_endFunction.xls create mode 100644 sc/qa/extras/testdocuments/vba_findFunction.xls create mode 100644 sc/qa/extras/testdocuments/window2.xls create mode 100644 sc/qa/extras/testdocuments/xcellrangesquery.ods create mode 100644 sc/qa/extras/vba-macro-test.cxx (limited to 'sc/qa/extras') diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx new file mode 100644 index 000000000..347da5ec9 --- /dev/null +++ b/sc/qa/extras/anchor.cxx @@ -0,0 +1,426 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScAnchorTest : public CalcUnoApiTest +{ +public: + ScAnchorTest(); + + void testUndoAnchor(); + void testTdf76183(); + void testODFAnchorTypes(); + void testCopyColumnWithImages(); + void testCutWithImages(); + void testTdf121963(); + void testTdf129552(); + void testTdf130556(); + void testTdf134161(); + + CPPUNIT_TEST_SUITE(ScAnchorTest); + CPPUNIT_TEST(testUndoAnchor); + CPPUNIT_TEST(testTdf76183); + CPPUNIT_TEST(testODFAnchorTypes); + CPPUNIT_TEST(testCopyColumnWithImages); + CPPUNIT_TEST(testCutWithImages); + CPPUNIT_TEST(testTdf121963); + CPPUNIT_TEST(testTdf129552); + CPPUNIT_TEST(testTdf130556); + CPPUNIT_TEST(testTdf134161); + CPPUNIT_TEST_SUITE_END(); +}; + +ScAnchorTest::ScAnchorTest() + : CalcUnoApiTest("sc/qa/unit/data/ods") +{ +} + +void ScAnchorTest::testUndoAnchor() +{ + OUString aFileURL; + createFileURL(u"document_with_linked_graphic.ods", aFileURL); + // open the document with graphic included + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Check whether graphic imported well + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + const SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT(pPage); + + SdrGrafObj* pObject = dynamic_cast(pPage->GetObj(0)); + CPPUNIT_ASSERT(pObject); + CPPUNIT_ASSERT(pObject->IsLinkedGraphic()); + + const GraphicObject& rGraphicObj = pObject->GetGraphicObject(true); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + // Get the document controller + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell); + + // Get the draw view of the document + ScDrawView* pDrawView = pViewShell->GetViewData().GetScDrawView(); + CPPUNIT_ASSERT(pDrawView); + + // Select graphic object + pDrawView->MarkNextObj(); + CPPUNIT_ASSERT(pDrawView->AreObjectsMarked()); + + // Set Cell Anchor + ScDrawLayer::SetCellAnchoredFromPosition(*pObject, rDoc, 0, false); + // Check state + ScAnchorType oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL, oldType); + + // Change all selected objects to page anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_PAGE); + // Check state + ScAnchorType newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_PAGE, newType); + + // Undo and check its result. + SfxUndoManager* pUndoMgr = rDoc.GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(oldType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(newType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + ScDrawLayer::SetPageAnchored(*pObject); + // Check state + oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_PAGE, oldType); + + // Change all selected objects to cell anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_CELL); + // Check state + newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL, newType); + + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(oldType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(newType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf76183() +{ + uno::Reference xComponent = loadFromDesktop("private:factory/scalc"); + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + ScDocShell* pDocSh = dynamic_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + + // Add a circle somewhere below first row. + const tools::Rectangle aOrigRect(1000, 1000, 1200, 1200); + SdrCircObj* pObj = new SdrCircObj(*pDrawLayer, SdrCircKind::Full, aOrigRect); + pPage->InsertObject(pObj); + // Anchor to cell + ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0, false); + const tools::Rectangle& rNewRect = pObj->GetLogicRect(); + + // Set word wrap to true + rDoc.ApplyAttr(0, 0, 0, ScLineBreakCell(true)); + // Add multi-line text to cell to initiate optimal height change + uno::Reference xDoc(xComponent, uno::UNO_QUERY_THROW); + uno::Reference xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xText(xSheet->getCellByPosition(0, 0), uno::UNO_QUERY_THROW); + xText->setString("first\nsecond\nthird"); + + // The resize of first row must have moved the object down after its anchor cell + CPPUNIT_ASSERT(aOrigRect.Top() < rNewRect.Top()); + + pDocSh->DoClose(); +} + +void ScAnchorTest::testODFAnchorTypes() +{ + OUString aFileURL; + createFileURL(u"3AnchorTypes.ods", aFileURL); + // open the document with graphic included + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Check whether graphic imported well + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + const SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT(pPage); + + // Check 1st object: Page anchored + SdrGrafObj* pObject = dynamic_cast(pPage->GetObj(0)); + CPPUNIT_ASSERT(pObject); + ScAnchorType anchorType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_PAGE, anchorType); + + // Check 2nd object: Cell anchored, resize with cell + pObject = dynamic_cast(pPage->GetObj(1)); + CPPUNIT_ASSERT(pObject); + anchorType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL_RESIZE, anchorType); + + // Check 3rd object: Cell anchored + pObject = dynamic_cast(pPage->GetObj(2)); + CPPUNIT_ASSERT(pObject); + anchorType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL, anchorType); + + pDocSh->DoClose(); +} + +/// Test that copying a column with an image anchored to it also copies the image +void ScAnchorTest::testCopyColumnWithImages() +{ + OUString aFileURL; + createFileURL(u"3AnchorTypes.ods", aFileURL); + // open the document with graphic included + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + ScDocument* pDoc = &(pDocSh->GetDocument()); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + // Get the document controller + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell != nullptr); + + ScDocument aClipDoc(SCDOCMODE_CLIP); + + // Copy whole column + { + // 1. Copy source range + ScRange aSrcRange; + aSrcRange.Parse("A1:A11", *pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); + + // 2. Paste to target range + ScRange aDstRange; + aDstRange.Parse("D1:D11", *pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); + pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + + // 3. Make sure the images have been copied too + std::map> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 3, 0, 11); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D3", 1, + static_cast(aRowObjects[2].size())); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D11", 1, + static_cast(aRowObjects[10].size())); + } + + // Copy individual cells + { + // 1. Copy source cells + ScRange aSrcRange; + aSrcRange.Parse("A3:B3", *pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); + + // 2. Paste to target cells + ScRange aDstRange; + aDstRange.Parse("G3:H3", *pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); + pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + + // 3. Make sure the image has been copied too + std::map> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 6, 2, 2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to G3", 1, + static_cast(aRowObjects[2].size())); + } + + pDocSh->DoClose(); +} + +void ScAnchorTest::testCutWithImages() +{ + OUString aFileURL; + createFileURL(u"3AnchorTypes.ods", aFileURL); + // open the document with graphic included + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + ScDocument* pDoc = &(pDocSh->GetDocument()); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + // Get the document controller + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell != nullptr); + + // Cut whole column + { + // Cut source range + ScRange aSrcRange; + aSrcRange.Parse("A1:A11", *pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CutToClip(); + + std::map> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 0, 0, 11); + + // Images should have been removed from the cells + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A3", 0, + static_cast(aRowObjects[2].size())); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A11", 0, + static_cast(aRowObjects[10].size())); + } + + // Cut individual cells + { + // Cut source cells + ScRange aSrcRange; + aSrcRange.Parse("A3:B3", *pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CutToClip(); + + // Image should have been removed from the cell + std::map> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 0, 2, 2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A3", 0, + static_cast(aRowObjects[2].size())); + } + + pDocSh->DoClose(); +} + +void ScAnchorTest::testTdf121963() +{ + OUString aFileURL; + createFileURL(u"tdf121963.ods", aFileURL); + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop, where ScGridWindow::Paint() invalidated itself. + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf129552() +{ + OUString aFileURL; + createFileURL(u"tdf129552.fods", aFileURL); + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop, where ScGridWindow::Paint() invalidated itself. + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf130556() +{ + OUString aFileURL; + createFileURL(u"tdf130556.ods", aFileURL); + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop, where ScGridWindow::Paint() invalidated itself. + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf134161() +{ + OUString aFileURL; + createFileURL(u"tdf134161.ods", aFileURL); + uno::Reference xComponent = loadFromDesktop(aFileURL); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnchorTest); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/check_data_pilot_field.cxx b/sc/qa/extras/check_data_pilot_field.cxx new file mode 100644 index 000000000..bd21856c1 --- /dev/null +++ b/sc/qa/extras/check_data_pilot_field.cxx @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//check the DataPilot of Calc. + +using namespace css; +using namespace css::lang; + +namespace sc_apitest +{ +class CheckDataPilotField : public CalcUnoApiTest, + public apitest::XNamed, + public apitest::XPropertySet +{ +public: + CheckDataPilotField(); + + virtual void setUp() override; + virtual void tearDown() override; + + uno::Reference 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 mxComponent; + uno::Reference mxObject; + int mMaxFieldIndex = 6; +}; + +bool CheckDataPilotField::isPropertyIgnored(const OUString& rName) +{ + return rName == "Function" || rName == "Subtotals" || rName == "Function2" + || rName == "Subtotals2"; +} + +CheckDataPilotField::CheckDataPilotField() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XNamed("Col1") +{ +} + +uno::Reference CheckDataPilotField::init() +{ + // create a calc document + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + else + return mxObject; + + uno::Reference 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 xSpreadsheets = xSheetDoc->getSheets(); + uno::Reference 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 oSheet; + CPPUNIT_ASSERT(aAny >>= oSheet); + + uno::Any aAny2 = oIndexAccess->getByIndex(1); + uno::Reference 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 DPTS(oSheet, uno::UNO_QUERY_THROW); + uno::Reference DPT = DPTS->getDataPilotTables(); + uno::Reference DPDsc = DPT->createDataPilotDescriptor(); + DPDsc->setSourceRange(sCellRangeAddress); + + uno::Any oDataPilotField = DPDsc->getDataPilotFields()->getByIndex(0); + uno::Reference 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 IA = DPDsc->getDataPilotFields(); + uno::Reference xDataPilotFieldObject; + data = IA->getByIndex(0); + CPPUNIT_ASSERT(data >>= xDataPilotFieldObject); + mxObject = xDataPilotFieldObject; + + return xDataPilotFieldObject; +} + +void CheckDataPilotField::setUp() +{ + CalcUnoApiTest::setUp(); + init(); +} + +void CheckDataPilotField::tearDown() +{ + closeDocument(mxComponent); + mxComponent.clear(); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckDataPilotField); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/check_data_pilot_table.cxx b/sc/qa/extras/check_data_pilot_table.cxx new file mode 100644 index 000000000..a38185bb9 --- /dev/null +++ b/sc/qa/extras/check_data_pilot_table.cxx @@ -0,0 +1,188 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//check the DataPilot of Calc. + +using namespace css; +using namespace css::lang; + +namespace sc_apitest { + +class CheckDataPilotTable : public CalcUnoApiTest, public apitest::XNamed, public apitest::XDataPilotTable, public apitest::XPropertySet, public apitest::XDataPilotDescriptor +{ +public: + CheckDataPilotTable(); + + virtual void setUp() override; + virtual void tearDown() 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 mxComponent; + uno::Reference mxObject; + static constexpr int MAX_FIELD_INDEX = 6; +}; + +CheckDataPilotTable::CheckDataPilotTable() + : CalcUnoApiTest("/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 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 xDataPilotTableObject; + data = DPT->getByName( DPT->getElementNames()[0] ); + CPPUNIT_ASSERT(data >>= xDataPilotTableObject); + mxObject = xDataPilotTableObject; + + return xDataPilotTableObject; +} + +void CheckDataPilotTable::setUp() +{ + CalcUnoApiTest::setUp(); + init(); +} + +void CheckDataPilotTable::tearDown() +{ + closeDocument(mxComponent); + mxComponent.clear(); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckDataPilotTable); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/check_xcell_ranges_query.cxx b/sc/qa/extras/check_xcell_ranges_query.cxx new file mode 100644 index 000000000..e2d216dc2 --- /dev/null +++ b/sc/qa/extras/check_xcell_ranges_query.cxx @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace css; +using namespace css::lang; + +namespace sc_apitest { + +class CheckXCellRangesQuery : public CalcUnoApiTest +{ +public: + CheckXCellRangesQuery(); + + virtual void setUp() override; + virtual void tearDown() 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 mxComponent; + uno::Reference< sheet::XCellRangesQuery > m_xCell; + OUString sSheetName; +}; + +CheckXCellRangesQuery::CheckXCellRangesQuery() + : CalcUnoApiTest("/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 xNamed; + CPPUNIT_ASSERT(aAny >>= xNamed); + sSheetName = xNamed->getName(); + + // get the cell + uno::Reference< sheet::XSpreadsheet > xSpreadSheet; + CPPUNIT_ASSERT(aAny >>= xSpreadSheet); + uno::Reference oObj = xSpreadSheet->getCellByPosition(2, 3); + m_xCell = uno::Reference(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: + *
    + *
  1. compare an empty cell with a cell with a value in the same column
  2. + *
  3. compare an empty cell with a cell with a value in the same row
  4. + *
  5. query for empty cells
  6. + *
      + */ +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: + *
        + *
      1. compare a cell with value 5 with a cell with value 15 in the same + * column
      2. + *
      3. compare a cell with value 5 with a cell with value 15 in the same + * row
      4. + *
      5. query for an empty cell.
      6. + *
          + */ + +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 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 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 ranges = m_xCell->queryRowDifferences(table::CellAddress(0, 1, 1)); + OUString getting = ranges->getRangeAddressesAsString(); + + CPPUNIT_ASSERT_EQUAL(expected, getting); +} + +void CheckXCellRangesQuery::setUp() +{ + CalcUnoApiTest::setUp(); + init(); +} + +void CheckXCellRangesQuery::tearDown() +{ + closeDocument(mxComponent); + mxComponent.clear(); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckXCellRangesQuery); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/htmlexporttest.cxx b/sc/qa/extras/htmlexporttest.cxx new file mode 100644 index 000000000..663bb468c --- /dev/null +++ b/sc/qa/extras/htmlexporttest.cxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace css::uno; +using namespace css::lang; +using namespace css::frame; +using namespace utl; + +class ScHTMLExportTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools, public HtmlTestTools +{ + Reference mxComponent; + OUString maFilterOptions; + + void load(std::u16string_view pDir, const char* pName) + { + if (mxComponent.is()) + mxComponent->dispose(); + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Calc.SpreadsheetDocument"); + } + + void save(const OUString& aFilterName, TempFile const & rTempFile) + { + Reference xStorable(mxComponent, UNO_QUERY); + MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= aFilterName; + if (!maFilterOptions.isEmpty()) + aMediaDescriptor["FilterOptions"] <<= maFilterOptions; + xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + } + +public: + ScHTMLExportTest() + {} + + virtual void setUp() override + { + test::BootstrapFixture::setUp(); + mxDesktop.set(css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); + } + + virtual void tearDown() override + { + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); + } + + void testHtmlSkipImage() + { + // need a temp dir, because there's an image exported too + TempFile aTempDir(nullptr, true); + aTempDir.EnableKillingFile(); + OUString const url(aTempDir.GetURL()); + TempFile aTempFile(&url, false); + + htmlDocUniquePtr pDoc; + + load(u"/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods"); + save("HTML (StarCalc)", aTempFile); + pDoc = parseHtml(aTempFile); + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/html/body", 1); + assertXPath(pDoc, "/html/body/table/tr/td/img", 1); + + load(u"/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods"); + maFilterOptions = "SkipImages"; + save("HTML (StarCalc)", aTempFile); + + pDoc = parseHtml(aTempFile); + CPPUNIT_ASSERT (pDoc); + assertXPath(pDoc, "/html/body", 1); + assertXPath(pDoc, "/html/body/table/tr/td/img", 0); + } + + CPPUNIT_TEST_SUITE(ScHTMLExportTest); + CPPUNIT_TEST(testHtmlSkipImage); + 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 000000000..f8642d0a4 --- /dev/null +++ b/sc/qa/extras/macros-test.cxx @@ -0,0 +1,1346 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +/* Implementation of Macros test */ + +class ScMacrosTest : public UnoApiTest, public XmlTestTools +{ +protected: + void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override; +public: + ScMacrosTest(); + void saveAndReload(css::uno::Reference& xComponent, + const OUString& rFilter); + + void testStarBasic(); + void testMSP(); + void testPasswordProtectedStarBasic(); + void testTdf114427(); + void testRowColumn(); + void testTdf104902(); + void testTdf64639(); + void testTdf142033(); + void testPasswordProtectedUnicodeString(); + void testPasswordProtectedArrayInUserType(); + void testTdf131296_legacy(); + void testTdf131296_new(); + void testTdf46119(); + void testTdf128218(); + void testTdf71271(); + void testTdf43003(); + void testTdf75263(); + void testTdf133887(); + void testTdf133889(); + void testTdf144970(); + void testTdf138646(); + void testTdf105558(); + void testTdf143582(); + void testTdf144085(); + void testTdf125800(); + void testTdf130307(); + void testTdf146742(); + void testMacroButtonFormControlXlsxExport(); + void testTdf107572(); + void testShapeLayerId(); + void testVbaRangeSort(); + void testFunctionAccessIndirect(); + + CPPUNIT_TEST_SUITE(ScMacrosTest); + CPPUNIT_TEST(testStarBasic); + CPPUNIT_TEST(testMSP); + CPPUNIT_TEST(testPasswordProtectedStarBasic); + CPPUNIT_TEST(testTdf114427); + CPPUNIT_TEST(testRowColumn); + CPPUNIT_TEST(testTdf104902); + CPPUNIT_TEST(testTdf64639); + CPPUNIT_TEST(testTdf142033); + CPPUNIT_TEST(testPasswordProtectedUnicodeString); + CPPUNIT_TEST(testPasswordProtectedArrayInUserType); + CPPUNIT_TEST(testTdf131296_legacy); + CPPUNIT_TEST(testTdf131296_new); + CPPUNIT_TEST(testTdf46119); + CPPUNIT_TEST(testTdf128218); + CPPUNIT_TEST(testTdf128218); + CPPUNIT_TEST(testTdf71271); + CPPUNIT_TEST(testTdf43003); + CPPUNIT_TEST(testTdf75263); + CPPUNIT_TEST(testTdf133887); + CPPUNIT_TEST(testTdf133889); + CPPUNIT_TEST(testTdf144970); + CPPUNIT_TEST(testTdf138646); + CPPUNIT_TEST(testTdf105558); + CPPUNIT_TEST(testTdf143582); + CPPUNIT_TEST(testTdf144085); + CPPUNIT_TEST(testTdf125800); + CPPUNIT_TEST(testTdf130307); + CPPUNIT_TEST(testTdf146742); + CPPUNIT_TEST(testMacroButtonFormControlXlsxExport); + CPPUNIT_TEST(testTdf107572); + CPPUNIT_TEST(testShapeLayerId); + CPPUNIT_TEST(testVbaRangeSort); + CPPUNIT_TEST(testFunctionAccessIndirect); + + CPPUNIT_TEST_SUITE_END(); +}; + +void ScMacrosTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) +{ + XmlTestTools::registerOOXMLNamespaces(pXmlXPathCtx); + XmlTestTools::registerODFNamespaces(pXmlXPathCtx); +} + +void ScMacrosTest::saveAndReload(css::uno::Reference& xComponent, + const OUString& rFilter) +{ + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + css::uno::Sequence aArgs{ comphelper::makePropertyValue("FilterName", rFilter) }; + css::uno::Reference xStorable(xComponent, css::uno::UNO_QUERY_THROW); + xStorable->storeAsURL(aTempFile.GetURL(), aArgs); + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); + + xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument"); +} + +// 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 +void ScMacrosTest::testMSP() +{ + OUString aFileName; + createFileURL(u"MasterScriptProviderProblem.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh != nullptr); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.TestMSP?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + OUString sResult; + aRet >>= sResult; + + SAL_INFO("sc.qa", "Result is " << sResult ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("TestMSP ( for fdo#67547) failed", OUString("OK"), sResult); + pDocSh->DoClose(); +} + +void ScMacrosTest::testPasswordProtectedStarBasic() +{ + OUString aFileName; + createFileURL(u"testTypePassword.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + + // User defined types + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.LoadAndExecuteTest?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aValue = rDoc.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 + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:MyLibrary.BigModule.bigMethod?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + aValue = rDoc.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 + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:MyLibrary.BigModule.farBigMethod?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + aValue = rDoc.GetString(2,0,0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Far Method script did not change the value of Sheet1.C1", OUString("success"), aValue); + + + pDocSh->DoClose(); +} + +void ScMacrosTest::testStarBasic() +{ + OUString aFileName; + createFileURL(u"StarBasic.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Macro1?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + double aValue = rDoc.GetValue(0,0,0); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("script did not change the value of Sheet1.A1",2.0, aValue, 0.00001); + pDocSh->DoClose(); +} + +void ScMacrosTest::testRowColumn() +{ + OUString aFileName; + createFileURL(u"StarBasic.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Macro_RowHeight?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + sal_uInt16 nHeight = o3tl::convert(rDoc.GetRowHeight(0, 0), o3tl::Length::twip, o3tl::Length::mm100); + CPPUNIT_ASSERT_EQUAL(static_cast(2000), nHeight); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Macro_ColumnWidth?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + sal_uInt16 nWidth = o3tl::convert(rDoc.GetColWidth(0, 0), o3tl::Length::twip, o3tl::Length::mm100); + CPPUNIT_ASSERT_EQUAL(static_cast(4001), nWidth); + + pDocSh->DoClose(); +} + +void ScMacrosTest::testTdf146742() +{ + OUString aFileName; + createFileURL(u"tdf146742.ods", aFileName); + uno::Reference xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + // Export to ODS and reload the file + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(OUString("2"), rDoc.GetString(ScAddress(0,1,0))); + + CPPUNIT_ASSERT_EQUAL(OUString("TRUE"), rDoc.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"), rDoc.GetString(ScAddress(1,1,0))); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testMacroButtonFormControlXlsxExport() +{ + // Given a button form control with an associated macro: + OUString aFileName; + createFileURL(u"macro-button-form-control.xlsm", aFileName); + uno::Reference xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + // When exporting to XLSM: + uno::Reference xStorable(xComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("Calc MS Excel 2007 VBA XML"); + auto pTempFile = std::make_shared(); + pTempFile->EnableKillingFile(); + xStorable->storeToURL(pTempFile->GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + xComponent->dispose(); + + // Then make sure that the macro is associated with the control: + xmlDocUniquePtr pSheetDoc = XPathHelper::parseExport(pTempFile, m_xSFactory, "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", "macro", "Module1.Button1_Click"); + + // Then also make sure that there is no defined name for the macro, which is only needed for + // XLS: + xmlDocUniquePtr pWorkbookDoc = XPathHelper::parseExport(pTempFile, m_xSFactory, "xl/workbook.xml"); + CPPUNIT_ASSERT(pWorkbookDoc); + assertXPath(pWorkbookDoc, "//x:workbook/definedNames", 0); +} + +void ScMacrosTest::testTdf104902() +{ + OUString aFileName; + createFileURL(u"tdf104902.ods", aFileName); + uno::Reference xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.display_bug?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // Export to ODS + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), rDoc.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"), rDoc.GetString(ScAddress(0, 1, 0))); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf64639() +{ + OUString aFileName; + createFileURL(u"tdf64639.ods", aFileName); + uno::Reference xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + const SdrPage* pPage = pDrawLayer->GetPage(0); + + CPPUNIT_ASSERT_EQUAL(static_cast(0), pPage->GetObjCount()); + + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + // 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) + { + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.DrawGraph?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT_EQUAL(static_cast(1), pPage->GetObjCount()); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.DeleteGraph?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT_EQUAL(static_cast(0), pPage->GetObjCount()); + } + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf142033() +{ + OUString aFileName; + createFileURL(u"tdf142033.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.display_bug?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // Export to ODS + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), rDoc.GetString(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), rDoc.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"), rDoc.GetString(ScAddress(1,0,0))); + CPPUNIT_ASSERT_EQUAL(OUString(u"string with" + OUStringChar(u'\xA') + u"newlines"), rDoc.GetString(ScAddress(1,1,0))); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testPasswordProtectedUnicodeString() +{ + const OUString sCorrectString(u"English Русский 中文"); + static const OUStringLiteral sMacroURL( + u"vnd.sun.Star.script:Protected.Module1.TestUnicodeString?language=Basic&location=document"); + static const OUStringLiteral sLibName(u"Protected"); + + OUString aFileName; + createFileURL(u"tdf57113.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + // Check that loading password-protected macro image correctly loads Unicode strings + { + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sCorrectString, aReturnValue); + } + + // Unlock and load the library, to regenerate the image on save + css::uno::Reference xES(xComponent, UNO_QUERY_THROW); + css::uno::Reference xLC(xES->getBasicLibraries(), + UNO_QUERY_THROW); + css::uno::Reference 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(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + { + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sCorrectString, aReturnValue); + } + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testPasswordProtectedArrayInUserType() +{ + static const OUStringLiteral sMacroURL( + u"vnd.sun.Star.script:Protected.Module1.TestMyType?language=Basic&location=document"); + static const OUStringLiteral sLibName(u"Protected"); + + OUString aFileName; + createFileURL(u"ProtectedArrayInCustomType.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + // Check that loading password-protected macro image correctly loads array bounds + { + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + 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 xES(xComponent, UNO_QUERY_THROW); + css::uno::Reference xLC(xES->getBasicLibraries(), + UNO_QUERY_THROW); + css::uno::Reference 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(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + { + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + sal_Int16 nReturnValue; + aRet >>= nReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nReturnValue); + } + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf114427() +{ + OUString aFileName; + createFileURL(u"tdf114427.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + + uno::Reference< frame::XModel > xModel = pDocSh->GetModel(); + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xModel, 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(1), xDraws->getCount()); + + // Without the fix in place, it would have crashed here + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.DeletingFrame?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT_EQUAL(static_cast(0), xDraws->getCount()); + + pDocSh->DoClose(); +} + +void 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> aTests({ + { "TestIntConst", "Integer: 123" }, + { "TestLongConst", "Double: 123" }, + { "TestSingleConst", "Double: 123" }, + { "TestDoubleConst", "Double: 123" }, + }); + + OUString aFileName; + createFileURL(u"tdf131296_legacy.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + { + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + for (auto& [sTestName, sExpected] : aTests) + { + SfxObjectShell::CallXScript(xComponent, + "vnd.sun.Star.script:Protected.Module1." + sTestName + + "?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf131296_new() +{ + // For new password-protected library images, we must correctly get both the constants' values + // and their types. + const std::vector> aTests({ + { "TestIntConst", "Integer: 123" }, + { "TestLongConst", "Long: 123" }, + { "TestSingleConst", "Single: 123" }, + { "TestDoubleConst", "Double: 123" }, + { "TestCurrencyConst", "Currency: 123.0000" }, + }); + + OUString aFileName; + createFileURL(u"tdf131296_new.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + { + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + for (auto& [sTestName, sExpected] : aTests) + { + SfxObjectShell::CallXScript(xComponent, + "vnd.sun.Star.script:Protected.Module1." + sTestName + + "?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf46119() +{ + OUString aFileName; + createFileURL(u"tdf46119.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Main?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT_EQUAL(OUString("0.074"), rDoc.GetString(ScAddress(2, 24, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.067"), rDoc.GetString(ScAddress(2, 25, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.273"), rDoc.GetString(ScAddress(2, 26, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.259"), rDoc.GetString(ScAddress(2, 27, 0))); + + CPPUNIT_ASSERT_EQUAL(OUString("0.097"), rDoc.GetString(ScAddress(3, 24, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.087"), rDoc.GetString(ScAddress(3, 25, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.311"), rDoc.GetString(ScAddress(3, 26, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.296"), rDoc.GetString(ScAddress(3, 27, 0))); + + CPPUNIT_ASSERT_EQUAL(OUString("0.149"), rDoc.GetString(ScAddress(4, 24, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.134"), rDoc.GetString(ScAddress(4, 25, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.386"), rDoc.GetString(ScAddress(4, 26, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0.366"), rDoc.GetString(ScAddress(4, 27, 0))); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf128218() +{ + OUString aFileName; + createFileURL(u"tdf128218.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.TestRAND?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf71271() +{ + uno::Reference xComponent = loadFromDesktop("private:factory/scalc"); + + { + uno::Reference xDoc(xComponent, uno::UNO_QUERY_THROW); + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xProps(xSheet, uno::UNO_QUERY_THROW); + xProps->setPropertyValue("CodeName", uno::Any(OUString("NewCodeName"))); + } + + saveAndReload(xComponent, ""); + CPPUNIT_ASSERT(xComponent); + + { + uno::Reference xDoc(xComponent, uno::UNO_QUERY_THROW); + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + OUString sCodeName; + uno::Reference 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); + } + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf43003() +{ + OUString aFileName; + createFileURL(u"tdf43003.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT(pFoundShell); + + ScDocShellRef xDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(xDocSh); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, the values of the specified cells won't be changed + rDoc.SetValue(ScAddress(0, 0, 0), 2); + CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(1, 0, 0))); + CPPUNIT_ASSERT_EQUAL(4.0, rDoc.GetValue(ScAddress(2, 0, 0))); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + + +void ScMacrosTest::testTdf75263() +{ + OUString aFileName; + createFileURL(u"tdf75263.xlsm", aFileName); + uno::Reference xComponent + = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + { + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + rDoc.CalcAll(); + + // A1 contains formula with user-defined function, and the function is defined in VBA. + CPPUNIT_ASSERT_EQUAL(OUString(u"проба"), rDoc.GetString(ScAddress(0, 0, 0))); + } + + saveAndReload(xComponent, "Calc MS Excel 2007 VBA XML"); + CPPUNIT_ASSERT(xComponent); + + { + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + rDoc.CalcAll(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: проба (sample) + // - Actual : ????? + CPPUNIT_ASSERT_EQUAL(OUString(u"проба"), rDoc.GetString(ScAddress(0, 0, 0))); + } + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf133887() +{ + OUString aFileName; + createFileURL(u"tdf133887.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence aOutParamIndex; + css::uno::Sequence aOutParam; + css::uno::Sequence aParams{ css::uno::Any(sal_Int16(0)) }; + + SfxObjectShell::CallXScript( + xComponent, + "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); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf133889() +{ + OUString aFileName; + createFileURL(u"tdf133889.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence aOutParamIndex; + css::uno::Sequence aOutParam; + css::uno::Sequence aParams{ css::uno::Any(sal_Int32(0)) }; + + SfxObjectShell::CallXScript( + xComponent, + "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); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf143582() +{ + OUString aFileName; + createFileURL(u"tdf143582.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence aParams; + css::uno::Sequence aOutParam; + css::uno::Sequence aOutParamIndex; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.TestScriptInvoke?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf144085() +{ + OUString aFileName; + createFileURL(u"tdf144085.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence aParams; + css::uno::Sequence aOutParam; + css::uno::Sequence aOutParamIndex; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.TestScriptInvoke?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf125800() +{ + OUString aFileName; + createFileURL(u"tdf125800.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence aParams; + css::uno::Sequence aOutParam; + css::uno::Sequence aOutParamIndex; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + ScConditionalFormat* pFormat = rDoc.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. + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.cf.doItForThisSheetindexThisRange?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + + pFormat = rDoc.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(pEntry); + CPPUNIT_ASSERT_EQUAL(ScConditionMode::Direct, pCondition->GetOperation()); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf130307() +{ + OUString aFileName; + createFileURL(u"tdf130307.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence aParams; + css::uno::Sequence aOutParam; + css::uno::Sequence aOutParamIndex; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.ForEachSheets?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + + // Without the fix in place, this test would have crashed here + CPPUNIT_ASSERT_EQUAL(OUString("Sheet1Sheet2"), aReturnValue); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf144970() +{ + OUString aFileName; + createFileURL(u"tdf144970.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_ENGLISH_XL_A1; + rDoc.SetGrammar(eGram); + + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + const SdrPage* pPage = pDrawLayer->GetPage(0); + + CPPUNIT_ASSERT_EQUAL(static_cast(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 + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Main?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT_EQUAL(static_cast(1), pPage->GetObjCount()); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf138646() +{ + OUString aFileName; + createFileURL(u"tdf138646.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // 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. + pDocSh->GetDocument().SetGrammar(formula::FormulaGrammar::Grammar::GRAM_NATIVE_XL_R1C1); + + const std::vector> aTests({ + { "GlobalNamedCell", "GlobalNamedCell" }, + { "GlobalNamedCellSheet", "GlobalNamedCell" }, + { "LocalNamedCell", "LocalNamedCell" }, + { "LocalNamedCellAccessError", "Exception" } + }); + + { + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + Sequence aParams; + + for (auto& [sTestName, sExpected] : aTests) + { + SfxObjectShell::CallXScript(xComponent, + "vnd.sun.Star.script:Standard.Module1." + sTestName + + "?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } + + pDocSh->DoClose(); +} + +void ScMacrosTest::testTdf105558() +{ + OUString aFileName; + createFileURL(u"tdf105558.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT(pFoundShell); + + ScDocShellRef xDocSh = dynamic_cast(pFoundShell); + CPPUNIT_ASSERT(xDocSh); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, this test would have failed with + // - Expected: 5.5 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(5.5, rDoc.GetValue(ScAddress(0, 0, 0))); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf107572() +{ + auto xComponent = loadFromDesktop("private:factory/scalc"); + + // insert initial library + css::uno::Reference xDocScr(xComponent, 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"))); + + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + ScDocShell* pDocSh = static_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Without the fix in place, this test would have crashed + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:TestLibrary.TestModule.Main?language=Basic&location=document", + {}, aRet, aOutParamIndex, aOutParam); + + ScDocument& rDoc = pDocSh->GetDocument(); + + //Check the autoformat has been applied + for (SCCOL i = 0; i < 5; ++i) + { + const ScPatternAttr* pAttr = rDoc.GetPattern(i, 0, 0); + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground = static_cast(rItem); + const Color& rColor = rBackground.GetColor(); + + CPPUNIT_ASSERT_EQUAL(Color(0x0, 0x0, 0x80), rColor); + } + + for (SCROW i = 1; i < 13; ++i) + { + const ScPatternAttr* pAttr = rDoc.GetPattern(0, i, 0); + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground = static_cast(rItem); + const Color& rColor = rBackground.GetColor(); + + CPPUNIT_ASSERT_EQUAL(Color(0x4d, 0x4d, 0x4d), rColor); + + const ScPatternAttr* pAttr2 = rDoc.GetPattern(5, i, 0); + const SfxPoolItem& rItem2 = pAttr2->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground2 = static_cast(rItem2); + const Color& rColor2 = rBackground2.GetColor(); + + CPPUNIT_ASSERT_EQUAL(Color(0xcc, 0xcc, 0xcc), rColor2); + } + + pDocSh->DoClose(); +} + +void ScMacrosTest::testShapeLayerId() +{ + auto xComponent = loadFromDesktop("private:factory/scalc"); + + // insert initial library + css::uno::Reference xDocScr(xComponent, 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; + Sequence aOutParamIndex; + Sequence aOutParam; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + ScDocShell* pDocSh = static_cast(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:TestLibrary.TestModule.TestLayerID?language=Basic&location=document", + {}, aRet, aOutParamIndex, aOutParam); + // Without the fix in place, this test would have failed in non-debug builds with + // - Expected : + // - Actual : + // 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); + pDocSh->DoClose(); +} + +void ScMacrosTest::testVbaRangeSort() +{ + auto xComponent = loadFromDesktop("private:factory/scalc"); + + css::uno::Reference xDocScr(xComponent, 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"))); + + Any aRet; + Sequence aOutParamIndex; + Sequence aOutParam; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + ScDocShell* pDocSh = static_cast(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 + ErrCode result = SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:TestLibrary.TestModule.TestRangeSort?language=Basic&location=document", + {}, aRet, aOutParamIndex, aOutParam); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, result); + + 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); + + result = SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:TestLibrary.TestModule.TestRangeSort?language=Basic&location=document", + {}, aRet, aOutParamIndex, aOutParam); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, result); + + // 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))); + + pDocSh->DoClose(); +} + +void ScMacrosTest::testFunctionAccessIndirect() +{ + OUString aFileName; + createFileURL(u"tdf120161.ods", aFileName); // just some document with known values in cells + const OUString aReference = "'" + aFileName + "'#$Sheet1.A1"; + + css::uno::Reference 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); +} + +ScMacrosTest::ScMacrosTest() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScMacrosTest); + +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 000000000..257d2e7f9 --- /dev/null +++ b/sc/qa/extras/new_cond_format.cxx @@ -0,0 +1,465 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace css; + +static std::ostream& operator<<(std::ostream& rStrm, const Color& rColor) +{ + rStrm << "Color: R:" << static_cast(rColor.GetRed()) << " G:" << static_cast(rColor.GetGreen()) << " B: " << static_cast(rColor.GetBlue()); + return rStrm; +} + +namespace sc_apitest { + +class ScConditionalFormatTest : public CalcUnoApiTest +{ +public: + ScConditionalFormatTest(); + + virtual void setUp() override; + virtual void tearDown() 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(); +private: + + uno::Reference< lang::XComponent > mxComponent; +}; + +ScConditionalFormatTest::ScConditionalFormatTest() + : CalcUnoApiTest("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 xSheet(init(), uno::UNO_QUERY_THROW); + uno::Reference xProps(xSheet, uno::UNO_QUERY_THROW); + uno::Any aAny = xProps->getPropertyValue("ConditionalFormats"); + uno::Reference xCondFormats; + CPPUNIT_ASSERT(aAny >>= xCondFormats); + CPPUNIT_ASSERT(xCondFormats.is()); +} + +namespace { + +uno::Reference getConditionalFormatList(uno::Reference const & xInterface) +{ + uno::Reference xSheet(xInterface, uno::UNO_QUERY_THROW); + uno::Reference xProps(xSheet, uno::UNO_QUERY_THROW); + uno::Any aAny = xProps->getPropertyValue("ConditionalFormats"); + uno::Reference xCondFormats; + CPPUNIT_ASSERT(aAny >>= xCondFormats); + CPPUNIT_ASSERT(xCondFormats.is()); + + return xCondFormats; +} + +} + +void ScConditionalFormatTest::testCondFormatListProperties() +{ + uno::Reference xCondFormat = + getConditionalFormatList(init()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xCondFormat->getLength()); +} + +void ScConditionalFormatTest::testCondFormatListFormats() +{ + uno::Reference xCondFormatList = + getConditionalFormatList(init()); + + const uno::Sequence > 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 xCondFormatList = + getConditionalFormatList(init(1)); + + uno::Sequence > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + uno::Reference xPropSet(xCondFormat, uno::UNO_QUERY_THROW); + uno::Any aAny = xPropSet->getPropertyValue("Range"); + uno::Reference xCellRanges; + CPPUNIT_ASSERT(aAny >>= xCellRanges); + CPPUNIT_ASSERT(xCellRanges.is()); + uno::Sequence 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 xCondFormatList = + getConditionalFormatList(init(1)); + + uno::Sequence > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference 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 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 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 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 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 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 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 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 const & xPropSet, + const OUString& rExpectedMinString, sal_Int32 nExpectedMinType, + const OUString& rExpectedMaxString, sal_Int32 nExpectedMaxType) +{ + uno::Any aAny = xPropSet->getPropertyValue("DataBarEntries"); + uno::Sequence > 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 xCondFormatList = + getConditionalFormatList(init(2)); + + uno::Sequence > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference 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 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 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 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 > 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 xCondFormatList = + getConditionalFormatList(init(3)); + + uno::Sequence > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference 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 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() +{ + CalcUnoApiTest::setUp(); + // get the test file + OUString aFileURL; + createFileURL(u"new_cond_format_api.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScConditionalFormatTest::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScConditionalFormatTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/recordchanges-test.cxx b/sc/qa/extras/recordchanges-test.cxx new file mode 100644 index 000000000..9eb0e6ffb --- /dev/null +++ b/sc/qa/extras/recordchanges-test.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 + +#include +#include + +#include + +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() +{ + uno::Reference xComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference xDoc(xComponent, UNO_QUERY_THROW); + uno::Reference 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); + + closeDocument(xComponent); +} + +void ScRecordChangesTest::testCheckRecordChangesProtection() +{ + // test with protected changes + OUString aFileName; + createFileURL(u"RecordChangesProtected.ods", aFileName); + uno::Reference xComponent = loadFromDesktop(aFileName); + + uno::Reference xDoc(xComponent, UNO_QUERY_THROW); + uno::Reference 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); + + closeDocument(xComponent); +} + +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/regression-test.cxx b/sc/qa/extras/regression-test.cxx new file mode 100644 index 000000000..0e26ce252 --- /dev/null +++ b/sc/qa/extras/regression-test.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "docsh.hxx" +#include "patattr.hxx" +#include "scitems.hxx" +#include "document.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace { + +bool checkDumpAgainstFile( const OUString& rDump, const OUString aFilePath, const OUString& rToleranceFile) +{ + OString aOFile = OUStringToOString(aFilePath, RTL_TEXTENCODING_UTF8); + OString aToleranceFile = OUStringToOString(rToleranceFile, RTL_TEXTENCODING_UTF8); + + CPPUNIT_ASSERT_MESSAGE("dump is empty", !rDump.isEmpty()); + + OString aDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8); + return doXMLDiff(aOFile.getStr(), aDump.getStr(), + static_cast(rDump.getLength()), aToleranceFile.getStr()); +} + +} + +class ScChartRegressionTest : public UnoApiTest +{ +public: + ScChartRegressionTest(); + + void test(); + + CPPUNIT_TEST_SUITE(ScChartRegressionTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); + +}; + +void ScChartRegressionTest::test() +{ + OUString aFileName; + createFileURL( "testChart.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW); + + uno::Reference< table::XTableChartsSupplier > xChartSupplier( xIA->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference< table::XTableCharts > xCharts = xChartSupplier->getCharts(); + CPPUNIT_ASSERT(xCharts.is()); + + uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW); + uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW); + + uno::Reference< lang::XComponent > xChartComp( xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW ); + + uno::Reference< chart2::XChartDocument > xChartDoc ( xChartComp, UNO_QUERY_THROW ); + + uno::Reference< qa::XDumper > xDumper( xChartDoc, UNO_QUERY_THROW ); + + OUString aDump = xDumper->dump(); + std::cout << aDump; + bool bCompare = checkDumpAgainstFile( aDump, getPathFromSrc("/chart2/qa/unit/data/reference/testChart.xml"), getPathFromSrc("/chart2/qa/unit/data/tolerance.xml") ); + CPPUNIT_ASSERT(bCompare); +} + +ScChartRegressionTest::ScChartRegressionTest() + : UnoApiTest("/chart2/qa/unit/data/ods") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChartRegressionTest); + +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 000000000..0e849f5ed --- /dev/null +++ b/sc/qa/extras/scannotationobj.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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScAnnontationObj : public CalcUnoApiTest, + 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 void tearDown() override; + + virtual uno::Reference init() override; + virtual uno::Reference 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(); + +private: + uno::Reference mxComponent; +}; + +ScAnnontationObj::ScAnnontationObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScAnnotationObj", "com.sun.star.sheet.CellAnnotation") +{ +} + +uno::Reference +ScAnnontationObj::getAnnotation(table::CellAddress& xCellAddress) +{ + // get the sheet + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(xCellAddress.Sheet), + uno::UNO_QUERY_THROW); + + // get the cell + uno::Reference xCell( + xSheet->getCellByPosition(xCellAddress.Column, xCellAddress.Row), uno::UNO_SET_THROW); + + // get the annotation from cell + uno::Reference xAnnotationAnchor(xCell, uno::UNO_QUERY_THROW); + uno::Reference xSheetAnnotation(xAnnotationAnchor->getAnnotation(), + uno::UNO_SET_THROW); + + return xSheetAnnotation; +} + +uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + + // get the test file + OUString aFileURL; + createFileURL(u"ScAnnotationObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScAnnontationObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..5a7a7258e --- /dev/null +++ b/sc/qa/extras/scannotationshapeobj.cxx @@ -0,0 +1,162 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScAnnotationShapeObj : public CalcUnoApiTest, + 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 init() override; + virtual uno::Reference 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: + uno::Reference m_xComponent; + static uno::Reference m_xField; +}; + +uno::Reference ScAnnotationShapeObj::m_xField; + +ScAnnotationShapeObj::ScAnnotationShapeObj() + : CalcUnoApiTest("sc/qa/extras/testdocuments") + , XShapeDescriptor("com.sun.star.drawing.CaptionShape") +{ +} + +void ScAnnotationShapeObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAnnotationShapeObj::tearDown() +{ + m_xField.clear(); + closeDocument(m_xComponent); + + CalcUnoApiTest::tearDown(); +} + +uno::Reference ScAnnotationShapeObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + // Use cell A1 for this. + table::CellAddress aNotePos(0, 0, 0); + uno::Reference xAnnosSupp(xSheet, uno::UNO_QUERY_THROW); + uno::Reference 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 xCell = xSheet->getCellByPosition(0, 0); + uno::Reference xAnchor(xCell, uno::UNO_QUERY_THROW); + uno::Reference xAnnotation(xAnchor->getAnnotation(), + uno::UNO_SET_THROW); + uno::Reference xAnnoText(xAnnotation, uno::UNO_QUERY_THROW); + xAnnoText->setString("ScAnnotationShapeObj"); + + uno::Reference xShapeSupp(xAnnotation, + uno::UNO_QUERY_THROW); + uno::Reference xShape(xShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW); + + return xShape; +} + +uno::Reference ScAnnotationShapeObj::getTextContent() +{ + if (!m_xField.is()) + { + uno::Reference xSM(m_xComponent, 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 000000000..4e9939772 --- /dev/null +++ b/sc/qa/extras/scannotationsobj.cxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScAnnontationsObj : public CalcUnoApiTest, public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XSheetAnnotations +{ +public: + ScAnnontationsObj(); + + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + + uno::Reference< lang::XComponent > mxComponent; +}; + + +ScAnnontationsObj::ScAnnontationsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::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() +{ + CalcUnoApiTest::setUp(); + + // get the test file + OUString aFileURL; + createFileURL(u"ScAnnotationObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScAnnontationsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..d28161f14 --- /dev/null +++ b/sc/qa/extras/scarealinkobj.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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScAreaLinkObj : public CalcUnoApiTest, + public apitest::CellAreaLink, + public apitest::XAreaLink, + public apitest::XPropertySet, + public apitest::XRefreshable +{ +public: + ScAreaLinkObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScAreaLinkObj::ScAreaLinkObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , CellAreaLink(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/scarealinkobj.ods")) +{ +} + +uno::Reference ScAreaLinkObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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 xLink(xLinks->getByIndex(0), uno::UNO_QUERY_THROW); + return xLink; +} + +void ScAreaLinkObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAreaLinkObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..6e14ccf22 --- /dev/null +++ b/sc/qa/extras/scarealinksobj.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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScAreaLinksObj : public CalcUnoApiTest, + public apitest::XAreaLinks, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScAreaLinksObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScAreaLinksObj::ScAreaLinksObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) +{ +} + +uno::Reference ScAreaLinksObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xLinks(xPropSet->getPropertyValue("AreaLinks"), + uno::UNO_QUERY_THROW); + + xLinks->insertAtPosition(table::CellAddress(1, 2, 3), "ScAreaLinksObj.ods", "A2:B5", "", ""); + + return xLinks; +} + +void ScAreaLinksObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAreaLinksObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..76db8c6a3 --- /dev/null +++ b/sc/qa/extras/scautoformatobj.cxx @@ -0,0 +1,127 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScAutoFormatObj : public CalcUnoApiTest, + 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 init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScAutoFormatObj::ScAutoFormatObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(16) + , XNamed("Default") + , XServiceInfo("ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat") +{ +} + +uno::Reference ScAutoFormatObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xIA( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_QUERY_THROW); + + uno::Reference xTableAutoFormat(xIA->getByIndex(xIA->getCount() - 1), + uno::UNO_QUERY_THROW); + return xTableAutoFormat; +} + +void ScAutoFormatObj::setUp() +{ + CalcUnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAutoFormatObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..a51bd76ab --- /dev/null +++ b/sc/qa/extras/scautoformatsobj.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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScAutoFormatsObj : public CalcUnoApiTest, + 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 init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScAutoFormatsObj::ScAutoFormatsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(2) + , XNameAccess("Default") + , XNameContainer("ScAutoFormatsObj") + , XNameReplace("ScAutoFormatsObj") + , XServiceInfo("stardiv.StarCalc.ScAutoFormatsObj", "com.sun.star.sheet.TableAutoFormats") +{ +} + +uno::Reference ScAutoFormatsObj::init() +{ + uno::Reference xMSF(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xTAF( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_SET_THROW); + + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAutoFormatsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..f0092c707 --- /dev/null +++ b/sc/qa/extras/sccellcursorobj.cxx @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScCellCursorObj : public CalcUnoApiTest, 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 void tearDown() 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(); + +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScCellCursorObj::ScCellCursorObj(): + CalcUnoApiTest("/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 xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference xCellRange = xSheet->getCellRangeByName("$A$1:$D$4"); + uno::Reference xSheetCellRange(xCellRange, UNO_QUERY_THROW); + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + createFileURL(u"ScCellCursorObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScCellCursorObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..573942b40 --- /dev/null +++ b/sc/qa/extras/sccellfieldsobj.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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFieldsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XRefreshable +{ +public: + ScCellFieldsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellFieldsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScCellFieldsObj::ScCellFieldsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) +{ +} + +uno::Reference ScCellFieldsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xTC(xMSF->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xCell(xSheet0->getCellByPosition(2, 3), uno::UNO_SET_THROW); + uno::Reference xText(xCell, uno::UNO_QUERY_THROW); + xText->insertTextContent(xText->createTextCursor(), xTC, true); + + uno::Reference xTFS(xCell, uno::UNO_QUERY_THROW); + return xTFS->getTextFields(); +} + +void ScCellFieldsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellFieldsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..0ecb6aea3 --- /dev/null +++ b/sc/qa/extras/sccellformatsenumeration.cxx @@ -0,0 +1,90 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFormatsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScCellFormatsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellFormatsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScCellFormatsEnumeration::ScCellFormatsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScCellFormatsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xCFRS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xIA_CFR(xCFRS->getCellFormatRanges(), + uno::UNO_SET_THROW); + uno::Reference xEA(xIA_CFR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScCellFormatsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellFormatsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..58d570f8b --- /dev/null +++ b/sc/qa/extras/sccellformatsobj.cxx @@ -0,0 +1,103 @@ +/* -*- 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFormatsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScCellFormatsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScCellFormatsObj::ScCellFormatsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) +{ +} + +uno::Reference ScCellFormatsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xCFRS(xSheet0, uno::UNO_QUERY_THROW); + + return xCFRS->getCellFormatRanges(); +} + +void ScCellFormatsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellFormatsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..590dad2eb --- /dev/null +++ b/sc/qa/extras/sccellobj.cxx @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellObj : public CalcUnoApiTest, + 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 init() override; + virtual uno::Reference getXSpreadsheet() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScCellObj::ScCellObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XFormulaQuery(table::CellRangeAddress(0, 2, 3, 2, 3), + table::CellRangeAddress(0, 0, 0, 3, 0), 0, 0) +{ +} + +uno::Reference ScCellObj::init() +{ + uno::Reference xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference xSheetAnnosSupplier(xSheet, UNO_QUERY_THROW); + uno::Reference xSheetAnnos(xSheetAnnosSupplier->getAnnotations(), + UNO_SET_THROW); + xSheetAnnos->insertNew(table::CellAddress(0, 2, 3), "xSheetAnnotation"); + + return xSheet->getCellByPosition(2, 3); +} + +uno::Reference ScCellObj::getXSpreadsheet() +{ + uno::Reference xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(2, 3)); + + return xSheet; +} + +void ScCellObj::setUp() +{ + CalcUnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..41731973e --- /dev/null +++ b/sc/qa/extras/sccellrangeobj.cxx @@ -0,0 +1,269 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScCellRangeObj : public CalcUnoApiTest, + 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 void tearDown() override; + virtual uno::Reference init() override; + virtual uno::Reference getXCellRangeData() override; + virtual uno::Reference 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(); + +private: + uno::Reference mxComponent; +}; + +ScCellRangeObj::ScCellRangeObj() + : CalcUnoApiTest("/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 ScCellRangeObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xReturn(xSheet->getCellRangeByPosition(0, 0, 4, 4), + uno::UNO_SET_THROW); + + return xReturn; +} + +uno::Reference ScCellRangeObj::getXSpreadsheet() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +uno::Reference ScCellRangeObj::getXCellRangeData() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(1), uno::UNO_QUERY_THROW); + + uno::Reference xReturn(xSheet->getCellRangeByPosition(0, 0, 3, 3), + uno::UNO_SET_THROW); + + return xReturn; +} + +void ScCellRangeObj::testSortOOB() +{ + uno::Reference xSortable(init(), uno::UNO_QUERY_THROW); + uno::Sequence aEmptyDescriptor; + xSortable->sort(aEmptyDescriptor); + + uno::Sequence aSort(1); + auto pSort = aSort.getArray(); + pSort[0].Field = 0xffffff; + pSort[0].SortAscending = true; + + uno::Sequence aProps( + comphelper::InitPropertySequence({ { "SortFields", uno::Any(aSort) } })); + + xSortable->sort(aProps); +} + +void ScCellRangeObj::setUp() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + createFileURL(u"xcellrangesquery.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScCellRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..e87f6792e --- /dev/null +++ b/sc/qa/extras/sccellrangesobj.cxx @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellRangesObj : public CalcUnoApiTest, + 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 void tearDown() override; + + virtual uno::Reference getXSpreadsheet() override; + virtual uno::Reference 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(); + +private: + uno::Reference mxComponent; +}; + +ScCellRangesObj::ScCellRangesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XFormulaQuery(table::CellRangeAddress(0, 4, 1, 5, 4), + table::CellRangeAddress(0, 4, 1, 5, 4)) +{ +} + +uno::Reference ScCellRangesObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndexAccess(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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 ScCellRangesObj::getXSpreadsheet() +{ + uno::Reference xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +void ScCellRangesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..e0ee5c3bb --- /dev/null +++ b/sc/qa/extras/sccellsearchobj.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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScCellSearchObj : public CalcUnoApiTest, + public apitest::SearchDescriptor, + public apitest::XPropertySet, + public apitest::XReplaceDescriptor, + public apitest::XSearchDescriptor, + public apitest::XServiceInfo +{ +public: + ScCellSearchObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScCellSearchObj::ScCellSearchObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScCellSearchObj", + { "com.sun.star.util.ReplaceDescriptor", "com.sun.star.util.SearchDescriptor" }) +{ +} + +uno::Reference ScCellSearchObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSearchable(xSheet0, uno::UNO_QUERY_THROW); + return xSearchable->createSearchDescriptor(); +} + +void ScCellSearchObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellSearchObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..8961d1e20 --- /dev/null +++ b/sc/qa/extras/sccellsenumeration.cxx @@ -0,0 +1,103 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScCellsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScCellsEnumeration::ScCellsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScCellsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference xCellRange(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xCell0(xCellRange->getCellByPosition(0, 0), uno::UNO_SET_THROW); + uno::Reference xTextRange0(xCell0, uno::UNO_QUERY_THROW); + xTextRange0->setString("Test string 1"); + + uno::Reference xCell1(xCellRange->getCellByPosition(5, 1), uno::UNO_SET_THROW); + xCell1->setValue(15); + + uno::Reference xCell2(xCellRange->getCellByPosition(3, 9), uno::UNO_SET_THROW); + uno::Reference xTextRange1(xCell2, uno::UNO_QUERY_THROW); + xTextRange1->setString("Test string 2"); + + uno::Reference xCellRangesQuery(xCellRange, uno::UNO_QUERY_THROW); + uno::Reference xSCR(xCellRangesQuery->queryVisibleCells(), + uno::UNO_SET_THROW); + + return xSCR->getCells()->createEnumeration(); +} + +void ScCellsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..bf7bb6870 --- /dev/null +++ b/sc/qa/extras/sccellsobj.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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess +{ +public: + ScCellsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellsObj); + + // XElementAccess + CPPUNIT_TEST(testHasElements); + CPPUNIT_TEST(testGetElementType); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScCellsObj::ScCellsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) +{ +} + +uno::Reference ScCellsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xCellRange(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xCell0(xCellRange->getCellByPosition(0, 0), uno::UNO_SET_THROW); + uno::Reference xTextRange0(xCell0, uno::UNO_QUERY_THROW); + xTextRange0->setString("ScCellsObj test 1"); + + uno::Reference xCell1(xCellRange->getCellByPosition(5, 1), uno::UNO_SET_THROW); + xCell1->setValue(15); + + uno::Reference xCell2(xCellRange->getCellByPosition(3, 9), uno::UNO_SET_THROW); + uno::Reference xTextRange2(xCell2, uno::UNO_QUERY_THROW); + xTextRange2->setString("ScCellsObj test 2"); + + uno::Reference xCRQ(xCellRange, uno::UNO_QUERY_THROW); + uno::Reference xSCR(xCRQ->queryVisibleCells(), uno::UNO_SET_THROW); + + return xSCR->getCells(); +} + +void ScCellsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..04eaeba81 --- /dev/null +++ b/sc/qa/extras/scchartobj.cxx @@ -0,0 +1,190 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScChartObj : public CalcUnoApiTest, + public apitest::XEmbeddedObjectSupplier, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XTableChart +{ +public: + ScChartObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScChartObj::ScChartObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("ScChartObj") + , XServiceInfo("ScChartObj", "com.sun.star.table.TableChart") +{ +} + +uno::Reference ScChartObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Sequence aCRA{ xCRA->getRangeAddress() }; + + uno::Reference xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000), aCRA, true, true); + + uno::Reference xNA(xTC, uno::UNO_QUERY_THROW); + uno::Reference xChart(xNA->getByName("ScChartObj"), uno::UNO_QUERY_THROW); + return xChart; +} + +void ScChartObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScChartObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..57b0c584e --- /dev/null +++ b/sc/qa/extras/scchartsobj.cxx @@ -0,0 +1,194 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScChartsObj : public CalcUnoApiTest, + public apitest::XEnumerationAccess, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XTableCharts +{ +public: + ScChartsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScChartsObj::ScChartsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) + , XNameAccess("ScChartsObj") + , XServiceInfo("ScChartsObj", "com.sun.star.table.TableCharts") +{ +} + +uno::Reference ScChartsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Reference xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartsObj", awt::Rectangle(500, 3000, 25000, 11000), + { xCRA->getRangeAddress() }, true, true); + + return xTC; +} + +void ScChartsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScChartsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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/scconsolidationdescriptorobj.cxx b/sc/qa/extras/scconsolidationdescriptorobj.cxx new file mode 100644 index 000000000..e229ade7e --- /dev/null +++ b/sc/qa/extras/scconsolidationdescriptorobj.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 +#include + +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScConsolidationDescriptorObj : public CalcUnoApiTest, public apitest::XConsolidationDescriptor +{ +public: + ScConsolidationDescriptorObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScConsolidationDescriptorObj::ScConsolidationDescriptorObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScConsolidationDescriptorObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xConsolidatable(xDoc, UNO_QUERY_THROW); + return xConsolidatable->createConsolidationDescriptor(true); +} + +void ScConsolidationDescriptorObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScConsolidationDescriptorObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..246ac3680 --- /dev/null +++ b/sc/qa/extras/scdatabaserangeobj.cxx @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScDatabaseRangeObj : public CalcUnoApiTest, + public apitest::DatabaseRange, + public apitest::XCellRangeReferrer, + public apitest::XDatabaseRange +{ +public: + virtual void setUp() override; + virtual void tearDown() 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(); +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScDatabaseRangeObj::ScDatabaseRangeObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference 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 xCRR(xNameAccess->getByName(rDBName), UNO_QUERY_THROW); + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + createFileURL(u"ScDatabaseRangeObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); + +} + +void ScDatabaseRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..39c190f31 --- /dev/null +++ b/sc/qa/extras/scdatabaserangesobj.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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDatabaseRangesObj : public CalcUnoApiTest, + public apitest::XDatabaseRanges, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDatabaseRangesObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScDatabaseRangesObj::ScDatabaseRangesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) + , XNameAccess("DbRange") + , XServiceInfo("ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges") +{ +} + +uno::Reference ScDatabaseRangesObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xPropSet(xDoc, UNO_QUERY_THROW); + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDatabaseRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..8b31050d7 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupitemobj.cxx @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupItemObj : public CalcUnoApiTest, + public apitest::XNamed, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupItemObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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; + uno::Reference m_xComponent; +}; + +ScDataPilotFieldGroupItemObj::ScDataPilotFieldGroupItemObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("aName") + , XServiceInfo("ScDataPilotFieldGroupItemObj", "com.sun.star.sheet.DataPilotFieldGroupItem") +{ +} + +uno::Reference ScDataPilotFieldGroupItemObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference 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 xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::Any(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + xDPFG->createNameGroup({ "aName", "otherName" }); + + uno::Reference xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + uno::Reference xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW); + uno::Reference xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xReturn(xNA_GN->getByName("aName"), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScDataPilotFieldGroupItemObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldGroupItemObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..c7b73da57 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupobj.cxx @@ -0,0 +1,217 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNamed, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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; + uno::Reference m_xComponent; +}; + +ScDataPilotFieldGroupObj::ScDataPilotFieldGroupObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(2) + , XNameAccess("aName") + , XNamed("Group1") + , XServiceInfo("ScDataPilotFieldGroupObj", "com.sun.star.sheet.DataPilotFieldGroup") +{ +} + +uno::Reference ScDataPilotFieldGroupObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference 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 xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::Any(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + xDPFG->createNameGroup({ "aName", "otherName" }); + + uno::Reference xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + uno::Reference xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW); + uno::Reference xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW); + + return xNA_GN; +} + +void ScDataPilotFieldGroupObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldGroupObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..3b05bc0de --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupsobj.cxx @@ -0,0 +1,222 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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; + uno::Reference m_xComponent; +}; + +ScDataPilotFieldGroupsObj::ScDataPilotFieldGroupsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) + , XNameAccess("Group1") + , XNameContainer("Group1") + , XServiceInfo("ScDataPilotFieldGroupsObj", "com.sun.star.sheet.DataPilotFieldGroups") +{ +} + +uno::Reference ScDataPilotFieldGroupsObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", uno::Any(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference 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 xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::Any(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + xDPFG->createNameGroup({ "aName", "otherName" }); + + uno::Reference xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldGroupsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..969f07b2b --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldobj.cxx @@ -0,0 +1,134 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldObj : public CalcUnoApiTest, + public apitest::DataPilotField, + public apitest::XDataPilotField, + public apitest::XDataPilotFieldGrouping, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference 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(); + +private: + uno::Reference mxComponent; +}; + +ScDataPilotFieldObj::ScDataPilotFieldObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("Col1") + , XPropertySet({ "Function", "HasAutoShowInfo", "HasLayoutInfo", "HasSortInfo", "Subtotals", + "Subtotals2" }) + , XServiceInfo("ScDataPilotFieldObj", "com.sun.star.sheet.DataPilotField") +{ +} + +uno::Reference ScDataPilotFieldObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(1), uno::UNO_QUERY_THROW); + + uno::Reference xDPTS(xSheet, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Sequence aElementNames = xDPT->getElementNames(); + (void)aElementNames; + + uno::Reference xDPDsc(xDPT->getByName("DataPilot1"), + uno::UNO_QUERY_THROW); + uno::Reference xIA(xDPDsc->getDataPilotFields(), uno::UNO_SET_THROW); + uno::Reference xReturnValue(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + return xReturnValue; +} + +void ScDataPilotFieldObj::setUp() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + createFileURL(u"scdatapilotfieldobj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScDataPilotFieldObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..54e1df298 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldsobj.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 +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +namespace sc_apitest +{ +class ScDataPilotFieldsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldsObj(); + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScDataPilotFieldsObj::ScDataPilotFieldsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(6) + , XNameAccess("") + , XServiceInfo("ScDataPilotFieldsObj", "com.sun.star.sheet.DataPilotFields") +{ +} + +uno::Reference ScDataPilotFieldsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..6abf68456 --- /dev/null +++ b/sc/qa/extras/scdatapilotitemobj.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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotItemObj : public CalcUnoApiTest, + public apitest::DataPilotItem, + public apitest::XNamed +{ +public: + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference 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; + uno::Reference m_xComponent; +}; + +ScDataPilotItemObj::ScDataPilotItemObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("2") +{ +} + +uno::Reference ScDataPilotItemObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference 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 xIA_DPF(xDPD->getDataPilotFields(), uno::UNO_SET_THROW); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + uno::Reference xDPF(xIA_DPF->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xReturn(xDPF->getItems()->getByIndex(0), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScDataPilotItemObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotItemObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..c59e76a02 --- /dev/null +++ b/sc/qa/extras/scdatapilotitemsobj.cxx @@ -0,0 +1,164 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotItemsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotItemsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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; + uno::Reference m_xComponent; +}; + +ScDataPilotItemsObj::ScDataPilotItemsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(5) + , XNameAccess("2") + , XServiceInfo("ScDataPilotItemsObj", "com.sun.star.sheet.DataPilotItems") +{ +} + +uno::Reference ScDataPilotItemsObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference 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 xIA_DPF(xDPD->getDataPilotFields(), uno::UNO_SET_THROW); + uno::Reference xDPF(xIA_DPF->getByIndex(0), uno::UNO_QUERY_THROW); + + return xDPF->getItems(); +} + +void ScDataPilotItemsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotItemsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..4963c05d7 --- /dev/null +++ b/sc/qa/extras/scdatapilottableobj.cxx @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScDataPilotTableObj : public CalcUnoApiTest, + public apitest::XDataPilotDescriptor, + public apitest::XDataPilotTable, + public apitest::XDataPilotTable2, + public apitest::XNamed +{ +public: + ScDataPilotTableObj(); + + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScDataPilotTableObj::ScDataPilotTableObj() + : CalcUnoApiTest("/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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL(u"ScDataPilotTableObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScDataPilotTableObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..3095feee7 --- /dev/null +++ b/sc/qa/extras/scdatapilottablesobj.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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDataPilotTablesObj : public CalcUnoApiTest, + public apitest::XDataPilotTables, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotTablesObj(); + + virtual uno::Reference init() override; + virtual uno::Reference getXSpreadsheet() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScDataPilotTablesObj::ScDataPilotTablesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) + , XNameAccess("DataPilotTable") + , XServiceInfo("ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables") +{ +} + +uno::Reference ScDataPilotTablesObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet, UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), UNO_SET_THROW); + uno::Reference 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 ScDataPilotTablesObj::getXSpreadsheet() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + return xSheet; +} + +void ScDataPilotTablesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotTablesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..14273198f --- /dev/null +++ b/sc/qa/extras/scddelinkobj.cxx @@ -0,0 +1,145 @@ +/* -*- 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 +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +static utl::TempFile createTempCopy(OUString const& url) +{ + utl::TempFile tmp; + tmp.EnableKillingFile(); + auto const e = osl::File::copy(url, tmp.GetURL()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + (OString("<" + OUStringToOString(url, RTL_TEXTENCODING_UTF8) + "> -> <" + + OUStringToOString(tmp.GetURL(), RTL_TEXTENCODING_UTF8) + ">") + .getStr()), + osl::FileBase::E_None, e); + return tmp; +} + +namespace +{ +struct TempFileBase +{ + utl::TempFile m_TempFile; + explicit TempFileBase(OUString const& url) + : m_TempFile(createTempCopy(url)) + { + } +}; +} + +class ScDDELinkObj : public CalcUnoApiTest, + public TempFileBase, + public apitest::XDDELink, + public apitest::XNamed, + public apitest::XRefreshable +{ +public: + ScDDELinkObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScDDELinkObj::ScDDELinkObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , TempFileBase(m_directories.getURLFromSrc(u"/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods")) + , XDDELink(m_TempFile.GetURL()) + , XNamed("soffice|" + m_TempFile.GetURL() + "!Sheet1.A1") +{ +} + +uno::Reference ScDDELinkObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIA(xSheets, UNO_QUERY_THROW); + uno::Reference xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + + const OUString testdoc = m_TempFile.GetURL(); + + xSheet->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + xSheet->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + + uno::Reference xPropSet(xDoc, UNO_QUERY_THROW); + uno::Any aDDELinks = xPropSet->getPropertyValue("DDELinks"); + uno::Reference xNA(aDDELinks, UNO_QUERY_THROW); + uno::Sequence sLinkNames = xNA->getElementNames(); + uno::Reference xDDELink(xNA->getByName(sLinkNames[0]), UNO_QUERY_THROW); + return xDDELink; +} + +void ScDDELinkObj::setUp() +{ + Application::SetAppName("soffice"); // Enable DDE + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDDELinkObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..d546c47dd --- /dev/null +++ b/sc/qa/extras/scddelinksobj.cxx @@ -0,0 +1,143 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDDELinksObj : public CalcUnoApiTest, + public apitest::XDDELinks, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDDELinksObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScDDELinksObj::ScDDELinksObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XDDELinks(m_directories.getURLFromSrc(u"/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods")) + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) + , XNameAccess("soffice|" + + m_directories.getURLFromSrc(u"/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods") + + "!Sheet1.A1") + , XServiceInfo("ScDDELinksObj", "com.sun.star.sheet.DDELinks") +{ +} + +uno::Reference ScDDELinksObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + const OUString testdoc + = m_directories.getURLFromSrc(u"/sc/qa/unoapi/testdocuments/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 xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Any aDDELinks = xPropSet->getPropertyValue("DDELinks"); + uno::Reference xDDELinks(aDDELinks, uno::UNO_QUERY_THROW); + + return xDDELinks; +} + +void ScDDELinksObj::setUp() +{ + Application::SetAppName("soffice"); // Enable DDE + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDDELinksObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..132e9b792 --- /dev/null +++ b/sc/qa/extras/scdocumentconfigurationobj.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 +#include + +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDocumentConfigurationObj : public CalcUnoApiTest, public apitest::DocumentSettings +{ +public: + ScDocumentConfigurationObj(); + + virtual uno::Reference init() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDocumentConfigurationObj); + + // DocumentSettings + CPPUNIT_TEST(testDocumentSettingsProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScDocumentConfigurationObj::ScDocumentConfigurationObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScDocumentConfigurationObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.DocumentSettings"); +} + +void ScDocumentConfigurationObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDocumentConfigurationObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..d7f54a086 --- /dev/null +++ b/sc/qa/extras/scdrawpageobj.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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScDrawPageObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo, + public apitest::XShapeGrouper, + public apitest::XShapes +{ +public: + ScDrawPageObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScDrawPageObj::ScDrawPageObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(2) + , XServiceInfo("ScPageObj", "com.sun.star.sheet.SpreadsheetDrawPage") +{ +} + +uno::Reference ScDrawPageObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + xDP->insertNewByIndex(0); + xDP->insertNewByIndex(1); + + uno::Reference xDrawPage(xDP->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xShapes(xDrawPage, uno::UNO_QUERY_THROW); + + uno::Reference xRectangle0( + apitest::helper::shape::createRectangle(m_xComponent, 7500, 5000, 5000, 3500), + uno::UNO_SET_THROW); + xShapes->add(xRectangle0); + uno::Reference xRectangle1( + apitest::helper::shape::createRectangle(m_xComponent, 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(m_xComponent, 7500, 10000, 5000, 3500)); + return xDrawPage; +} + +void ScDrawPageObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDrawPageObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..59a78e618 --- /dev/null +++ b/sc/qa/extras/scdrawpagesobj.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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScDrawPagesObj : public CalcUnoApiTest, + public apitest::XDrawPages, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo +{ +public: + ScDrawPagesObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScDrawPagesObj::ScDrawPagesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(3) + , XServiceInfo("ScDrawPagesObj", "com.sun.star.drawing.DrawPages") +{ +} + +uno::Reference ScDrawPagesObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + + xDP->insertNewByIndex(1); + xDP->insertNewByIndex(2); + + return xDP; +} + +void ScDrawPagesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDrawPagesObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..c01a40c47 --- /dev/null +++ b/sc/qa/extras/sceditfieldobj-cell.cxx @@ -0,0 +1,213 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScEditFieldObj_Cell : public CalcUnoApiTest, + 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 init() override; + virtual uno::Reference getTextContent() override; + virtual uno::Reference 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: + uno::Reference mxComponent; + static uno::Reference mxField; +}; + +uno::Reference ScEditFieldObj_Cell::mxField; + +ScEditFieldObj_Cell::ScEditFieldObj_Cell() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , TextContent(text::TextContentAnchorType_AS_CHARACTER, + text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE, + text::WrapTextMode_NONE) +{ +} + +void ScEditFieldObj_Cell::setUp() +{ + CalcUnoApiTest::setUp(); + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScEditFieldObj_Cell::tearDown() +{ + mxField.clear(); + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +namespace +{ +uno::Reference getNewField(const uno::Reference& xSM) +{ + uno::Reference xField(xSM->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + uno::Reference 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 ScEditFieldObj_Cell::init() +{ + // Return a field that's already in the cell. + if (!mxField.is()) + { + uno::Reference 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 xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + // Use cell A1 for this. + uno::Reference xCell = xSheet->getCellByPosition(0, 0); + uno::Reference xText(xCell, uno::UNO_QUERY_THROW); + + uno::Reference xCursor = xText->createTextCursor(); + uno::Reference xRange(xCursor, uno::UNO_QUERY_THROW); + uno::Reference xContent(mxField, uno::UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, false); + } + return mxField; +} + +uno::Reference ScEditFieldObj_Cell::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference xSM(mxComponent, uno::UNO_QUERY_THROW); + return uno::Reference(getNewField(xSM), uno::UNO_QUERY_THROW); +} + +uno::Reference ScEditFieldObj_Cell::getTextRange() +{ + // Use cell A2 for this. + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xCell = xSheet->getCellByPosition(0, 1); + uno::Reference xText(xCell, uno::UNO_QUERY_THROW); + + uno::Reference xCursor = xText->createTextCursor(); + uno::Reference xRange(xCursor, uno::UNO_QUERY_THROW); + return xRange; +} + +void ScEditFieldObj_Cell::testEditFieldProperties() +{ + uno::Reference xSM(mxComponent, uno::UNO_QUERY_THROW); + + { + // Test properties of date time field. + uno::Reference xField( + xSM->createInstance("com.sun.star.text.textfield.DateTime"), uno::UNO_QUERY_THROW); + uno::Reference xPropSet(xField, uno::UNO_QUERY_THROW); + + uno::Reference 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 xField( + xSM->createInstance("com.sun.star.text.textfield.docinfo.Title"), uno::UNO_QUERY_THROW); + uno::Reference xPropSet(xField, uno::UNO_QUERY_THROW); + + uno::Reference 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 000000000..6e8721ed7 --- /dev/null +++ b/sc/qa/extras/sceditfieldobj-header.cxx @@ -0,0 +1,173 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScEditFieldObj_Header : public CalcUnoApiTest, + 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 init() override; + virtual uno::Reference getTextContent() override; + virtual uno::Reference 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: + uno::Reference mxComponent; + static uno::Reference mxField; + static uno::Reference mxRightText; +}; + +uno::Reference ScEditFieldObj_Header::mxField; +uno::Reference ScEditFieldObj_Header::mxRightText; + +ScEditFieldObj_Header::ScEditFieldObj_Header() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , TextContent(text::TextContentAnchorType_AS_CHARACTER, + text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE, + text::WrapTextMode_NONE) +{ +} + +void ScEditFieldObj_Header::setUp() +{ + CalcUnoApiTest::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(); + closeDocument(mxComponent); + + CalcUnoApiTest::tearDown(); +} + +uno::Reference ScEditFieldObj_Header::init() +{ + // Return a field that's already in the header. + if (!mxField.is()) + { + uno::Reference 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 xSFS(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xStyleFamilies(xSFS->getStyleFamilies(), + uno::UNO_SET_THROW); + uno::Reference xPageStyles(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY_THROW); + uno::Reference xPropSet(xPageStyles->getByName("Default"), + uno::UNO_QUERY_THROW); + + uno::Reference xHeaderContent( + xPropSet->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW); + + // Use the left header text. + uno::Reference xText = xHeaderContent->getLeftText(); + uno::Reference xCursor = xText->createTextCursor(); + uno::Reference xRange(xCursor, uno::UNO_QUERY_THROW); + uno::Reference xContent(mxField, uno::UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, false); + + xPropSet->setPropertyValue("RightPageHeaderContent", uno::Any(xHeaderContent)); + + mxRightText = xHeaderContent->getRightText(); + } + + return mxField; +} + +uno::Reference ScEditFieldObj_Header::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference xSM(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xField( + xSM->createInstance("com.sun.star.text.TextField.Date"), uno::UNO_QUERY_THROW); + return xField; +} + +uno::Reference ScEditFieldObj_Header::getTextRange() +{ + // Use the right header text for this. + uno::Reference 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 000000000..7811d6c83 --- /dev/null +++ b/sc/qa/extras/scfilterdescriptorbase.cxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScFilterDescriptorBase : public CalcUnoApiTest, + 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 void tearDown() override; + + virtual uno::Reference 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(); + +private: + uno::Reference mxComponent; +}; + +ScFilterDescriptorBase::ScFilterDescriptorBase() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "Orientation", "OutputPosition" }) + , XServiceInfo("ScFilterDescriptorBase", "com.sun.star.sheet.SheetFilterDescriptor") +{ +} + +uno::Reference ScFilterDescriptorBase::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndexAccess(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference 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 xSF(xSheet, uno::UNO_QUERY_THROW); + + return xSF->createFilterDescriptor(true); +} + +void ScFilterDescriptorBase::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScFilterDescriptorBase::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..ee6456be1 --- /dev/null +++ b/sc/qa/extras/scfunctiondescriptionobj.cxx @@ -0,0 +1,90 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScFunctionDescriptionObj : public CalcUnoApiTest, public apitest::FunctionDescription +{ +public: + ScFunctionDescriptionObj(); + + virtual uno::Sequence init() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScFunctionDescriptionObj); + + // FunctionDescription + CPPUNIT_TEST(testFunctionDescriptionProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScFunctionDescriptionObj::ScFunctionDescriptionObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Sequence ScFunctionDescriptionObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xMSF(xDoc, UNO_QUERY_THROW); + uno::Reference xFDs( + xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"), UNO_QUERY_THROW); + + uno::Reference xNA(xFDs, UNO_QUERY_THROW); + uno::Sequence names = xNA->getElementNames(); + + uno::Sequence sPropertyValues; + CPPUNIT_ASSERT(xNA->getByName(names[0]) >>= sPropertyValues); + return sPropertyValues; +} + +void ScFunctionDescriptionObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScFunctionDescriptionObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..385ea7d89 --- /dev/null +++ b/sc/qa/extras/scfunctionlistobj.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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScFunctionListObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XFunctionDescriptions, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScFunctionListObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScFunctionListObj::ScFunctionListObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType>::get()) + , XIndexAccess(395) + , XNameAccess("IF") + , XServiceInfo("stardiv.StarCalc.ScFunctionListObj", "com.sun.star.sheet.FunctionDescriptions") +{ +} + +uno::Reference ScFunctionListObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"); +} + +void ScFunctionListObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScFunctionListObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..4333ef6a5 --- /dev/null +++ b/sc/qa/extras/scheaderfieldsobj.cxx @@ -0,0 +1,122 @@ +/* -*- 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScHeaderFieldsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XRefreshable +{ +public: + ScHeaderFieldsObj(); + + virtual uno::Reference 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: + uno::Reference m_xComponent; + // 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 m_xText; +}; + +uno::Reference ScHeaderFieldsObj::m_xText; + +ScHeaderFieldsObj::ScHeaderFieldsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , ::apitest::XElementAccess(cppu::UnoType::get()) +{ +} + +uno::Reference ScHeaderFieldsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + uno::Reference xNA1(xNA->getByName("PageStyles"), uno::UNO_QUERY_THROW); + uno::Reference xStyle(xNA1->getByName("Default"), uno::UNO_QUERY_THROW); + + uno::Reference xPropertySet(xStyle, uno::UNO_QUERY_THROW); + uno::Reference xHFC( + xPropertySet->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW); + m_xText = xHFC->getLeftText(); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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 xTFS(m_xText, uno::UNO_QUERY_THROW); + return xTFS->getTextFields(); +} + +void ScHeaderFieldsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScHeaderFieldsObj::tearDown() +{ + m_xText.clear(); + + closeDocument(m_xComponent); + CalcUnoApiTest::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 000000000..454a402da --- /dev/null +++ b/sc/qa/extras/scheaderfootercontentobj.cxx @@ -0,0 +1,104 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScHeaderFooterContentObj : public CalcUnoApiTest, public apitest::XHeaderFooterContent +{ +public: + ScHeaderFooterContentObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScHeaderFooterContentObj); + + // XHeaderFooterContent + CPPUNIT_TEST(testGetCenterText); + CPPUNIT_TEST(testGetLeftText); + CPPUNIT_TEST(testGetRightText); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScHeaderFooterContentObj::ScHeaderFooterContentObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScHeaderFooterContentObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xStyleFamSupp(xDoc, UNO_QUERY_THROW); + uno::Reference xStyleFamiliesNames(xStyleFamSupp->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference xPageStyles(xStyleFamiliesNames->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Any aDefaultStyle = xPageStyles->getByName("Default"); + uno::Reference xProp(aDefaultStyle, UNO_QUERY_THROW); + + uno::Any aHFC = xProp->getPropertyValue("RightPageHeaderContent"); + uno::Reference xHFC(aHFC, UNO_QUERY_THROW); + + uno::Reference xTxtCenter = xHFC->getCenterText(); + uno::Reference xTxtLeft = xHFC->getLeftText(); + uno::Reference xTxtRight = xHFC->getRightText(); + + xTxtCenter->setString("CENTER"); + xTxtLeft->setString("LEFT"); + xTxtRight->setString("RIGHT"); + + xProp->setPropertyValue("RightPageHeaderContent", aHFC); + + return xHFC; +} + +void ScHeaderFooterContentObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScHeaderFooterContentObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..b4812096e --- /dev/null +++ b/sc/qa/extras/scimportdescriptorbaseobj.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 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScImportDescriptorBaseObj : public CalcUnoApiTest, public apitest::DatabaseImportDescriptor +{ +public: + ScImportDescriptorBaseObj(); + + virtual uno::Reference init() override; + virtual uno::Reference getXImportable() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScImportDescriptorBaseObj); + + // DatabaseImportDescriptor + CPPUNIT_TEST(testDatabaseImportDescriptorProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScImportDescriptorBaseObj::ScImportDescriptorBaseObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScImportDescriptorBaseObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + return xSheet; +} + +uno::Reference ScImportDescriptorBaseObj::getXImportable() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference XImportable(xSheet, UNO_QUERY_THROW); + return XImportable; +} + +void ScImportDescriptorBaseObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScImportDescriptorBaseObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..30c2cc891 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx @@ -0,0 +1,96 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_CellAnnotationsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_CellAnnotationsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_CellAnnotationsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_CellAnnotationsEnumeration::ScIndexEnumeration_CellAnnotationsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_CellAnnotationsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSAS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xSA(xSAS->getAnnotations(), uno::UNO_SET_THROW); + xSA->insertNew(table::CellAddress(0, 5, 5), "Note"); + + uno::Reference xEA(xSA, uno::UNO_QUERY_THROW); + uno::Reference xE(xEA->createEnumeration(), uno::UNO_SET_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_CellAnnotationsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_CellAnnotationsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..63446d4f8 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_cellarealinksenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_CellAreaLinksEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_CellAreaLinksEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_CellAreaLinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_CellAreaLinksEnumeration::ScIndexEnumeration_CellAreaLinksEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_CellAreaLinksEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xAL; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("AreaLinks") >>= xAL); + xAL->insertAtPosition(table::CellAddress(1, 2, 3), + "ScIndexEnumeration_CellAreaLinksEnumeration.ods", "A2:B5", "", ""); + + uno::Reference xEA(xAL, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_CellAreaLinksEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_CellAreaLinksEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..08a6805f8 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_databaserangesenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DatabaseRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DatabaseRangesEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DatabaseRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_DatabaseRangesEnumeration::ScIndexEnumeration_DatabaseRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_DatabaseRangesEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xDR; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("DatabaseRanges") >>= xDR); + xDR->addNewByName("DatabaseRange", table::CellRangeAddress(0, 2, 4, 5, 6)); + + uno::Reference xEA(xDR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DatabaseRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_DatabaseRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..d29b35220 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotFieldsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotFieldsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotFieldsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_DataPilotFieldsEnumeration::ScIndexEnumeration_DataPilotFieldsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_DataPilotFieldsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference 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 xEA(xDPD->getDataPilotFields(), + uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotFieldsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_DataPilotFieldsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..05ce7ffdd --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotItemsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotItemsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotItemsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_DataPilotItemsEnumeration::ScIndexEnumeration_DataPilotItemsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_DataPilotItemsEnumeration::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no document", xDoc.is()); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Any aValue; + uno::Reference 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 xDPF(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xEA(xDPF->getItems(), uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotItemsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_DataPilotItemsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..7f5985784 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx @@ -0,0 +1,109 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotTablesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotTablesEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotTablesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_DataPilotTablesEnumeration::ScIndexEnumeration_DataPilotTablesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_DataPilotTablesEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference 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 xEA(xDPT, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotTablesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_DataPilotTablesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..d229dd597 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_ddelinksenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DDELinksEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DDELinksEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DDELinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_DDELinksEnumeration::ScIndexEnumeration_DDELinksEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_DDELinksEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xPropertySet(xDoc, uno::UNO_QUERY_THROW); + + uno::Reference xEA(xPropertySet->getPropertyValue("DDELinks"), + uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DDELinksEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_DDELinksEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..91408ddbf --- /dev/null +++ b/sc/qa/extras/scindexenumeration_functiondescriptionenumeration.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 +#include + +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_FunctionDescriptionEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_FunctionDescriptionEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_FunctionDescriptionEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_FunctionDescriptionEnumeration:: + ScIndexEnumeration_FunctionDescriptionEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_FunctionDescriptionEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xEA( + xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"), uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_FunctionDescriptionEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_FunctionDescriptionEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..284436242 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx @@ -0,0 +1,90 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_LabelRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_LabelRangesEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_LabelRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_LabelRangesEnumeration::ScIndexEnumeration_LabelRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_LabelRangesEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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 xEA(xLR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_LabelRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_LabelRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..d508f4fe1 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx @@ -0,0 +1,95 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_NamedRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_NamedRangesEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_NamedRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_NamedRangesEnumeration::ScIndexEnumeration_NamedRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_NamedRangesEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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 xEA(xNR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_NamedRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_NamedRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..9de0bbb98 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_scenariosenumeration.cxx @@ -0,0 +1,103 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_ScenariosEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_ScenariosEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_ScenariosEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_ScenariosEnumeration::ScIndexEnumeration_ScenariosEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_ScenariosEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xScenariosSupplier(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + xScenariosSupplier->getScenarios()->addNewByName("ScScenario", { xCRA->getRangeAddress() }, + "Range"); + uno::Reference xEA(xScenariosSupplier->getScenarios(), + uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_ScenariosEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_ScenariosEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..1ce69f621 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SheetCellRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SheetCellRangesEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SheetCellRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_SheetCellRangesEnumeration::ScIndexEnumeration_SheetCellRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_SheetCellRangesEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xSCR( + xMSF->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY_THROW); + uno::Reference 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 xEA(xSCR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SheetCellRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_SheetCellRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..e0a3b5cd2 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_sheetlinksenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SheetLinksEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SheetLinksEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SheetLinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_SheetLinksEnumeration::ScIndexEnumeration_SheetLinksEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_SheetLinksEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSL(xSheet0, uno::UNO_QUERY_THROW); + xSL->link("ScIndexEnumeration_SheetLinksEnumeration.ods", "Sheet1", "", "", + sheet::SheetLinkMode_VALUE); + + uno::Reference xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xSheetLinks; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("SheetLinks") >>= xSheetLinks); + + uno::Reference xEA(xSheetLinks, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SheetLinksEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_SheetLinksEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..faf8878a2 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_spreadsheetsenumeration.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 +#include + +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SpreadsheetsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SpreadsheetsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SpreadsheetsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_SpreadsheetsEnumeration::ScIndexEnumeration_SpreadsheetsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_SpreadsheetsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xEA(xSheets, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SpreadsheetsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_SpreadsheetsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..a34207b9b --- /dev/null +++ b/sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx @@ -0,0 +1,90 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SpreadsheetViewPanesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SpreadsheetViewPanesEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SpreadsheetViewPanesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_SpreadsheetViewPanesEnumeration:: + ScIndexEnumeration_SpreadsheetViewPanesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_SpreadsheetViewPanesEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xModel(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xController(xModel->getCurrentController(), + uno::UNO_SET_THROW); + uno::Reference xIA(xController, uno::UNO_QUERY_THROW); + xIA->getByIndex(0); + + uno::Reference xEA(xIA, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SpreadsheetViewPanesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_SpreadsheetViewPanesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..9adba41f6 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SubTotalFieldsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SubTotalFieldsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SubTotalFieldsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_SubTotalFieldsEnumeration::ScIndexEnumeration_SubTotalFieldsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_SubTotalFieldsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSTC(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xSTD(xSTC->createSubTotalDescriptor(true), + uno::UNO_SET_THROW); + + xSTD->addNew({ { 5, sheet::GeneralFunction_SUM } }, 1); + + uno::Reference xIA_STD(xSTD, uno::UNO_QUERY_THROW); + uno::Reference xEA(xIA_STD, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SubTotalFieldsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_SubTotalFieldsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..23f930af1 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx @@ -0,0 +1,83 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableAutoFormatEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableAutoFormatEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableAutoFormatEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_TableAutoFormatEnumeration::ScIndexEnumeration_TableAutoFormatEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_TableAutoFormatEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xEA( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableAutoFormatEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_TableAutoFormatEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..55134be87 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx @@ -0,0 +1,162 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableChartsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableChartsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableChartsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_TableChartsEnumeration::ScIndexEnumeration_TableChartsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_TableChartsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Reference xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000), + { xCRA->getRangeAddress() }, true, false); + + uno::Reference xEA(xTC, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableChartsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_TableChartsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..7ec0de3d2 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablecolumnsenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableColumnsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableColumnsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableColumnsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_TableColumnsEnumeration::ScIndexEnumeration_TableColumnsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_TableColumnsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xNA->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference xColumnRowRange(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTableColumns(xColumnRowRange->getColumns(), + uno::UNO_SET_THROW); + uno::Reference xEA(xTableColumns, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableColumnsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_TableColumnsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..bf3a03f8c --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx @@ -0,0 +1,118 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableConditionalEntryEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableConditionalEntryEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableConditionalEntryEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_TableConditionalEntryEnumeration:: + ScIndexEnumeration_TableConditionalEntryEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_TableConditionalEntryEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 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 xPropertySet(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xSCE( + xPropertySet->getPropertyValue("ConditionalFormat"), uno::UNO_QUERY_THROW); + xSCE->addNew(aConditions); + + uno::Any aProperty; + aProperty <<= xSCE; + xPropertySet->setPropertyValue("ConditionalFormat", aProperty); + + uno::Reference xEA(xSCE, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableConditionalEntryEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_TableConditionalEntryEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..3d3ceefb8 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx @@ -0,0 +1,95 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableRowsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableRowsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableRowsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_TableRowsEnumeration::ScIndexEnumeration_TableRowsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_TableRowsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xNA->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + // limit the range the XEnumeration has to walk over (see fdo#45337). + uno::Reference xCR(xSheet0->getCellRangeByName("A1:A4"), uno::UNO_SET_THROW); + + uno::Reference xColRowRange(xCR, uno::UNO_QUERY_THROW); + uno::Reference xTableRows(xColRowRange->getRows(), uno::UNO_SET_THROW); + uno::Reference xEA(xTableRows, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableRowsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_TableRowsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..a0dd65fc6 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_textfieldenumeration.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TextFieldEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TextFieldEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TextFieldEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; +}; + +ScIndexEnumeration_TextFieldEnumeration::ScIndexEnumeration_TextFieldEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScIndexEnumeration_TextFieldEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xTF(xMSF->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + uno::Reference xTC(xTF, uno::UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xCell(xSheet0->getCellByPosition(2, 3), uno::UNO_SET_THROW); + uno::Reference xText(xCell, uno::UNO_QUERY_THROW); + xText->insertTextContent(xText->createTextCursor(), xTC, true); + uno::Reference xTFS(xCell, uno::UNO_QUERY_THROW); + uno::Reference xEA(xTFS->getTextFields(), uno::UNO_SET_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TextFieldEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScIndexEnumeration_TextFieldEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..15b7ee494 --- /dev/null +++ b/sc/qa/extras/sclabelrangeobj.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 +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScLabelRangeObj : public CalcUnoApiTest, public apitest::XLabelRange +{ +public: + ScLabelRangeObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScLabelRangeObj); + + // XLabelRange + CPPUNIT_TEST(testGetSetDataArea); + CPPUNIT_TEST(testGetSetLabelArea); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScLabelRangeObj::ScLabelRangeObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScLabelRangeObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xProp(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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 xLabelRange(xLabelRanges->getByIndex(0), + uno::UNO_QUERY_THROW); + return xLabelRange; +} + +void ScLabelRangeObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScLabelRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..9f720eeaa --- /dev/null +++ b/sc/qa/extras/sclabelrangesobj.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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScLabelRangesObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XLabelRanges +{ +public: + ScLabelRangesObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScLabelRangesObj::ScLabelRangesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) +{ +} + +uno::Reference ScLabelRangesObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xProp(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScLabelRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..1a5dcd013 --- /dev/null +++ b/sc/qa/extras/scmodelobj.cxx @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +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 void tearDown() override; + + virtual uno::Reference init() override; + virtual uno::Reference getXMSF() override; + virtual uno::Sequence> 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::Reference mxComponent; + uno::Sequence> m_xCells; +}; + +ScModelObj::ScModelObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScModelObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xModel(xDoc, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIA(xSheets, UNO_QUERY_THROW); + uno::Reference 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::Reference ScModelObj::getXMSF() { return getMultiServiceFactory(); } + +uno::Sequence> ScModelObj::getXCells() { return m_xCells; } + +void ScModelObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL(u"ScModelObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScModelObj::tearDown() +{ + closeDocument(mxComponent); + UnoApiTest::tearDown(); +} + +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 000000000..7ba7ec222 --- /dev/null +++ b/sc/qa/extras/scnamedrangeobj.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScNamedRangeObj : public CalcUnoApiTest, + public apitest::XCellRangeReferrer, + public apitest::XNamed, + public apitest::XNamedRange +{ +public: + ScNamedRangeObj(); + + virtual void setUp() override; + virtual void tearDown() 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(); + uno::Reference< lang::XComponent > mxComponent; +}; + +ScNamedRangeObj::ScNamedRangeObj(): + CalcUnoApiTest("/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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL(u"ScNamedRangeObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScNamedRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..34543cf5e --- /dev/null +++ b/sc/qa/extras/scnamedrangesobj.cxx @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScNamedRangesObj : public CalcUnoApiTest, + 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 void tearDown() override; + + virtual uno::Reference init() override; + virtual uno::Reference 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(); + +private: + uno::Reference mxComponent; +}; + +ScNamedRangesObj::ScNamedRangesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(4) + , XNameAccess("initial1") + , XServiceInfo("ScNamedRangesObj", "com.sun.star.sheet.NamedRanges") +{ +} + +uno::Reference ScNamedRangesObj::init() +{ + uno::Reference xPropSet(mxComponent, UNO_QUERY_THROW); + uno::Reference xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), + UNO_QUERY_THROW); + + //set value from xnamedranges.hxx + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW); + xSheet.set(xIndexAccess->getByIndex(0), UNO_QUERY_THROW); + + return xNamedRanges; +} + +uno::Reference ScNamedRangesObj::getXNamedRanges(sal_Int32 nSheet) +{ + uno::Reference xPropSet(mxComponent, UNO_QUERY_THROW); + uno::Reference xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), + UNO_QUERY_THROW); + + //set value from xnamedranges.hxx + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW); + xSheet.set(xIndexAccess->getByIndex(nSheet), UNO_QUERY_THROW); + + return xNamedRanges; +} + +void ScNamedRangesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL(u"ScNamedRangeObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScNamedRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..e47580238 --- /dev/null +++ b/sc/qa/extras/scoutlineobj.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScOutlineObj : public CalcUnoApiTest, public apitest::XSheetOutline +{ +public: + ScOutlineObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference 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(); + +private: + uno::Reference mxComponent; +}; + +ScOutlineObj::ScOutlineObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScOutlineObj::init() +{ + // get the first sheet + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + return xSheet; +} + +void ScOutlineObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL(u"ScOutlineObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScOutlineObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..b3b878e5f --- /dev/null +++ b/sc/qa/extras/scpdfexport.cxx @@ -0,0 +1,578 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#if USE_TLS_NSS +#include +#endif + +using namespace css::lang; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScPDFExportTest : public test::BootstrapFixture, public unotest::MacrosTest +{ + Reference mxComponent; + +public: + ScPDFExportTest() {} + ~ScPDFExportTest(); + + virtual void setUp() override final; + virtual void tearDown() override final; + + // helpers +private: + std::shared_ptr exportToPDF(const uno::Reference& xModel, + const ScRange& range); + + std::shared_ptr exportToPDFWithUnoCommands(const OUString& rRange); + + static bool hasTextInPdf(const std::shared_ptr& pPDFFile, 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 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(testTdf84012); + CPPUNIT_TEST(testTdf78897); + CPPUNIT_TEST(testForcepoint97); + CPPUNIT_TEST_SUITE_END(); +}; + +constexpr OUStringLiteral DATA_DIRECTORY = u"/sc/qa/extras/testdocuments/"; + +ScPDFExportTest::~ScPDFExportTest() +{ +#if USE_TLS_NSS + NSS_Shutdown(); +#endif +} + +void ScPDFExportTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set( + css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); +} + +void ScPDFExportTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +bool ScPDFExportTest::hasTextInPdf(const std::shared_ptr& pPDFFile, + const char* sText, bool& bFound) +{ + SvStream* pStream = pPDFFile->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; + pPDFFile->CloseStream(); + return (nRead == nFileSize); +} + +std::shared_ptr +ScPDFExportTest::exportToPDF(const uno::Reference& xModel, const ScRange& range) +{ + // create temp file name + auto pTempFile = std::make_shared(); + pTempFile->EnableKillingFile(); + OUString sFileURL = pTempFile->GetURL(); + // Note: under Windows path path should be with "/" delimiters instead of "\\" + // due to usage of INetURLObject() that converts "\\" to hexadecimal notation. + ::osl::FileBase::getFileURLFromSystemPath(sFileURL, sFileURL); + + // get XSpreadsheet + uno::Reference xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xSheets, uno::UNO_QUERY_THROW); + uno::Reference rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + // select requested cells to print + // query for the XCellRange interface + uno::Reference xCellRange = rSheet->getCellRangeByPosition( + range.aStart.Col(), range.aStart.Row(), range.aEnd.Col(), range.aEnd.Row()); + { + uno::Reference xController = xModel->getCurrentController(); + CPPUNIT_ASSERT(xController.is()); + + uno::Reference 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 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 seqArguments{ + comphelper::makePropertyValue("FilterData", aFilterData), + comphelper::makePropertyValue("FilterName", OUString("calc_pdf_Export")), + comphelper::makePropertyValue("URL", sFileURL) + }; + + // call storeToURL() + uno::Reference xComponent(mxComponent, UNO_SET_THROW); + uno::Reference xStorable(xComponent, UNO_QUERY); + xStorable->storeToURL(sFileURL, seqArguments); + + // return file object with generated PDF + return pTempFile; +} + +std::shared_ptr ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange) +{ + // create temp file name + auto pTempFile = std::make_shared(); + pTempFile->EnableKillingFile(); + OUString sFileURL = pTempFile->GetURL(); + // Note: under Windows path path should be with "/" delimiters instead of "\\" + // due to usage of INetURLObject() that converts "\\" to hexadecimal notation. + ::osl::FileBase::getFileURLFromSystemPath(sFileURL, sFileURL); + + uno::Sequence aArgs + = comphelper::InitPropertySequence({ { "ToPoint", uno::Any(rRange) } }); + dispatchCommand(mxComponent, ".uno:GoToCell", aArgs); + + dispatchCommand(mxComponent, ".uno:DefinePrintArea", {}); + + uno::Sequence aFilterData(comphelper::InitPropertySequence( + { { "ViewPDFAfterExport", uno::Any(true) }, { "Printing", uno::Any(sal_Int32(2)) } })); + + uno::Sequence aDescriptor( + comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("calc_pdf_Export")) }, + { "FilterData", uno::Any(aFilterData) }, + { "URL", uno::Any(sFileURL) } })); + + dispatchCommand(mxComponent, ".uno:ExportToPDF", aDescriptor); + + // return file object with generated PDF + return pTempFile; +} + +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 xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("First Sheet", 0); + uno::Reference 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(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); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(false, bFound); + } + + // G1:H1 + { + ScRange range1(6, 0, 0, 7, 0, 0); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // H1:I1 + { + ScRange range1(7, 0, 0, 8, 0, 0); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testExportFitToPage_Tdf103516() +{ + // create test document + mxComponent = loadFromDesktop("private:factory/scalc"); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("First Sheet", 0); + uno::Reference 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(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); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 2>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // A1:L80: 4-page export + { + ScRange range1(0, 0, 0, 11, 79, 0); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 4>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // set fit to page: width=1 page, height=0 (automatic) + uno::Reference xStyleFamSupp(xDoc, UNO_QUERY_THROW); + uno::Reference xStyleFamiliesNames(xStyleFamSupp->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference xPageStyles(xStyleFamiliesNames->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Any aDefaultStyle = xPageStyles->getByName("Default"); + uno::Reference xProp(aDefaultStyle, UNO_QUERY_THROW); + + uno::Any aScaleX, aScaleY; + sal_Int16 nScale; + aScaleX <<= static_cast(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); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/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); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 1>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testUnoCommands_Tdf120161() +{ + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf120161.ods", + "com.sun.star.sheet.SpreadsheetDocument"); + + // A1:G1 + { + std::shared_ptr pPDFFile = exportToPDFWithUnoCommands("A1:G1"); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(false, bFound); + } + + // G1:H1 + { + std::shared_ptr pPDFFile = exportToPDFWithUnoCommands("G1:H1"); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // H1:I1 + { + std::shared_ptr pPDFFile = exportToPDFWithUnoCommands("H1:I1"); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testTdf64703_hiddenPageBreak() +{ + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf64703_hiddenPageBreak.ods", + "com.sun.star.sheet.SpreadsheetDocument"); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + + // A1:A11: 4-page export + { + ScRange range1(0, 0, 0, 0, 10, 0); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 4>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testTdf143978() +{ + std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf143978.ods", + "com.sun.star.sheet.SpreadsheetDocument"); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + + // A1:A2 + ScRange range1(0, 0, 0, 0, 1, 0); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + // Parse the export result with pdfium. + SvFileStream aFile(pPDFFile->GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + std::unique_ptr pPdfDocument + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + CPPUNIT_ASSERT(pPdfDocument); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr 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 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 pPageObject2 = pPdfPage->getObject(1); + OUString sText2 = pPageObject2->getText(pTextPage); + CPPUNIT_ASSERT_EQUAL(OUString("2021-11-17"), sText2); +} + +void ScPDFExportTest::testTdf84012() +{ + std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf84012.ods", + "com.sun.star.sheet.SpreadsheetDocument"); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + + // A1 + ScRange range1(0, 0, 0, 0, 0, 0); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + // Parse the export result with pdfium. + SvFileStream aFile(pPDFFile->GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + std::unique_ptr pPdfDocument + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + CPPUNIT_ASSERT(pPdfDocument); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr pTextPage = pPdfPage->getTextPage(); + + int nChars = pTextPage->countChars(); + std::vector 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 pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf78897.xls", + "com.sun.star.sheet.SpreadsheetDocument"); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + + // C3:D3 + ScRange range1(2, 2, 0, 3, 2, 0); + std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + // Parse the export result with pdfium. + SvFileStream aFile(pPDFFile->GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + std::unique_ptr pPdfDocument + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + CPPUNIT_ASSERT(pPdfDocument); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr pTextPage = pPdfPage->getTextPage(); + + int nChars = pTextPage->countChars(); + std::vector 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() +{ + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + "forcepoint97.xlsx", + "com.sun.star.sheet.SpreadsheetDocument"); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + + // A1:H81 + ScRange range1(0, 0, 0, 7, 81, 0); + std::shared_ptr pPDFFile = 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 000000000..84fdc3857 --- /dev/null +++ b/sc/qa/extras/screcentfunctionsobj.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 +#include + +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScRecentFunctionsObj : public CalcUnoApiTest, public apitest::XRecentFunctions +{ +public: + ScRecentFunctionsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScRecentFunctionsObj); + + // XRecentFunctions + CPPUNIT_TEST(testGetRecentFunctionIds); + CPPUNIT_TEST(testSetRecentFunctionIds); + CPPUNIT_TEST(testGetMaxRecentFunctions); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScRecentFunctionsObj::ScRecentFunctionsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScRecentFunctionsObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.RecentFunctions"); +} + +void ScRecentFunctionsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScRecentFunctionsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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/scscenariosobj.cxx b/sc/qa/extras/scscenariosobj.cxx new file mode 100644 index 000000000..2805772f1 --- /dev/null +++ b/sc/qa/extras/scscenariosobj.cxx @@ -0,0 +1,138 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScScenariosObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XNameAccess, + public apitest::XIndexAccess, + public apitest::XScenarios, + public apitest::XServiceInfo +{ +public: + ScScenariosObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScScenariosObj::ScScenariosObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XNameAccess("ScScenarios") + , XIndexAccess(1) + , XServiceInfo("ScScenariosObj", "com.sun.star.sheet.Scenarios") +{ +} + +uno::Reference ScScenariosObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference 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 xCellRange(xSheet, uno::UNO_QUERY_THROW); + uno::Reference xCellRange2 = xCellRange->getCellRangeByName("A1:N4"); + uno::Reference xCRAddressable(xCellRange2, uno::UNO_QUERY_THROW); + table::CellRangeAddress aCellRangeAddr = xCRAddressable->getRangeAddress(); + + uno::Reference xSupplier(xSheet, uno::UNO_QUERY_THROW); + xSupplier->getScenarios()->addNewByName("ScScenarios", { aCellRangeAddr }, "Range"); + + return xSupplier->getScenarios(); +} + +void ScScenariosObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScScenariosObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..ef8761a65 --- /dev/null +++ b/sc/qa/extras/scshapeobj.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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScShapeObj : public CalcUnoApiTest, + public apitest::Shape, + public apitest::XComponent, + public apitest::XGluePointsSupplier, + public apitest::XShape, + public apitest::XShapeDescriptor +{ +public: + ScShapeObj(); + + virtual uno::Reference init() override; + virtual uno::Reference getXSheetDocument() override; + virtual void triggerDesktopTerminate() override{}; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScShapeObj::ScShapeObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XShapeDescriptor("com.sun.star.drawing.RectangleShape") +{ +} + +uno::Reference ScShapeObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference 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 xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xDrawPages = xDPS->getDrawPages(); + uno::Reference xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference 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 ScShapeObj::getXSheetDocument() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + return xDoc; +} + +void ScShapeObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScShapeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..c45c9b2db --- /dev/null +++ b/sc/qa/extras/scsheetlinkobj.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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScSheetLinkObj : public CalcUnoApiTest, + public apitest::SheetLink, + public apitest::XNamed, + public apitest::XRefreshable +{ +public: + ScSheetLinkObj(); + + virtual uno::Reference init() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSheetLinkObj); + + // SheetLink + CPPUNIT_TEST(testSheetLinkProperties); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetNameByScSheetLinkObj); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScSheetLinkObj::ScSheetLinkObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/ScSheetLinkObj.ods")) +{ +} + +uno::Reference ScSheetLinkObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSL(xSheet, uno::UNO_QUERY_THROW); + xSL->link(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/ScSheetLinkObj.ods"), + "Sheet1", "", "", sheet::SheetLinkMode_VALUE); + + uno::Reference xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference sheetLinks; + CPPUNIT_ASSERT(xPropSet->getPropertyValue("SheetLinks") >>= sheetLinks); + CPPUNIT_ASSERT(sheetLinks.is()); + + uno::Any aAny = sheetLinks->getByName(sheetLinks->getElementNames()[0]); + uno::Reference sheetLink; + aAny >>= sheetLink; + return sheetLink; +} + +void ScSheetLinkObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSheetLinkObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..e61c71c6a --- /dev/null +++ b/sc/qa/extras/scsheetlinksobj.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 +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScSheetLinksObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScSheetLinksObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScSheetLinksObj::ScSheetLinksObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) + , XNameAccess(m_directories.getURLFromSrc(u"/sc/qa/extras/testdocuments/ScSheetLinksObj.ods")) + , XServiceInfo("ScSheetLinksObj", "com.sun.star.sheet.SheetLinks") +{ +} + +uno::Reference ScSheetLinksObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSL(xSheet0, uno::UNO_QUERY_THROW); + OUString aFileURL; + createFileURL(u"ScSheetLinksObj.ods", aFileURL); + xSL->link(aFileURL, "Sheet1", "", "", sheet::SheetLinkMode_VALUE); + + uno::Reference xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xNA; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("SheetLinks") >>= xNA); + + return xNA; +} + +void ScSheetLinksObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSheetLinksObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..439e906fa --- /dev/null +++ b/sc/qa/extras/scsortdescriptorbaseobj.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 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSortDescriptorBaseObj : public CalcUnoApiTest, public apitest::SheetSortDescriptor2 +{ +public: + ScSortDescriptorBaseObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSortDescriptorBaseObj); + + // SheetSortDescriptor2 + CPPUNIT_TEST(testSheetSortDescriptor2Properties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScSortDescriptorBaseObj::ScSortDescriptorBaseObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScSortDescriptorBaseObj::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference xSortable(xSheet, UNO_QUERY_THROW); + return xSortable; +} + +void ScSortDescriptorBaseObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSortDescriptorBaseObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..a06d65cd5 --- /dev/null +++ b/sc/qa/extras/scspreadsheetsettings.cxx @@ -0,0 +1,97 @@ +/* -*- 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 +#include +#include +#include + +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSpreadsheetSettings : public CalcUnoApiTest, + public apitest::GlobalSheetSettings, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScSpreadsheetSettings(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScSpreadsheetSettings::ScSpreadsheetSettings() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "LinkUpdateMode", "UsePrinterMetrics", "UserLists" }) + , XServiceInfo("stardiv.StarCalc.ScSpreadsheetSettings", + "com.sun.star.sheet.GlobalSheetSettings") +{ +} + +uno::Reference ScSpreadsheetSettings::init() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.GlobalSheetSettings"); +} + +void ScSpreadsheetSettings::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSpreadsheetSettings::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..faf0b5605 --- /dev/null +++ b/sc/qa/extras/scspreadsheetsettingsobj.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 +#include +#include + +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScSpreadsheetSettingsObj : public CalcUnoApiTest, + public apitest::SpreadsheetDocumentSettings, + public apitest::XPropertySet +{ +public: + ScSpreadsheetSettingsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScSpreadsheetSettingsObj::ScSpreadsheetSettingsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ + "AreaLinks", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "ColumnLabelRanges", + "DDELinks", + "DatabaseRanges", + "ExternalDocLinks", + "InteropGrabBag", + "NamedRanges", + "NullDate", + "RowLabelRanges", + "SheetLinks", + }) +{ +} + +uno::Reference ScSpreadsheetSettingsObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + return xDoc; +} + +void ScSpreadsheetSettingsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSpreadsheetSettingsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..9b789d935 --- /dev/null +++ b/sc/qa/extras/scstylefamiliesobj.cxx @@ -0,0 +1,145 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScStyleFamiliesObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XStyleLoader +{ +public: + ScStyleFamiliesObj(); + + virtual uno::Reference init() override; + virtual uno::Reference getTargetDoc() override; + virtual uno::Reference 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 m_xComponent; + uno::Reference m_xSrcComponent; +}; + +ScStyleFamiliesObj::ScStyleFamiliesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(2) + , XNameAccess("CellStyles") + , XServiceInfo("ScStyleFamiliesObj", "com.sun.star.style.StyleFamilies") +{ +} + +uno::Reference ScStyleFamiliesObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + + return xNA; +} + +uno::Reference ScStyleFamiliesObj::getTargetDoc() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + return xDoc; +} + +uno::Reference ScStyleFamiliesObj::getSourceComponent() +{ + return m_xSrcComponent; +} + +OUString ScStyleFamiliesObj::getTestURL() +{ + OUString aFileURL; + createFileURL(u"ScStyleFamiliesObj.ods", aFileURL); + return aFileURL; +} + +void ScStyleFamiliesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); + + m_xSrcComponent = loadFromDesktop(getTestURL()); +} + +void ScStyleFamiliesObj::tearDown() +{ + closeDocument(m_xComponent); + closeDocument(m_xSrcComponent); + CalcUnoApiTest::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 000000000..c1edea68a --- /dev/null +++ b/sc/qa/extras/scstylefamilyobj.cxx @@ -0,0 +1,143 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScStyleFamilyObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XNameReplace, + public apitest::XServiceInfo +{ +public: + ScStyleFamilyObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +/* 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() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(kScStyleFamilyObjCount) + , XNameAccess("ScStyleFamilyObj") + , XNameContainer("ScStyleFamilyObj") + , XNameReplace("ScStyleFamilyObj") + , XServiceInfo("ScStyleFamilyObj", "com.sun.star.style.StyleFamily") +{ +} + +uno::Reference ScStyleFamilyObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + uno::Reference xIA(xNA, uno::UNO_QUERY_THROW); + uno::Reference xNA_SF(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xMSF(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference 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 xNC(xNA_SF, uno::UNO_QUERY_THROW); + xNC->insertByName("ScStyleFamilyObj", uno::Any(xCS)); + + return xNA_SF; +} + +void ScStyleFamilyObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScStyleFamilyObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..bf69fafba --- /dev/null +++ b/sc/qa/extras/scstyleobj.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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScStyleObj : public CalcUnoApiTest, public apitest::XNamed, public apitest::XPropertySet +{ +public: + ScStyleObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference 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(); + +private: + uno::Reference m_xComponent; +}; + +ScStyleObj::ScStyleObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("ScStyleObj") + , XPropertySet({ + "BottomBorder", "BottomBorder2", "CellProtection", "CharLocale", + "CharLocaleAsian", "CharLocaleComplex", "CharPosture", "CharPostureAsian", + "CharPostureComplex", "DiagonalBLTR", "DiagonalBLTR2", "DiagonalTLBR", + "DiagonalTLBR2", "HoriJustify", "LeftBorder", "LeftBorder2", + "NumberFormat", "Orientation", "RightBorder", "RightBorder2", + "ShadowFormat", "TableBorder", "TopBorder", "TopBorder2", + "UserDefinedAttributes", + }) +{ +} + +uno::Reference ScStyleObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xNA_StyleFamilies(xSFS->getStyleFamilies(), + uno::UNO_SET_THROW); + uno::Reference xIA_StyleFamilies(xNA_StyleFamilies, + uno::UNO_QUERY_THROW); + uno::Reference xNA_StyleFamily(xIA_StyleFamilies->getByIndex(0), + uno::UNO_QUERY_THROW); + + uno::Reference xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xStyle(xMSF->createInstance("com.sun.star.style.CellStyle"), + uno::UNO_QUERY_THROW); + uno::Reference xNC(xNA_StyleFamily, uno::UNO_QUERY_THROW); + if (xNC->hasByName("ScStyleObj")) + { + xNC->removeByName("ScStyleObj"); + } + xNC->insertByName("ScStyleObj", uno::Any(xStyle)); + + uno::Reference xIA_sheets(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA_sheets->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xCell = xSheet0->getCellByPosition(2, 3); + uno::Reference xPS(xCell, uno::UNO_QUERY_THROW); + xPS->setPropertyValue("CellStyle", uno::Any(xStyle->getName())); + + return xStyle; +} + +void ScStyleObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScStyleObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..0bae1c46d --- /dev/null +++ b/sc/qa/extras/scsubtotaldescriptorbase.cxx @@ -0,0 +1,136 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace css; + +namespace sc_apitest +{ +class ScSubTotalDescriptorBase : public CalcUnoApiTest, + 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 init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScSubTotalDescriptorBase::ScSubTotalDescriptorBase() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) + , XServiceInfo("ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor") +{ +} + +uno::Reference ScSubTotalDescriptorBase::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSTC(xSheet, uno::UNO_QUERY_THROW); + uno::Reference xSTD = xSTC->createSubTotalDescriptor(true); + + uno::Sequence xCols{ { /* Column */ 5, + /* Function */ sheet::GeneralFunction_SUM } }; + xSTD->addNew(xCols, 10); + + return xSTD; +} + +void ScSubTotalDescriptorBase::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSubTotalDescriptorBase::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..ab1a9c377 --- /dev/null +++ b/sc/qa/extras/scsubtotalfieldobj.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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSubTotalFieldObj : public CalcUnoApiTest, public apitest::XSubTotalField +{ +public: + ScSubTotalFieldObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSubTotalFieldObj); + + // XSubTotalField + CPPUNIT_TEST(testGetSetGroupColumn); + CPPUNIT_TEST(testGetSetTotalColumns); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +ScSubTotalFieldObj::ScSubTotalFieldObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScSubTotalFieldObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xSubTotalCalc(xSheet, uno::UNO_QUERY_THROW); + uno::Reference xSubTotalDesc + = xSubTotalCalc->createSubTotalDescriptor(true); + + uno::Sequence xCols{ { /* Column */ 5, + /* Function */ sheet::GeneralFunction_SUM } }; + xSubTotalDesc->addNew(xCols, 1); + + uno::Reference xDescIndex(xSubTotalDesc, uno::UNO_QUERY_THROW); + uno::Reference xSTF(xDescIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + return xSTF; +} + +void ScSubTotalFieldObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSubTotalFieldObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..0dab1c6ab --- /dev/null +++ b/sc/qa/extras/sctablecolumnobj.cxx @@ -0,0 +1,157 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScTableColumnObj : public CalcUnoApiTest, + public apitest::TableColumn, + public apitest::XCellRange, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScTableColumnObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScTableColumnObj::ScTableColumnObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XCellRange("K1:K1") + , XNamed("K") + , XPropertySet({ + "BottomBorder", + "BottomBorder2", + "CellProtection", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "CharPosture", + "CharPostureAsian", + "CharPostureComplex", + "ConditionalFormat", + "ConditionalFormatLocal", + "ConditionalFormatXML", + "DiagonalBLTR", + "DiagonalBLTR2", + "DiagonalTLBR", + "DiagonalTLBR2", + "HoriJustify", + "LeftBorder", + "LeftBorder2", + "NumberingRules", + "Orientation", + "RightBorder", + "RightBorder2", + "ShadowFormat", + "TableBorder", + "TableBorder2", + "TopBorder", + "TopBorder2", + "UserDefinedAttributes", + "Validation", + "ValidationLocal", + "ValidationXML", + "WritingMode", + }) + , XServiceInfo("ScTableColumnObj", "com.sun.star.table.TableColumn") +{ +} + +uno::Reference ScTableColumnObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + setSpreadsheet(xSheet0); + uno::Reference xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTC(xCRR->getColumns(), uno::UNO_SET_THROW); + + uno::Reference xIA_TC(xTC, uno::UNO_QUERY_THROW); + uno::Reference xReturn(xIA_TC->getByIndex(10), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScTableColumnObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableColumnObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..ccb96f7c7 --- /dev/null +++ b/sc/qa/extras/sctablecolumnsobj.cxx @@ -0,0 +1,149 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScTableColumnsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XTableColumns +{ +public: + ScTableColumnsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScTableColumnsObj::ScTableColumnsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(ScSheetLimits::CreateDefault().GetMaxColCount()) + , XNameAccess("ABC") + , XServiceInfo("ScTableColumnsObj", "com.sun.star.table.TableColumns") +{ +} + +uno::Reference ScTableColumnsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTC(xCRR->getColumns(), uno::UNO_SET_THROW); + setXSpreadsheet(xSheet0); + + uno::Reference xCR(xSheet0, uno::UNO_QUERY_THROW); + for (auto i = 0; i < xTC->getCount() - 1 && i < 3; ++i) + { + uno::Reference xST0(xCR->getCellByPosition(i, 0), uno::UNO_QUERY_THROW); + xST0->setString(OUString::number(i) + "a"); + uno::Reference 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 xST0(xCR->getCellByPosition(i, 0), uno::UNO_QUERY_THROW); + xST0->setString(""); + uno::Reference xST1(xCR->getCellByPosition(i, 1), uno::UNO_QUERY_THROW); + xST1->setString(""); + } + return xTC; +} + +void ScTableColumnsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableColumnsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..cd5286745 --- /dev/null +++ b/sc/qa/extras/sctableconditionalentryobj.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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableConditionalEntryObj : public CalcUnoApiTest, + public apitest::XSheetConditionalEntry, + public apitest::XSheetCondition +{ +public: + ScTableConditionalEntryObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScTableConditionalEntryObj::ScTableConditionalEntryObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScTableConditionalEntryObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference 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 xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference xSheetConditionalEntries; + xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT), + uno::UNO_QUERY_THROW); + + uno::Sequence 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 xSheetConditionalEntry( + xSheetConditionalEntries->getByIndex(0), uno::UNO_QUERY_THROW); + return xSheetConditionalEntry; +} + +void ScTableConditionalEntryObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableConditionalEntryObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..99e1ad04b --- /dev/null +++ b/sc/qa/extras/sctableconditionalformat.cxx @@ -0,0 +1,157 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableConditionalFormat : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XSheetConditionalEntries +{ +public: + ScTableConditionalFormat(); + + virtual uno::Reference init() override; + virtual uno::Sequence createCondition(const sal_Int32 nr) override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScTableConditionalFormat::ScTableConditionalFormat() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(2) + , XNameAccess("Entry1") + , XServiceInfo("ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat") +{ +} + +uno::Reference ScTableConditionalFormat::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference 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 xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference xSheetConditionalEntries; + xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT), + uno::UNO_QUERY_THROW); + + xSheetConditionalEntries->addNew(createCondition(5)); + xSheetConditionalEntries->addNew(createCondition(2)); + + return xSheetConditionalEntries; +} + +uno::Sequence ScTableConditionalFormat::createCondition(const sal_Int32 nr) +{ + uno::Sequence 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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableConditionalFormat::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..bb377646e --- /dev/null +++ b/sc/qa/extras/sctablerowobj.cxx @@ -0,0 +1,146 @@ +/* -*- 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScTableRowObj : public CalcUnoApiTest, + public apitest::TableRow, + public apitest::XCellRange, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScTableRowObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScTableRowObj::ScTableRowObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XCellRange("A7:A7") + , XPropertySet({ "BottomBorder", + "BottomBorder2", + "CellProtection", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "CharPosture", + "CharPostureAsian", + "CharPostureComplex", + "ConditionalFormat", + "ConditionalFormatLocal", + "ConditionalFormatXML", + "DiagonalBLTR", + "DiagonalBLTR2", + "DiagonalTLBR", + "DiagonalTLBR2", + "HoriJustify", + "LeftBorder", + "LeftBorder2", + "NumberingRules", + "Orientation", + "RightBorder", + "RightBorder2", + "ShadowFormat", + "TableBorder", + "TableBorder2", + "TopBorder", + "TopBorder2", + "UserDefinedAttributes", + "Validation", + "ValidationLocal", + "ValidationXML", + "WritingMode" }) + , XServiceInfo("ScTableRowObj", "com.sun.star.table.TableRow") +{ +} + +uno::Reference ScTableRowObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTR(xCRR->getRows(), uno::UNO_SET_THROW); + + uno::Reference xIA_TR(xTR, uno::UNO_QUERY_THROW); + uno::Reference xReturn(xIA_TR->getByIndex(6), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScTableRowObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableRowObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..419a326f4 --- /dev/null +++ b/sc/qa/extras/sctablerowsobj.cxx @@ -0,0 +1,136 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTableRowsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo, + public apitest::XTableRows +{ +public: + ScTableRowsObj(); + + virtual uno::Reference init() override; + virtual uno::Reference getXCellRange() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScTableRowsObj::ScTableRowsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(ScSheetLimits::CreateDefault().GetMaxRowCount()) + , XServiceInfo("ScTableRowsObj", "com.sun.star.table.TableRows") +{ +} + +uno::Reference ScTableRowsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xSheets->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xTR(xCRR->getRows(), uno::UNO_SET_THROW); + + return xTR; +} + +uno::Reference ScTableRowsObj::getXCellRange() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xSheets->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference xCR(xSheet0, uno::UNO_QUERY_THROW); + return xCR; +} + +void ScTableRowsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableRowsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..055de3bab --- /dev/null +++ b/sc/qa/extras/sctablesheetobj.cxx @@ -0,0 +1,375 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ + +class ScTableSheetObj : public CalcUnoApiTest, 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 void tearDown() 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; + uno::Reference< lang::XComponent > mxComponent; +}; + +ScTableSheetObj::ScTableSheetObj(): + CalcUnoApiTest("/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 xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference 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 aCellRangeAddr { { 0, 0, 0, 10, 10 } }; + + uno::Reference 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 ScTableSheetObj::getXSpreadsheetDocument() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + return xDoc; +} + +uno::Reference ScTableSheetObj::getScenarioSpreadsheet() +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference 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 aCellRangeAddr { { 0, 0, 0, 10, 10 } }; + + uno::Reference xScence(xSheet, UNO_QUERY_THROW); + xScence->getScenarios()->addNewByName("Scenario", aCellRangeAddr, "Comment"); + uno::Reference 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 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 aCellRangeAddr { {0, 0, 0, 10, 10} }; + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + createFileURL(u"ScTableSheetObj.ods", maFileURL); + mxComponent = loadFromDesktop(maFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScTableSheetObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..de30ec26b --- /dev/null +++ b/sc/qa/extras/sctablesheetsobj.cxx @@ -0,0 +1,172 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTableSheetsObj : public CalcUnoApiTest, + 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 void tearDown() override; + virtual uno::Reference 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 getComponent() override; + virtual void createFileURL(const OUString& rFileBase, OUString& rFileURL) override; + virtual uno::Reference loadFromDesktop(const OUString& rString) override; + +protected: + uno::Reference mxComponent; +}; + +ScTableSheetsObj::ScTableSheetsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , ::apitest::XElementAccess(cppu::UnoType::get()) + , ::apitest::XIndexAccess(3) + , ::apitest::XNameAccess("Sheet1") + , ::apitest::XNameContainer("Sheet2") + , ::apitest::XNameReplace("Sheet2") + , ::apitest::XServiceInfo("ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets") +{ +} + +uno::Reference ScTableSheetsObj::getComponent() { return mxComponent; } + +void ScTableSheetsObj::createFileURL(const OUString& rFileBase, OUString& rFileURL) +{ + CalcUnoApiTest::createFileURL(rFileBase, rFileURL); +} + +uno::Reference ScTableSheetsObj::loadFromDesktop(const OUString& rString) +{ + return CalcUnoApiTest::loadFromDesktop(rString); +} + +uno::Reference ScTableSheetsObj::init() +{ + xDocument.set(mxComponent, UNO_QUERY_THROW); + uno::Reference xReturn(xDocument->getSheets(), UNO_QUERY_THROW); + + uno::Reference 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() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL("rangenamessrc.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScTableSheetsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..852738c22 --- /dev/null +++ b/sc/qa/extras/sctablevalidationobj.cxx @@ -0,0 +1,124 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableValidationObj : public CalcUnoApiTest, + public apitest::TableValidation, + public apitest::XMultiFormulaTokens, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XSheetCondition +{ +public: + ScTableValidationObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScTableValidationObj::ScTableValidationObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "Type", "ErrorAlertStyle" }) + , XServiceInfo("ScTableValidationObj", "com.sun.star.sheet.TableValidation") +{ +} + +uno::Reference ScTableValidationObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference 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 xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference xSheetCondition; + CPPUNIT_ASSERT(xPropSet->getPropertyValue("Validation") >>= xSheetCondition); + + return xSheetCondition; +} + +void ScTableValidationObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableValidationObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..9fb100388 --- /dev/null +++ b/sc/qa/extras/sctabviewobj.cxx @@ -0,0 +1,143 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTabViewObj : public CalcUnoApiTest, + 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 init() override; + virtual uno::Reference getXSpreadsheet(const sal_Int16 nNumber = 0) override; + + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScTabViewObj::ScTabViewObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) +{ +} + +uno::Reference ScTabViewObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xModel(xDoc, uno::UNO_QUERY_THROW); + + setCellRange(table::CellRangeAddress(0, 0, 0, 6, 23)); + + return xModel->getCurrentController(); +} + +uno::Reference ScTabViewObj::getXSpreadsheet(const sal_Int16 nNumber) +{ + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); + xSheets->insertNewByName("Sheet2", 2); + uno::Reference xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(nNumber), UNO_QUERY_THROW); + + return xSheet; +} + +void ScTabViewObj::setUp() +{ + CalcUnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTabViewObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..e92ca14ff --- /dev/null +++ b/sc/qa/extras/scuniquecellformatsenumeration.cxx @@ -0,0 +1,134 @@ +/* -*- 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +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 CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScUniqueCellFormatsEnumeration(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScUniqueCellFormatsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xComponent; + void changeColor(const uno::Reference& xSheet, const OUString& sRangeName, + const RGBColor& rgb); +}; + +ScUniqueCellFormatsEnumeration::ScUniqueCellFormatsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference ScUniqueCellFormatsEnumeration::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference 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 xUCFRS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference xEA(xUCFRS->getUniqueCellFormatRanges(), + uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScUniqueCellFormatsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScUniqueCellFormatsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +void ScUniqueCellFormatsEnumeration::changeColor(const uno::Reference& xSheet, + const OUString& sRangeName, const RGBColor& rgb) +{ + uno::Reference xCellRange(xSheet->getCellRangeByName(sRangeName), + uno::UNO_SET_THROW); + uno::Reference 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 000000000..e3050200e --- /dev/null +++ b/sc/qa/extras/scuniquecellformatsobj.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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScUniqueCellFormatsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScUniqueCellFormatsObj(); + + virtual uno::Reference init() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference m_xComponent; +}; + +ScUniqueCellFormatsObj::ScUniqueCellFormatsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType::get()) + , XIndexAccess(1) +{ +} + +uno::Reference ScUniqueCellFormatsObj::init() +{ + uno::Reference xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xUCFRS(xSheet0, uno::UNO_QUERY_THROW); + return xUCFRS->getUniqueCellFormatRanges(); +} + +void ScUniqueCellFormatsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScUniqueCellFormatsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +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 000000000..1956f4d56 --- /dev/null +++ b/sc/qa/extras/scviewpaneobj.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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace sc_apitest +{ +class ScViewPaneObj : public CalcUnoApiTest, + public apitest::XCellRangeReferrer, + public apitest::XControlAccess, + public apitest::XFormLayerAccess, + public apitest::XServiceInfo, + public apitest::XViewPane +{ +public: + ScViewPaneObj(); + + virtual uno::Reference init() override; + virtual uno::Reference getXComponent() override; + virtual void setUp() override; + virtual void tearDown() 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(); + +private: + uno::Reference mxComponent; +}; + +ScViewPaneObj::ScViewPaneObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScViewPaneObj", "com.sun.star.sheet.SpreadsheetViewPane") +{ +} + +uno::Reference ScViewPaneObj::getXComponent() { return mxComponent; } + +uno::Reference ScViewPaneObj::init() +{ + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference xModel(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xController(xModel->getCurrentController(), + uno::UNO_SET_THROW); + uno::Reference xIA(xController, uno::UNO_QUERY_THROW); + uno::Reference xViewPane(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + xDP->insertNewByIndex(1); + xDP->insertNewByIndex(2); + + uno::Reference xDrawPage(xDP->getByIndex(0), uno::UNO_QUERY_THROW); + xDrawPage->add( + apitest::helper::form::createCommandButton(mxComponent, 15000, 10000, 3000, 4500)); + + uno::Reference xFS(xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference xNC(xFS->getForms(), uno::UNO_SET_THROW); + + // XFormLayerAccess + uno::Reference xForm(xNC->getByName("Form"), uno::UNO_QUERY_THROW); + setForm(xForm); + // XCellRangeReferrer + setCellRange(xViewPane->getVisibleRange()); + + return xViewPane; +} + +void ScViewPaneObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScViewPaneObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +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 new file mode 100644 index 000000000..1a8e5e5e9 Binary files /dev/null and b/sc/qa/extras/testdocuments/AutoFilter.xls differ diff --git a/sc/qa/extras/testdocuments/BaseForHTMLExport.ods b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods new file mode 100644 index 000000000..025b1e480 Binary files /dev/null and b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods differ diff --git a/sc/qa/extras/testdocuments/CalcFont.xls b/sc/qa/extras/testdocuments/CalcFont.xls new file mode 100644 index 000000000..86304063c Binary files /dev/null and b/sc/qa/extras/testdocuments/CalcFont.xls differ diff --git a/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls b/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls new file mode 100644 index 000000000..14cf152af Binary files /dev/null and b/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls differ diff --git a/sc/qa/extras/testdocuments/ForEachInSelection.ods b/sc/qa/extras/testdocuments/ForEachInSelection.ods new file mode 100644 index 000000000..7996c86eb Binary files /dev/null and b/sc/qa/extras/testdocuments/ForEachInSelection.ods differ diff --git a/sc/qa/extras/testdocuments/GeneratedEventTest.xls b/sc/qa/extras/testdocuments/GeneratedEventTest.xls new file mode 100644 index 000000000..9325de32d Binary files /dev/null and b/sc/qa/extras/testdocuments/GeneratedEventTest.xls differ diff --git a/sc/qa/extras/testdocuments/KeyShortcut.xlsm b/sc/qa/extras/testdocuments/KeyShortcut.xlsm new file mode 100644 index 000000000..d684d2a48 Binary files /dev/null and b/sc/qa/extras/testdocuments/KeyShortcut.xlsm differ diff --git a/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods b/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods new file mode 100644 index 000000000..35e2b985b Binary files /dev/null and b/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods differ diff --git a/sc/qa/extras/testdocuments/MiscControlTests.xls b/sc/qa/extras/testdocuments/MiscControlTests.xls new file mode 100644 index 000000000..3503795b0 Binary files /dev/null and b/sc/qa/extras/testdocuments/MiscControlTests.xls differ diff --git a/sc/qa/extras/testdocuments/MiscRangeTests.xls b/sc/qa/extras/testdocuments/MiscRangeTests.xls new file mode 100644 index 000000000..c6dffd475 Binary files /dev/null and b/sc/qa/extras/testdocuments/MiscRangeTests.xls differ diff --git a/sc/qa/extras/testdocuments/MultiDocumentCopyPaste.xlsm b/sc/qa/extras/testdocuments/MultiDocumentCopyPaste.xlsm new file mode 100644 index 000000000..4f24cf4e6 Binary files /dev/null and b/sc/qa/extras/testdocuments/MultiDocumentCopyPaste.xlsm differ diff --git a/sc/qa/extras/testdocuments/Names.xls b/sc/qa/extras/testdocuments/Names.xls new file mode 100644 index 000000000..fcacf9bbd Binary files /dev/null and b/sc/qa/extras/testdocuments/Names.xls differ diff --git a/sc/qa/extras/testdocuments/NamesSheetLocal.xls b/sc/qa/extras/testdocuments/NamesSheetLocal.xls new file mode 100644 index 000000000..9086d62a1 Binary files /dev/null and b/sc/qa/extras/testdocuments/NamesSheetLocal.xls differ diff --git a/sc/qa/extras/testdocuments/PageBreaks.xls b/sc/qa/extras/testdocuments/PageBreaks.xls new file mode 100644 index 000000000..4e6ac0a42 Binary files /dev/null and b/sc/qa/extras/testdocuments/PageBreaks.xls differ diff --git a/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods new file mode 100644 index 000000000..5d7b1a4c2 Binary files /dev/null and b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods differ diff --git a/sc/qa/extras/testdocuments/Ranges-2.xls b/sc/qa/extras/testdocuments/Ranges-2.xls new file mode 100644 index 000000000..84fdc45c0 Binary files /dev/null and b/sc/qa/extras/testdocuments/Ranges-2.xls differ diff --git a/sc/qa/extras/testdocuments/Ranges-3.xls b/sc/qa/extras/testdocuments/Ranges-3.xls new file mode 100644 index 000000000..f96620f21 Binary files /dev/null and b/sc/qa/extras/testdocuments/Ranges-3.xls differ diff --git a/sc/qa/extras/testdocuments/Ranges.xls b/sc/qa/extras/testdocuments/Ranges.xls new file mode 100644 index 000000000..7a513de25 Binary files /dev/null and b/sc/qa/extras/testdocuments/Ranges.xls differ diff --git a/sc/qa/extras/testdocuments/RecordChangesProtected.ods b/sc/qa/extras/testdocuments/RecordChangesProtected.ods new file mode 100644 index 000000000..fac012d84 Binary files /dev/null and b/sc/qa/extras/testdocuments/RecordChangesProtected.ods differ diff --git a/sc/qa/extras/testdocuments/ScAnnotationObj.ods b/sc/qa/extras/testdocuments/ScAnnotationObj.ods new file mode 100644 index 000000000..bed0680b9 Binary files /dev/null and b/sc/qa/extras/testdocuments/ScAnnotationObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScCellCursorObj.ods b/sc/qa/extras/testdocuments/ScCellCursorObj.ods new file mode 100644 index 000000000..46d8090ec Binary files /dev/null and b/sc/qa/extras/testdocuments/ScCellCursorObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods b/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods new file mode 100644 index 000000000..e160f5edd Binary files /dev/null and b/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods b/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods new file mode 100644 index 000000000..48f001ccd Binary files /dev/null and b/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScModelObj.ods b/sc/qa/extras/testdocuments/ScModelObj.ods new file mode 100644 index 000000000..56a25329c Binary files /dev/null and b/sc/qa/extras/testdocuments/ScModelObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScNamedRangeObj.ods b/sc/qa/extras/testdocuments/ScNamedRangeObj.ods new file mode 100644 index 000000000..6bd563623 Binary files /dev/null and b/sc/qa/extras/testdocuments/ScNamedRangeObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScOutlineObj.ods b/sc/qa/extras/testdocuments/ScOutlineObj.ods new file mode 100644 index 000000000..bc4642a33 Binary files /dev/null and b/sc/qa/extras/testdocuments/ScOutlineObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScSheetLinkObj.ods b/sc/qa/extras/testdocuments/ScSheetLinkObj.ods new file mode 100644 index 000000000..7f09e0d97 Binary files /dev/null and b/sc/qa/extras/testdocuments/ScSheetLinkObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods b/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods new file mode 100644 index 000000000..0cc718c98 Binary files /dev/null and b/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods differ diff --git a/sc/qa/extras/testdocuments/ScTableSheetObj.ods b/sc/qa/extras/testdocuments/ScTableSheetObj.ods new file mode 100644 index 000000000..a18b1e7d5 Binary files /dev/null and b/sc/qa/extras/testdocuments/ScTableSheetObj.ods differ diff --git a/sc/qa/extras/testdocuments/Shapes.xls b/sc/qa/extras/testdocuments/Shapes.xls new file mode 100644 index 000000000..dbccf3da3 Binary files /dev/null and b/sc/qa/extras/testdocuments/Shapes.xls differ diff --git a/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm new file mode 100644 index 000000000..684480c3f Binary files /dev/null and b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm differ diff --git a/sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm b/sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm new file mode 100644 index 000000000..6c71c75b3 Binary files /dev/null and b/sc/qa/extras/testdocuments/SimpleCopyPaste.xlsm differ diff --git a/sc/qa/extras/testdocuments/StarBasic.ods b/sc/qa/extras/testdocuments/StarBasic.ods new file mode 100644 index 000000000..6b94f0684 Binary files /dev/null and b/sc/qa/extras/testdocuments/StarBasic.ods differ diff --git a/sc/qa/extras/testdocuments/TestAddress.xls b/sc/qa/extras/testdocuments/TestAddress.xls new file mode 100644 index 000000000..629645c41 Binary files /dev/null and b/sc/qa/extras/testdocuments/TestAddress.xls differ diff --git a/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls b/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls new file mode 100644 index 000000000..9c00f5522 Binary files /dev/null and b/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls differ diff --git a/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls b/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls new file mode 100644 index 000000000..409459df6 Binary files /dev/null and b/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls differ diff --git a/sc/qa/extras/testdocuments/TestIntersection.xls b/sc/qa/extras/testdocuments/TestIntersection.xls new file mode 100644 index 000000000..5872be7ca Binary files /dev/null and b/sc/qa/extras/testdocuments/TestIntersection.xls differ diff --git a/sc/qa/extras/testdocuments/TestUnion.xls b/sc/qa/extras/testdocuments/TestUnion.xls new file mode 100644 index 000000000..bde207e74 Binary files /dev/null and b/sc/qa/extras/testdocuments/TestUnion.xls differ diff --git a/sc/qa/extras/testdocuments/VariousTestMacros.xlsm b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm new file mode 100644 index 000000000..455dad654 Binary files /dev/null and b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm differ diff --git a/sc/qa/extras/testdocuments/Window.xls b/sc/qa/extras/testdocuments/Window.xls new file mode 100644 index 000000000..3daebfb99 Binary files /dev/null and b/sc/qa/extras/testdocuments/Window.xls differ diff --git a/sc/qa/extras/testdocuments/Workbooks.xls b/sc/qa/extras/testdocuments/Workbooks.xls new file mode 100644 index 000000000..2e8a7e78b Binary files /dev/null and b/sc/qa/extras/testdocuments/Workbooks.xls differ diff --git a/sc/qa/extras/testdocuments/bytearraystring.xls b/sc/qa/extras/testdocuments/bytearraystring.xls new file mode 100644 index 000000000..22da6de48 Binary files /dev/null and b/sc/qa/extras/testdocuments/bytearraystring.xls differ diff --git a/sc/qa/extras/testdocuments/cond_format_merge.ods b/sc/qa/extras/testdocuments/cond_format_merge.ods new file mode 100644 index 000000000..43b676d22 Binary files /dev/null and b/sc/qa/extras/testdocuments/cond_format_merge.ods differ diff --git a/sc/qa/extras/testdocuments/forcepoint97.xlsx b/sc/qa/extras/testdocuments/forcepoint97.xlsx new file mode 100644 index 000000000..152fbbc45 Binary files /dev/null and b/sc/qa/extras/testdocuments/forcepoint97.xlsx differ diff --git a/sc/qa/extras/testdocuments/macro-button-form-control.xlsm b/sc/qa/extras/testdocuments/macro-button-form-control.xlsm new file mode 100644 index 000000000..e4e76b13f Binary files /dev/null and b/sc/qa/extras/testdocuments/macro-button-form-control.xlsm differ diff --git a/sc/qa/extras/testdocuments/new_cond_format_api.ods b/sc/qa/extras/testdocuments/new_cond_format_api.ods new file mode 100644 index 000000000..06bb1d759 Binary files /dev/null and b/sc/qa/extras/testdocuments/new_cond_format_api.ods differ diff --git a/sc/qa/extras/testdocuments/pagesetup.xls b/sc/qa/extras/testdocuments/pagesetup.xls new file mode 100644 index 000000000..db1033af7 Binary files /dev/null and b/sc/qa/extras/testdocuments/pagesetup.xls differ diff --git a/sc/qa/extras/testdocuments/range-4.xls b/sc/qa/extras/testdocuments/range-4.xls new file mode 100644 index 000000000..67d1ad7aa Binary files /dev/null and b/sc/qa/extras/testdocuments/range-4.xls differ diff --git a/sc/qa/extras/testdocuments/rangenamessrc.ods b/sc/qa/extras/testdocuments/rangenamessrc.ods new file mode 100644 index 000000000..d22702bda Binary files /dev/null and b/sc/qa/extras/testdocuments/rangenamessrc.ods differ diff --git a/sc/qa/extras/testdocuments/scarealinkobj.ods b/sc/qa/extras/testdocuments/scarealinkobj.ods new file mode 100644 index 000000000..7f09e0d97 Binary files /dev/null and b/sc/qa/extras/testdocuments/scarealinkobj.ods differ diff --git a/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods b/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods new file mode 100644 index 000000000..8ba12e638 Binary files /dev/null and b/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods differ diff --git a/sc/qa/extras/testdocuments/tdf104902.ods b/sc/qa/extras/testdocuments/tdf104902.ods new file mode 100644 index 000000000..8524522fd Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf104902.ods differ diff --git a/sc/qa/extras/testdocuments/tdf105558.ods b/sc/qa/extras/testdocuments/tdf105558.ods new file mode 100644 index 000000000..0ea77ee66 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf105558.ods differ diff --git a/sc/qa/extras/testdocuments/tdf107885.xlsm b/sc/qa/extras/testdocuments/tdf107885.xlsm new file mode 100644 index 000000000..f16d8b1b3 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf107885.xlsm differ diff --git a/sc/qa/extras/testdocuments/tdf107902.xlsm b/sc/qa/extras/testdocuments/tdf107902.xlsm new file mode 100644 index 000000000..f5333959b Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf107902.xlsm differ diff --git a/sc/qa/extras/testdocuments/tdf114427.ods b/sc/qa/extras/testdocuments/tdf114427.ods new file mode 100644 index 000000000..656398661 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf114427.ods differ diff --git a/sc/qa/extras/testdocuments/tdf120161.ods b/sc/qa/extras/testdocuments/tdf120161.ods new file mode 100644 index 000000000..4b2c6e3ce Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf120161.ods differ diff --git a/sc/qa/extras/testdocuments/tdf125800.ods b/sc/qa/extras/testdocuments/tdf125800.ods new file mode 100644 index 000000000..91f000d74 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf125800.ods differ diff --git a/sc/qa/extras/testdocuments/tdf128218.ods b/sc/qa/extras/testdocuments/tdf128218.ods new file mode 100644 index 000000000..9fa3e8b4e Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf128218.ods differ diff --git a/sc/qa/extras/testdocuments/tdf130307.ods b/sc/qa/extras/testdocuments/tdf130307.ods new file mode 100644 index 000000000..fc354cf2c Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf130307.ods differ diff --git a/sc/qa/extras/testdocuments/tdf131296_legacy.ods b/sc/qa/extras/testdocuments/tdf131296_legacy.ods new file mode 100644 index 000000000..43ebdeb24 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf131296_legacy.ods differ diff --git a/sc/qa/extras/testdocuments/tdf131296_new.ods b/sc/qa/extras/testdocuments/tdf131296_new.ods new file mode 100644 index 000000000..9c0161c40 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf131296_new.ods differ diff --git a/sc/qa/extras/testdocuments/tdf131562.xlsm b/sc/qa/extras/testdocuments/tdf131562.xlsm new file mode 100644 index 000000000..e56576ba4 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf131562.xlsm differ diff --git a/sc/qa/extras/testdocuments/tdf133887.ods b/sc/qa/extras/testdocuments/tdf133887.ods new file mode 100644 index 000000000..92d135f58 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf133887.ods differ diff --git a/sc/qa/extras/testdocuments/tdf133889.ods b/sc/qa/extras/testdocuments/tdf133889.ods new file mode 100644 index 000000000..db87da612 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf133889.ods differ diff --git a/sc/qa/extras/testdocuments/tdf138646.ods b/sc/qa/extras/testdocuments/tdf138646.ods new file mode 100644 index 000000000..9faa95a54 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf138646.ods differ diff --git a/sc/qa/extras/testdocuments/tdf142033.ods b/sc/qa/extras/testdocuments/tdf142033.ods new file mode 100644 index 000000000..da49b7323 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf142033.ods differ diff --git a/sc/qa/extras/testdocuments/tdf143582.ods b/sc/qa/extras/testdocuments/tdf143582.ods new file mode 100644 index 000000000..1375bf5b9 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf143582.ods differ diff --git a/sc/qa/extras/testdocuments/tdf143978.ods b/sc/qa/extras/testdocuments/tdf143978.ods new file mode 100644 index 000000000..25a79defc Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf143978.ods differ diff --git a/sc/qa/extras/testdocuments/tdf144085.ods b/sc/qa/extras/testdocuments/tdf144085.ods new file mode 100644 index 000000000..249369576 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf144085.ods differ diff --git a/sc/qa/extras/testdocuments/tdf144970.ods b/sc/qa/extras/testdocuments/tdf144970.ods new file mode 100644 index 000000000..860521a52 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf144970.ods differ diff --git a/sc/qa/extras/testdocuments/tdf146742.ods b/sc/qa/extras/testdocuments/tdf146742.ods new file mode 100644 index 000000000..18ede8a04 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf146742.ods differ diff --git a/sc/qa/extras/testdocuments/tdf43003.ods b/sc/qa/extras/testdocuments/tdf43003.ods new file mode 100644 index 000000000..3c40deefa Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf43003.ods differ diff --git a/sc/qa/extras/testdocuments/tdf46119.ods b/sc/qa/extras/testdocuments/tdf46119.ods new file mode 100644 index 000000000..953f75d64 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf46119.ods differ diff --git a/sc/qa/extras/testdocuments/tdf57113.ods b/sc/qa/extras/testdocuments/tdf57113.ods new file mode 100644 index 000000000..9768e0de0 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf57113.ods differ diff --git a/sc/qa/extras/testdocuments/tdf64639.ods b/sc/qa/extras/testdocuments/tdf64639.ods new file mode 100644 index 000000000..0b2e708d7 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf64639.ods differ diff --git a/sc/qa/extras/testdocuments/tdf64703_hiddenPageBreak.ods b/sc/qa/extras/testdocuments/tdf64703_hiddenPageBreak.ods new file mode 100644 index 000000000..87f110915 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf64703_hiddenPageBreak.ods differ diff --git a/sc/qa/extras/testdocuments/tdf75263.xlsm b/sc/qa/extras/testdocuments/tdf75263.xlsm new file mode 100644 index 000000000..5a09ed677 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf75263.xlsm differ diff --git a/sc/qa/extras/testdocuments/tdf78897.xls b/sc/qa/extras/testdocuments/tdf78897.xls new file mode 100644 index 000000000..e2177fc78 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf78897.xls differ diff --git a/sc/qa/extras/testdocuments/tdf84012.ods b/sc/qa/extras/testdocuments/tdf84012.ods new file mode 100644 index 000000000..c2f30e0f4 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf84012.ods differ diff --git a/sc/qa/extras/testdocuments/tdf90278.xls b/sc/qa/extras/testdocuments/tdf90278.xls new file mode 100644 index 000000000..2d7945556 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf90278.xls differ diff --git a/sc/qa/extras/testdocuments/testTypePassword.ods b/sc/qa/extras/testdocuments/testTypePassword.ods new file mode 100644 index 000000000..d75c17ace Binary files /dev/null and b/sc/qa/extras/testdocuments/testTypePassword.ods differ diff --git a/sc/qa/extras/testdocuments/vba.xls b/sc/qa/extras/testdocuments/vba.xls new file mode 100644 index 000000000..399b1ec20 Binary files /dev/null and b/sc/qa/extras/testdocuments/vba.xls differ diff --git a/sc/qa/extras/testdocuments/vba_endFunction.xls b/sc/qa/extras/testdocuments/vba_endFunction.xls new file mode 100644 index 000000000..af7fa8625 Binary files /dev/null and b/sc/qa/extras/testdocuments/vba_endFunction.xls differ diff --git a/sc/qa/extras/testdocuments/vba_findFunction.xls b/sc/qa/extras/testdocuments/vba_findFunction.xls new file mode 100644 index 000000000..bb0f450b1 Binary files /dev/null and b/sc/qa/extras/testdocuments/vba_findFunction.xls differ diff --git a/sc/qa/extras/testdocuments/window2.xls b/sc/qa/extras/testdocuments/window2.xls new file mode 100644 index 000000000..d1822fa36 Binary files /dev/null and b/sc/qa/extras/testdocuments/window2.xls differ diff --git a/sc/qa/extras/testdocuments/xcellrangesquery.ods b/sc/qa/extras/testdocuments/xcellrangesquery.ods new file mode 100644 index 000000000..494d79d36 Binary files /dev/null and b/sc/qa/extras/testdocuments/xcellrangesquery.ods differ diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx new file mode 100644 index 000000000..15dfe9c87 --- /dev/null +++ b/sc/qa/extras/vba-macro-test.cxx @@ -0,0 +1,806 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace css; + +class VBAMacroTest : public UnoApiTest +{ +public: + VBAMacroTest() + : UnoApiTest("/sc/qa/extras/testdocuments") + { + } + + virtual void tearDown() override; + + void testSimpleCopyAndPaste(); + void testMultiDocumentCopyAndPaste(); + void testSheetAndColumnSelectAndHide(); + void testPrintArea(); + void testSelectAllChaged(); + void testRangeSelect(); + void testWindowState(); + void testScroll(); + void testMacroKeyBinding(); + + void testVba(); + void testTdf107885(); + void testTdf131562(); + void testTdf107902(); + void testTdf90278(); + void testForEachInSelection(); + + CPPUNIT_TEST_SUITE(VBAMacroTest); + CPPUNIT_TEST(testSimpleCopyAndPaste); + CPPUNIT_TEST(testMultiDocumentCopyAndPaste); + CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testPrintArea); + CPPUNIT_TEST(testSelectAllChaged); + CPPUNIT_TEST(testRangeSelect); + CPPUNIT_TEST(testWindowState); + CPPUNIT_TEST(testScroll); + CPPUNIT_TEST(testMacroKeyBinding); + + CPPUNIT_TEST(testVba); + CPPUNIT_TEST(testTdf107885); + CPPUNIT_TEST(testTdf131562); + CPPUNIT_TEST(testTdf107902); + CPPUNIT_TEST(testTdf90278); + CPPUNIT_TEST(testForEachInSelection); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference mxComponent; +}; + +void VBAMacroTest::tearDown() +{ + closeDocument(mxComponent); + UnoApiTest::tearDown(); +} + +void VBAMacroTest::testSimpleCopyAndPaste() +{ + // Copy-paste values in the same sheet + + // Range(Cells(4, 3), Cells(6, 3)).Copy + // Cells(4, 2).Activate + // ActiveCell.PasteSpecial xlValues + + OUString aFileName; + createFileURL(u"SimpleCopyPaste.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(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))); + + SfxObjectShell::CallXScript( + mxComponent, "vnd.sun.Star.script:VBAProject.Module1.test?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // 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))); + + pDocSh->DoClose(); +} + +void 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 + // ... + + OUString aFileName; + createFileURL(u"MultiDocumentCopyPaste.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(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))); + + SfxObjectShell::CallXScript( + mxComponent, "vnd.sun.Star.script:VBAProject.Module1.test?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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))); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testSheetAndColumnSelectAndHide() +{ + OUString aFileName; + createFileURL(u"SheetAndColumnSelectAndHide.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(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)); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testHide?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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()); + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testUnhide?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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()); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testPrintArea() +{ + // Sets the print area to A1:B5 + // ActiveSheet.PageSetup.PrintArea = "$A$1:$B$5" + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xPrintAreas(xSheet, uno::UNO_QUERY_THROW); + + { + const uno::Sequence aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(false, aSequence.hasElements()); + } + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testPrintArea?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + { + const uno::Sequence aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(true, aSequence.hasElements()); + } + + css::uno::Reference xCloseable(mxComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void VBAMacroTest::testSelectAllChaged() +{ + // Columns("A:A").Select + // Range(Selection, Selection.End(xlToRight)).Select + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + CPPUNIT_ASSERT_EQUAL(ScRange(), pViewData.GetMarkData().GetMarkArea()); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testSelectAll?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // A1:E1048576 + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 4, MAXROW, 0), pViewData.GetMarkData().GetMarkArea()); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testRangeSelect() +{ + // Range("B2").Select + // Range(Selection, Selection.End(xlToRight)).Select + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + CPPUNIT_ASSERT_EQUAL(ScRange(), pViewData.GetMarkData().GetMarkArea()); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testRangeSelect?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // B2:E5 + CPPUNIT_ASSERT_EQUAL(ScRange(1, 1, 0, 4, 1, 0), pViewData.GetMarkData().GetMarkArea()); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testWindowState() +{ + // Application.WindowState = xlMinimized + // Application.WindowState = xlMaximized + // Application.WindowState = xlNormal + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testWindowState?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + css::uno::Reference xCloseable(mxComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void VBAMacroTest::testScroll() +{ + // ActiveWindow.ScrollColumn = 30 + // ActiveWindow.ScrollRow = 100 + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast(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)); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testScroll?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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)); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testMacroKeyBinding() +{ + // key_U() -> CTRL+U + // key_T() -> CTRL+T + + OUString aFileName; + createFileURL(u"KeyShortcut.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel.is()); + + uno::Reference xConfigSupplier(xModel, uno::UNO_QUERY); + CPPUNIT_ASSERT(xConfigSupplier.is()); + uno::Reference xConfigManager + = xConfigSupplier->getUIConfigurationManager(); + uno::Reference 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)); + + css::uno::Reference xCloseable(mxComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void VBAMacroTest::testVba() +{ + TestMacroInfo testInfo[] = { + { OUString("TestAddress."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { + OUString("vba."), + OUString( + "vnd.sun.Star.script:VBAProject.Modul1.Modul1?language=Basic&location=document"), + }, + { OUString("MiscRangeTests."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("bytearraystring."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacro.test?language=Basic&location=document") }, + { OUString("AutoFilter."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("CalcFont."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestIntersection."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestUnion."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("range-4."), + 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."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, +#endif + { OUString("TestCalc_Rangetest."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestCalc_Rangetest2."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Ranges-2."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("pagesetup."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Window."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("window2."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("PageBreaks."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Shapes."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Ranges."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("CheckOptionToggleValue."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("GeneratedEventTest."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("MiscControlTests."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Workbooks."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Names."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("NamesSheetLocal."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("vba_endFunction."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("vba_findFunction."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.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 aParams; + for (const auto& rTestInfo : testInfo) + { + OUString aFileName; + createFileURL(OUStringConcatenation(rTestInfo.sFileBaseName + "xls"), aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + // 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(); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + bool bWorkbooksHandling = rTestInfo.sFileBaseName == "Workbooks." && !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); + + SfxObjectShell::CallXScript(mxComponent, rTestInfo.sMacroUrl, aParams, aRet, aOutParamIndex, + aOutParam); + OUString aStringRes; + aRet >>= aStringRes; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + OUString("script reported failure in file " + rTestInfo.sFileBaseName + "xls") + .toUtf8() + .getStr(), + OUString("OK"), aStringRes); + + css::uno::Reference xCloseable(mxComponent, + css::uno::UNO_QUERY_THROW); + xCloseable->close(true); + + if (bWorkbooksHandling) + { + OUString sFileUrl; + OUString sFilePath = sTempDir + sTestFileName; + osl::FileBase::getFileURLFromSystemPath(sFilePath, sFileUrl); + if (!sFileUrl.isEmpty()) + osl::File::remove(sFileUrl); + } + } +} + +void VBAMacroTest::testTdf107885() +{ + OUString aFileName; + createFileURL(u"tdf107885.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(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 + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.Module1.AFString?language=Basic&location=document", aParams, + aRet, aOutParamIndex, aOutParam); + + //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 + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.Module1.AFNumeric?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT(rDoc.RowHidden(1, 0)); + CPPUNIT_ASSERT(rDoc.RowHidden(2, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(4, 0)); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testTdf131562() +{ + OUString aFileName; + createFileURL(u"tdf131562.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(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))); + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.Munka1.numberconcat?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + //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))); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testTdf107902() +{ + OUString aFileName; + createFileURL(u"tdf107902.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + //Without the fix in place, it would have failed with 'Unexpected dialog: Error: BASIC runtime error.' + SfxObjectShell::CallXScript( + mxComponent, "vnd.sun.Star.script:VBAProject.Module1.AF?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + //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)); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testTdf90278() +{ + OUString aFileName; + createFileURL(u"tdf90278.xls", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + // Without the fix in place, changing the border weight + // would cause a Basic exception/error in the following script. + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.Module1.BorderWeight?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // Check the border weight of the corresponding cell in the test document + sal_Int32 aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReturnValue); + + css::uno::Reference xCloseable(mxComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void VBAMacroTest::testForEachInSelection() +{ + OUString aFileName; + createFileURL(u"ForEachInSelection.ods", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + uno::Any aRet; + uno::Sequence aOutParamIndex; + uno::Sequence aOutParam; + uno::Sequence aParams; + + 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. + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:Standard.Module1.TestForEachInSelection?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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_SUITE_REGISTRATION(VBAMacroTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3