diff options
Diffstat (limited to 'sc/qa/unit/screenshots')
-rw-r--r-- | sc/qa/unit/screenshots/data/screenshots.txt | 165 | ||||
-rw-r--r-- | sc/qa/unit/screenshots/screenshots.cxx | 328 |
2 files changed, 493 insertions, 0 deletions
diff --git a/sc/qa/unit/screenshots/data/screenshots.txt b/sc/qa/unit/screenshots/data/screenshots.txt new file mode 100644 index 000000000..2f795e601 --- /dev/null +++ b/sc/qa/unit/screenshots/data/screenshots.txt @@ -0,0 +1,165 @@ +# -*- 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/. +# + +# This file contains all dialogs that the unit tests in the module +# will work on if it is in script mode. It will read one-by-one, +# try to open it and create a screenshot that will be saved in +# workdir/screenshots using the pattern of the ui-file name. +# +# Syntax: +# - empty lines are allowed +# - lines starting with '#' are treated as comment +# - all other lines should contain a *.ui filename in the same +# notation as in the dialog constructors (see code) + +# +# The 'known' dialogs which have a hard-coded representation +# in registerKnownDialogsByID/createDialogByID +# + +modules/scalc/ui/insertsheet.ui +modules/scalc/ui/deletecells.ui +modules/scalc/ui/pastespecial.ui +modules/scalc/ui/changesourcedialog.ui +modules/scalc/ui/selectdatasource.ui +modules/scalc/ui/selectsource.ui +modules/scalc/ui/deletecontents.ui +modules/scalc/ui/createnamesdialog.ui +modules/scalc/ui/inputstringdialog.ui +modules/scalc/ui/tabcolordialog.ui +modules/scalc/ui/textimportoptions.ui +modules/scalc/ui/dataform.ui +modules/scalc/ui/movecopysheet.ui +modules/scalc/ui/textimportcsv.ui +modules/scalc/ui/formatcellsdialog.ui + +# +# Dialogs without a hard-coded representation. These will +# be visualized using a fallback based on VclBuilder +# + +# currently deactivated, leads to problems and the test to not work +# This is typically a hint that these should be hard-coded in the +# test case since they need some document and model data to work +# +# modules/scalc/ui/headerfootercontent.ui +# modules/scalc/ui/pivottablelayoutdialog.ui +# +# problems under Linux: +# modules/scalc/ui/RowHeightDialog.ui +# modules/scalc/ui/OptimalRowHeightDialog.ui +# modules/scalc/ui/ColWidthDialog.ui +# modules/scalc/ui/OptimalColWidthDialog.ui + +modules/scalc/ui/autoformattable.ui +modules/scalc/ui/sortwarning.ui +modules/scalc/ui/condformatmanager.ui +modules/scalc/ui/pagetemplatedialog.ui +modules/scalc/ui/paratemplatedialog.ui +modules/scalc/ui/databaroptions.ui +modules/scalc/ui/advancedfilterdialog.ui +modules/scalc/ui/datafielddialog.ui +modules/scalc/ui/pivotfielddialog.ui +modules/scalc/ui/datafieldoptionsdialog.ui +modules/scalc/ui/showdetaildialog.ui +modules/scalc/ui/consolidatedialog.ui +modules/scalc/ui/dapiservicedialog.ui +modules/scalc/ui/imoptdialog.ui +modules/scalc/ui/pivotfilterdialog.ui +modules/scalc/ui/groupbynumber.ui +modules/scalc/ui/groupbydate.ui +modules/scalc/ui/sortdialog.ui +modules/scalc/ui/standardfilterdialog.ui +modules/scalc/ui/validationdialog.ui +modules/scalc/ui/subtotaldialog.ui +modules/scalc/ui/scenariodialog.ui +modules/scalc/ui/searchresults.ui +modules/scalc/ui/definename.ui +modules/scalc/ui/insertname.ui +modules/scalc/ui/tpviewpage.ui +modules/scalc/ui/scgeneralpage.ui +modules/scalc/ui/optformula.ui +modules/scalc/ui/formulacalculationoptions.ui +modules/scalc/ui/optdlg.ui +modules/scalc/ui/optcompatibilitypage.ui +modules/scalc/ui/optchangespage.ui +modules/scalc/ui/optdefaultpage.ui +modules/scalc/ui/optsortlists.ui +modules/scalc/ui/optcalculatepage.ui +modules/scalc/ui/movingaveragedialog.ui +modules/scalc/ui/analysisofvariancedialog.ui +modules/scalc/ui/covariancedialog.ui +modules/scalc/ui/correlationdialog.ui +modules/scalc/ui/ttestdialog.ui +modules/scalc/ui/ztestdialog.ui +modules/scalc/ui/chisquaretestdialog.ui +modules/scalc/ui/fourieranalysisdialog.ui +modules/scalc/ui/regressiondialog.ui +modules/scalc/ui/exponentialsmoothingdialog.ui +modules/scalc/ui/descriptivestatisticsdialog.ui +modules/scalc/ui/samplingdialog.ui +modules/scalc/ui/goalseekdlg.ui +modules/scalc/ui/selectrange.ui +modules/scalc/ui/protectsheetdlg.ui +modules/scalc/ui/namerangesdialog.ui +modules/scalc/ui/sharedocumentdlg.ui +modules/scalc/ui/solverdlg.ui +modules/scalc/ui/solveroptionsdialog.ui +modules/scalc/ui/externaldata.ui +modules/scalc/ui/datastreams.ui +modules/scalc/ui/statisticsinfopage.ui +modules/scalc/ui/cellprotectionpage.ui +modules/scalc/ui/printareasdialog.ui +modules/scalc/ui/headerfooterdialog.ui +modules/scalc/ui/conditionalformatdialog.ui +modules/scalc/ui/definedatabaserangedialog.ui +modules/scalc/ui/sortkey.ui +modules/scalc/ui/sortcriteriapage.ui +modules/scalc/ui/sortoptionspage.ui +modules/scalc/ui/subtotalgrppage.ui +modules/scalc/ui/subtotaloptionspage.ui +modules/scalc/ui/validationcriteriapage.ui +modules/scalc/ui/validationhelptabpage.ui +modules/scalc/ui/erroralerttabpage.ui +modules/scalc/ui/conflictsdialog.ui +modules/scalc/ui/colorrowdialog.ui +modules/scalc/ui/filldlg.ui +modules/scalc/ui/ungroupdialog.ui +modules/scalc/ui/groupdialog.ui +modules/scalc/ui/showchangesdialog.ui +modules/scalc/ui/insertcells.ui +modules/scalc/ui/solverprogressdialog.ui +modules/scalc/ui/nosolutiondialog.ui +modules/scalc/ui/solversuccessdialog.ui +modules/scalc/ui/retypepassdialog.ui +modules/scalc/ui/retypepassworddialog.ui +modules/scalc/ui/showsheetdialog.ui +modules/scalc/ui/simplerefdialog.ui +modules/scalc/ui/integerdialog.ui +modules/scalc/ui/doubledialog.ui +modules/scalc/ui/multipleoperationsdialog.ui +modules/scalc/ui/chardialog.ui +modules/scalc/ui/paradialog.ui +modules/scalc/ui/managenamesdialog.ui +modules/scalc/ui/headerdialog.ui +modules/scalc/ui/footerdialog.ui +modules/scalc/ui/leftheaderdialog.ui +modules/scalc/ui/rightheaderdialog.ui +modules/scalc/ui/leftfooterdialog.ui +modules/scalc/ui/rightfooterdialog.ui +modules/scalc/ui/sharedheaderdialog.ui +modules/scalc/ui/sharedfooterdialog.ui +modules/scalc/ui/allheaderfooterdialog.ui +modules/scalc/ui/sheetprintpage.ui +modules/scalc/ui/sidebaralignment.ui +modules/scalc/ui/sidebarcellappearance.ui +modules/scalc/ui/sidebarnumberformat.ui +modules/scalc/ui/randomnumbergenerator.ui +modules/scalc/ui/printeroptions.ui +modules/scalc/ui/xmlsourcedialog.ui diff --git a/sc/qa/unit/screenshots/screenshots.cxx b/sc/qa/unit/screenshots/screenshots.cxx new file mode 100644 index 000000000..632466e82 --- /dev/null +++ b/sc/qa/unit/screenshots/screenshots.cxx @@ -0,0 +1,328 @@ +/* -*- 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 <memory> +#include <test/screenshot_test.hxx> + +#include <sfx2/sfxdlg.hxx> +#include <svx/numinf.hxx> +#include <svx/svxids.hrc> +#include <tools/stream.hxx> + +#include <tabvwsh.hxx> +#include <docsh.hxx> +#include <document.hxx> +#include <scabstdlg.hxx> +#include <scui_def.hxx> +#include <patattr.hxx> + +#include <strings.hrc> +#include <scresid.hxx> +#include <scitems.hxx> + +using namespace css; + +class ScScreenshotTest : public ScreenshotTest +{ +private: + /// members + uno::Reference<lang::XComponent> mxComponent; + SfxObjectShell* mpFoundShell; + ScDocShellRef mxDocSh; + ScTabViewShell* mpViewShell; + ScAbstractDialogFactory* mpFact; + OUString mCsv; // needs to outlive mpStream + std::unique_ptr<SvMemoryStream> mpStream; + std::unique_ptr<SfxItemSet> mpItemSet; + + /// helper + void initialize(); + + /// helper method to populate KnownDialogs, called in setUp(). Needs to be + /// written and has to add entries to KnownDialogs + virtual void registerKnownDialogsByID(mapType& rKnownDialogs) override; + + /// dialog creation for known dialogs by ID. Has to be implemented for + /// each registered known dialog + virtual VclPtr<VclAbstractDialog> createDialogByID(sal_uInt32 nID) override; + +public: + ScScreenshotTest(); + + void testOpeningModalDialogs(); +#if 0 + void testMultiViewCopyPaste(); +#endif + + CPPUNIT_TEST_SUITE(ScScreenshotTest); + CPPUNIT_TEST(testOpeningModalDialogs); +#if 0 + CPPUNIT_TEST(testMultiViewCopyPaste); +#endif + CPPUNIT_TEST_SUITE_END(); +}; + +ScScreenshotTest::ScScreenshotTest() +: mxComponent(), + mpFoundShell(nullptr), + mxDocSh(), + mpViewShell(nullptr), + mpFact(nullptr), + mCsv("some, strings, here, separated, by, commas"), + mpStream(), + mpItemSet() +{ +} + +void ScScreenshotTest::initialize() +{ + if (mxComponent.is()) + mxComponent->dispose(); + // use new, empty doc to avoid file locking + mxComponent = loadFromDesktop("private:factory/scalc", "com.sun.star.sheet.SpreadsheetDocument"); + + mpFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", mpFoundShell); + + mxDocSh = dynamic_cast<ScDocShell*>(mpFoundShell); + CPPUNIT_ASSERT(mxDocSh != nullptr); + + mpViewShell = mxDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(mpViewShell != nullptr); + + mpFact = ScAbstractDialogFactory::Create(); + + SvMemoryStream* pNewMemStream = new SvMemoryStream(const_cast<sal_Unicode *>(mCsv.getStr()), mCsv.getLength() * sizeof(sal_Unicode), StreamMode::READ); + pNewMemStream->SetStreamCharSet( RTL_TEXTENCODING_UNICODE ); +#ifdef OSL_BIGENDIAN + pNewMemStream->SetEndian(SvStreamEndian::BIG); +#else + pNewMemStream->SetEndian(SvStreamEndian::LITTLE); +#endif + mpStream.reset(pNewMemStream); +} + +void ScScreenshotTest::registerKnownDialogsByID(mapType& rKnownDialogs) +{ + // fill map of known dialogs + rKnownDialogs["modules/scalc/ui/insertsheet.ui"] = 0; + rKnownDialogs["modules/scalc/ui/deletecells.ui"] = 1; + rKnownDialogs["modules/scalc/ui/pastespecial.ui"] = 2; + rKnownDialogs["modules/scalc/ui/changesourcedialog.ui"] = 3; + rKnownDialogs["modules/scalc/ui/selectdatasource.ui"] = 4; + rKnownDialogs["modules/scalc/ui/selectsource.ui"] = 5; + rKnownDialogs["modules/scalc/ui/deletecontents.ui"] = 6; + rKnownDialogs["modules/scalc/ui/createnamesdialog.ui"] = 7; + rKnownDialogs["modules/scalc/ui/inputstringdialog.ui"] = 8; + rKnownDialogs["modules/scalc/ui/tabcolordialog.ui"] = 9; + rKnownDialogs["modules/scalc/ui/textimportoptions.ui"] = 10; + rKnownDialogs["modules/scalc/ui/dataform.ui"] = 11; + rKnownDialogs["modules/scalc/ui/movecopysheet.ui"] = 12; + rKnownDialogs["modules/scalc/ui/textimportcsv.ui"] = 13; + rKnownDialogs["modules/scalc/ui/formatcellsdialog.ui"] = 14; +} + +VclPtr<VclAbstractDialog> ScScreenshotTest::createDialogByID(sal_uInt32 nID) +{ + VclPtr<VclAbstractDialog> pReturnDialog; + ////FIXME: translatable string here + const OUString aDefaultSheetName("Sheet1"); + + switch ( nID ) + { + case 0: // "modules/scalc/ui/insertsheet.ui" + { + ScViewData& rViewData = mpViewShell->GetViewData(); + SCTAB nTabSelCount = rViewData.GetMarkData().GetSelectCount(); + + pReturnDialog = mpFact->CreateScInsertTableDlg( + mpViewShell->GetFrameWeld(), rViewData, nTabSelCount, false); + + break; + } + + case 1: // "modules/scalc/ui/deletecells.ui" + { + pReturnDialog = mpFact->CreateScDeleteCellDlg(mpViewShell->GetFrameWeld(), false); + break; + } + + case 2: // "modules/scalc/ui/pastespecial.ui" + { + pReturnDialog = mpFact->CreateScInsertContentsDlg(mpViewShell->GetFrameWeld()); + break; + } + + case 3: // "modules/scalc/ui/changesourcedialog.ui" + { + pReturnDialog = mpFact->CreateScColRowLabelDlg(mpViewShell->GetFrameWeld(), true, false); + break; + } + + case 4: // "modules/scalc/ui/selectdatasource.ui" + { + pReturnDialog = mpFact->CreateScDataPilotDatabaseDlg(mpViewShell->GetFrameWeld()); + break; + } + case 5: // "modules/scalc/ui/selectsource.ui" + { + pReturnDialog = mpFact->CreateScDataPilotSourceTypeDlg(mpViewShell->GetFrameWeld(), true); + break; + } + + case 6: // "modules/scalc/ui/deletecontents.ui" + { + pReturnDialog = mpFact->CreateScDeleteContentsDlg(mpViewShell->GetFrameWeld()); + break; + } + + case 7: // "modules/scalc/ui/createnamesdialog.ui" + { + pReturnDialog = mpFact->CreateScNameCreateDlg( + mpViewShell->GetFrameWeld(), + CreateNameFlags::Left | CreateNameFlags::Top); + // just fake some flags + break; + } + + case 8: // "modules/scalc/ui/inputstringdialog.ui" + { + const OString aEmpty(""); + pReturnDialog = mpFact->CreateScStringInputDlg(mpViewShell->GetFrameWeld(), + ScResId(SCSTR_APDTABLE), ScResId(SCSTR_NAME), + aDefaultSheetName, "modules/scalc/ui/inputstringdialog/InputStringDialog", aEmpty ); + break; + } + + case 9: // "modules/scalc/ui/tabcolordialog.ui" + { + pReturnDialog = mpFact->CreateScTabBgColorDlg(mpViewShell->GetFrameWeld(), + ScResId(SCSTR_SET_TAB_BG_COLOR), + ScResId(SCSTR_NO_TAB_BG_COLOR), Color(0xff00ff) ); + break; + } + + case 10: // "modules/scalc/ui/textimportoptions.ui" + { + pReturnDialog = mpFact->CreateScTextImportOptionsDlg(mpViewShell->GetFrameWeld()); + break; + } + + case 11: // "modules/scalc/ui/dataform.ui" + { + ////FIXME: looks butt-ugly w/ empty file, move it elsewhere, where + ////we actually have some data + pReturnDialog = mpFact->CreateScDataFormDlg(mpViewShell->GetFrameWeld(), mpViewShell); + break; + } + + case 12: // "modules/scalc/ui/movecopysheet.ui" + { + pReturnDialog = mpFact->CreateScMoveTableDlg(mpViewShell->GetFrameWeld(), aDefaultSheetName); + break; + } + + case 13: // "modules/scalc/ui/textimportcsv.ui" + { + pReturnDialog = mpFact->CreateScImportAsciiDlg(mpViewShell->GetFrameWeld(), OUString(), mpStream.get(), SC_PASTETEXT); + break; + } + case 14: // "modules/scalc/ui/formatcellsdialog.ui" + { + ScViewData& rViewData = mpViewShell->GetViewData(); + ScDocument *pDoc = rViewData.GetDocument(); + + const ScPatternAttr *pAttr = mpViewShell->GetSelectionPattern(); + std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem; + + mpItemSet.reset(new SfxItemSet(pAttr->GetItemSet())); + mpItemSet->Put(SfxUInt32Item(ATTR_VALUE_FORMAT, + pAttr->GetNumberFormat( pDoc->GetFormatTable() ) ) ); + + pNumberInfoItem = ScTabViewShell::MakeNumberInfoItem(pDoc, &rViewData); + + mpItemSet->MergeRange(SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO); + mpItemSet->Put(*pNumberInfoItem); + + pReturnDialog = mpFact->CreateScAttrDlg(mpViewShell->GetFrameWeld(), mpItemSet.get()); + break; + } + default: + break; + } + + //CPPUNIT_ASSERT_MESSAGE( "Failed to create dialog", pReturnDialog ); + return pReturnDialog; +} + +void ScScreenshotTest::testOpeningModalDialogs() +{ + initialize(); + + /// process input file containing the UXMLDescriptions of the dialogs to dump + processDialogBatchFile("sc/qa/unit/screenshots/data/screenshots.txt"); + + mxComponent->dispose(); + mxComponent.clear(); +} + +#if 0 +void ScScreenshotTest::testMultiViewCopyPaste() +{ + initialize(); + + ScDocument& rDoc = mxDocSh->GetDocument(); + + rDoc.SetString(ScAddress(0, 0, 0), "TestCopy1"); + rDoc.SetString(ScAddress(1, 0, 0), "TestCopy2"); + + // view #1 + ScTabViewShell* pView1 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current()); + CPPUNIT_ASSERT(pView1); + + // view #2 + SfxLokHelper::createView(); + ScTabViewShell* pView2 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current()); + CPPUNIT_ASSERT(pView1 != pView2); + { + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + CPPUNIT_ASSERT(SfxItemState::DISABLED != pView1->GetViewFrame()->GetBindings().QueryState(SID_PASTE, xItem1)); + CPPUNIT_ASSERT(SfxItemState::DISABLED != pView2->GetViewFrame()->GetBindings().QueryState(SID_PASTE, xItem2)); + } + + // copy text view 1 + pView1->SetCursor(0, 0); + pView1->GetViewFrame()->GetBindings().Execute(SID_COPY); + + // copy text view 2 + pView2->SetCursor(1, 0); + pView2->GetViewFrame()->GetBindings().Execute(SID_COPY); + + // paste text view 1 + pView1->SetCursor(0, 1); + pView1->GetViewFrame()->GetBindings().Execute(SID_PASTE); + + // paste text view 2 + pView2->SetCursor(1, 1); + pView2->GetViewFrame()->GetBindings().Execute(SID_PASTE); + + CPPUNIT_ASSERT_EQUAL(OUString("TestCopy2"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("TestCopy2"), rDoc.GetString(ScAddress(1, 1, 0))); + + mxComponent->dispose(); + mxComponent.clear(); +} +#endif + +CPPUNIT_TEST_SUITE_REGISTRATION(ScScreenshotTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |