[Libreoffice-commits] core.git: Branch 'feature/dialog-screenshots' - include/test sc/qa sd/qa test/source
Armin Le Grand
Armin.Le.Grand at cib.de
Wed Jul 20 09:01:12 UTC 2016
include/test/screenshot_test.hxx | 18 +++
sc/qa/unit/screenshots/screenshots.cxx | 90 ++++++++++++++-----
sd/qa/unit/dialogs-test.cxx | 122 ++++++++++++++++++--------
test/source/screenshot_test.cxx | 154 +++++++++++++++++++++++----------
4 files changed, 283 insertions(+), 101 deletions(-)
New commits:
commit 6ad23c23d2b33cfa65a7423c55d4a7cc8b9a71db
Author: Armin Le Grand <Armin.Le.Grand at cib.de>
Date: Fri Jul 15 15:25:59 2016 +0200
Use UI string and fallback for UI-String only
Two changes in this commit:
The Dialogs to be dumped are identified in their test files
using their UXMLDescription to allow later to 'find' the
known dialogs and use the specialized construction for these.
Also added a fallback to construct a vcl Dialog based on only
the UXMLDescription and the VclBuilder. This will be constructed
without any active initialization/layouting, so should only be
used for unknown Dialogs. Also added a dumpDialogToPath version
to the tooling that can work directly with a vcl Dialog instead
of a VclAbstractDialog.
Change-Id: I90abb6f59c2fcc5d534907ae7e4b9a15edc2d694
diff --git a/include/test/screenshot_test.hxx b/include/test/screenshot_test.hxx
index f07c29a..a3b0b0e 100644
--- a/include/test/screenshot_test.hxx
+++ b/include/test/screenshot_test.hxx
@@ -15,6 +15,7 @@
#include <unotest/macros_test.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <osl/file.hxx>
+#include <vcl/dialog.hxx>
class VclAbstractDialog;
@@ -27,10 +28,23 @@ public:
virtual void setUp() override;
virtual void tearDown() override;
- void dumpDialogToPath( VclAbstractDialog& rDialog );
+ /// version for AbstractDialogs, the ones created in AbstractDialogFactories
+ void dumpDialogToPath(VclAbstractDialog& rDialog);
+
+ /// version for pure vcl-based dialogs
+ void dumpDialogToPath(Dialog& rDialog);
+
+ /// fallback version for dialogs for which only the UXMLDescription is known.
+ /// This should be used with care - no active layouting will be done, only the
+ /// VclBuilder will be activated for layouting. Result can thus vary drastically
+ /// compared to the active dialog (can be compared with dialog previewer)
+ void dumpDialogToPath(const OString& rUIXMLDescription);
private:
- void saveScreenshot( VclAbstractDialog& rDialog );
+ void implSaveScreenshot(const Bitmap& rScreenshot, const OString& rScreenshotId);
+ void saveScreenshot(VclAbstractDialog& rDialog);
+ void saveScreenshot(Dialog& rDialog);
+
OUString m_aScreenshotDirectory;
};
diff --git a/sc/qa/unit/screenshots/screenshots.cxx b/sc/qa/unit/screenshots/screenshots.cxx
index 10213e5..556db72 100644
--- a/sc/qa/unit/screenshots/screenshots.cxx
+++ b/sc/qa/unit/screenshots/screenshots.cxx
@@ -40,8 +40,10 @@
#include <sc.hrc>
#include <scresid.hxx>
#include <scitems.hxx>
+#include <map>
using namespace css;
+typedef std::map< OString, sal_uInt32 > mapType;
static const char* DATA_DIRECTORY = "/sc/qa/unit/screenshots/data/";
@@ -72,9 +74,19 @@ private:
std::unique_ptr<ScImportStringStream> pStream;
std::unique_ptr<SfxItemSet> pItemSet;
+
+ /// the set of known dialogs and their ID for usage in createDialogByID
+ mapType maKnownDialogs;
};
ScScreenshotTest::ScScreenshotTest()
+: mxComponent(),
+ pFoundShell(nullptr),
+ xDocSh(),
+ pViewShell(nullptr),
+ pFact(nullptr),
+ pStream(),
+ maKnownDialogs()
{
}
@@ -97,7 +109,29 @@ void ScScreenshotTest::initializeWithDoc(const char* pName)
CPPUNIT_ASSERT_MESSAGE("Failed to create dialog factory", pFact);
const OUString aCsv("some, strings, here, separated, by, commas");
- pStream.reset( new ScImportStringStream( aCsv) );
+ pStream.reset(new ScImportStringStream(aCsv));
+
+ if (maKnownDialogs.empty())
+ {
+ // fill map of unknown dilogs. Use a set here to allow later
+ // to 'find' a ID for construction based on the UIXMLDescription
+ // string (currently not yet used)
+ maKnownDialogs["modules/scalc/ui/insertsheet.ui"] = 0;
+ maKnownDialogs["modules/scalc/ui/deletecells.ui"] = 1;
+ maKnownDialogs["modules/scalc/ui/pastespecial.ui"] = 2;
+ maKnownDialogs["modules/scalc/ui/changesourcedialog.ui"] = 3;
+ maKnownDialogs["modules/scalc/ui/selectdatasource.ui"] = 4;
+ maKnownDialogs["modules/scalc/ui/selectsource.ui"] = 5;
+ maKnownDialogs["modules/scalc/ui/deletecontents.ui"] = 6;
+ maKnownDialogs["modules/scalc/ui/createnamesdialog.ui"] = 7;
+ maKnownDialogs["modules/scalc/ui/inputstringdialog.ui"] = 8;
+ maKnownDialogs["modules/scalc/ui/tabcolordialog.ui"] = 9;
+ maKnownDialogs["modules/scalc/ui/textimportoptions.ui"] = 10;
+ maKnownDialogs["modules/scalc/ui/dataform.ui"] = 11;
+ maKnownDialogs["modules/scalc/ui/movecopysheet.ui"] = 12;
+ maKnownDialogs["modules/scalc/ui/textimportcsv.ui"] = 13;
+ maKnownDialogs["modules/scalc/ui/formatcellsdialog.ui"] = 14;
+ }
}
VclAbstractDialog* ScScreenshotTest::createDialogByID( sal_uInt32 nID )
@@ -108,7 +142,7 @@ VclAbstractDialog* ScScreenshotTest::createDialogByID( sal_uInt32 nID )
switch ( nID )
{
- case 0:
+ case 0: // "modules/scalc/ui/insertsheet.ui"
{
ScViewData& rViewData = pViewShell->GetViewData();
SCTAB nTabSelCount = rViewData.GetMarkData().GetSelectCount();
@@ -119,43 +153,42 @@ VclAbstractDialog* ScScreenshotTest::createDialogByID( sal_uInt32 nID )
break;
}
- case 1:
+ case 1: // "modules/scalc/ui/deletecells.ui"
{
pReturnDialog = pFact->CreateScDeleteCellDlg( pViewShell->GetDialogParent(), false );
break;
}
- case 2:
+ case 2: // "modules/scalc/ui/pastespecial.ui"
{
pReturnDialog = pFact->CreateScInsertContentsDlg( pViewShell->GetDialogParent() );
break;
}
- case 3:
+ case 3: // "modules/scalc/ui/changesourcedialog.ui"
{
pReturnDialog = pFact->CreateScColRowLabelDlg( pViewShell->GetDialogParent(), true, false );
break;
}
- case 4:
+ case 4: // "modules/scalc/ui/selectdatasource.ui"
{
pReturnDialog = pFact->CreateScDataPilotDatabaseDlg( pViewShell->GetDialogParent() );
break;
}
- case 5:
+ case 5: // "modules/scalc/ui/selectsource.ui"
{
-
pReturnDialog = pFact->CreateScDataPilotSourceTypeDlg(pViewShell->GetDialogParent(), true );
break;
}
- case 6:
+ case 6: // "modules/scalc/ui/deletecontents.ui"
{
pReturnDialog = pFact->CreateScDeleteContentsDlg( pViewShell->GetDialogParent() );
break;
}
- case 7:
+ case 7: // "modules/scalc/ui/createnamesdialog.ui"
{
//// just fake some flags
sal_uInt16 nFlags = NAME_LEFT | NAME_TOP;
@@ -163,7 +196,7 @@ VclAbstractDialog* ScScreenshotTest::createDialogByID( sal_uInt32 nID )
break;
}
- case 8:
+ case 8: // "modules/scalc/ui/inputstringdialog.ui"
{
const OString aEmpty("");
pReturnDialog = pFact->CreateScStringInputDlg( pViewShell->GetDialogParent(),
@@ -172,7 +205,7 @@ VclAbstractDialog* ScScreenshotTest::createDialogByID( sal_uInt32 nID )
break;
}
- case 9:
+ case 9: // "modules/scalc/ui/tabcolordialog.ui"
{
pReturnDialog = pFact->CreateScTabBgColorDlg( pViewShell->GetDialogParent(),
OUString(ScResId(SCSTR_SET_TAB_BG_COLOR)),
@@ -180,13 +213,13 @@ VclAbstractDialog* ScScreenshotTest::createDialogByID( sal_uInt32 nID )
break;
}
- case 10:
+ case 10: // "modules/scalc/ui/textimportoptions.ui"
{
pReturnDialog = pFact->CreateScTextImportOptionsDlg();
break;
}
- case 11:
+ case 11: // "modules/scalc/ui/dataform.ui"
{
////FIXME: looks butt-ugly w/ empty file, move it elsewhere, where
////we actually have some data
@@ -194,18 +227,18 @@ VclAbstractDialog* ScScreenshotTest::createDialogByID( sal_uInt32 nID )
break;
}
- case 12:
+ case 12: // "modules/scalc/ui/movecopysheet.ui"
{
pReturnDialog = pFact->CreateScMoveTableDlg( pViewShell->GetDialogParent(), aDefaultSheetName );
break;
}
- case 13:
+ case 13: // "modules/scalc/ui/textimportcsv.ui"
{
pReturnDialog = pFact->CreateScImportAsciiDlg( OUString(), pStream.get(), SC_PASTETEXT );
break;
}
- case 14:
+ case 14: // "modules/scalc/ui/formatcellsdialog.ui"
{
ScViewData& rViewData = pViewShell->GetViewData();
ScDocument *pDoc = rViewData.GetDocument();
@@ -239,13 +272,26 @@ void ScScreenshotTest::testOpeningModalDialogs()
{
initializeWithDoc("empty.ods");
- const sal_uInt32 nDialogs = 15;
+ static bool bDumpAllKnownDialogs = true;
- for ( sal_uInt32 i = 0; i < nDialogs; i++ )
+ if (bDumpAllKnownDialogs)
{
- std::unique_ptr<VclAbstractDialog> pDialog( createDialogByID( i ) );
-
- dumpDialogToPath( *pDialog );
+ for (mapType::const_iterator i = maKnownDialogs.begin(); i != maKnownDialogs.end(); i++)
+ {
+ std::unique_ptr<VclAbstractDialog> pDlg(createDialogByID((*i).second));
+
+ if (pDlg)
+ {
+ // known dialog, dump screenshot to path
+ dumpDialogToPath(*pDlg);
+ }
+ else
+ {
+ // unknown dialog, should not happen in this basic loop.
+ // You have probably forgotten to add a case and
+ // implementastion to createDialogByID, please do this
+ }
+ }
}
}
diff --git a/sd/qa/unit/dialogs-test.cxx b/sd/qa/unit/dialogs-test.cxx
index 02dfa20..893fd43 100644
--- a/sd/qa/unit/dialogs-test.cxx
+++ b/sd/qa/unit/dialogs-test.cxx
@@ -54,8 +54,10 @@
#include <com/sun/star/frame/XDesktop2.hpp>
#include <comphelper/processfactory.hxx>
#include <unotest/macros_test.hxx>
+#include <map>
using namespace ::com::sun::star;
+typedef std::map< OString, sal_uInt32 > mapType;
/// Test opening a dialog in sd
class SdDialogsTest : public ScreenshotTest
@@ -77,6 +79,9 @@ private:
std::unique_ptr<SfxItemSet> mpEmptySfxItemSet;
std::unique_ptr<SfxItemSet> mpEmptyFillStyleSfxItemSet;
+ /// the set of known dialogs and their ID for usage in createDialogByID
+ mapType maKnownDialogs;
+
/// helpers
SdAbstractDialogFactory* getSdAbstractDialogFactory();
SdXImpressDocument* getSdXImpressDocument();
@@ -113,7 +118,8 @@ SdDialogsTest::SdDialogsTest()
mpDrawView(nullptr),
mpSfxItemSetFromSdrObject(nullptr),
mpEmptySfxItemSet(nullptr),
- mpEmptyFillStyleSfxItemSet(nullptr)
+ mpEmptyFillStyleSfxItemSet(nullptr),
+ maKnownDialogs()
{
}
@@ -131,6 +137,36 @@ void SdDialogsTest::setUp()
mpImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
CPPUNIT_ASSERT(mpImpressDocument);
+
+ if (maKnownDialogs.empty())
+ {
+ // fill map of unknown dilogs. Use a set here to allow later
+ // to 'find' a ID for construction based on the UIXMLDescription
+ // string (currently not yet used)
+ maKnownDialogs["modules/simpress/ui/publishingdialog.ui"] = 0;
+ maKnownDialogs["modules/sdraw/ui/breakdialog.ui"] = 1;
+ maKnownDialogs["modules/sdraw/ui/copydlg.ui"] = 2;
+ maKnownDialogs["modules/simpress/ui/customslideshows.ui"] = 3;
+ maKnownDialogs["modules/sdraw/ui/drawchardialog.ui"] = 4;
+ maKnownDialogs["modules/sdraw/ui/drawpagedialog.ui"] = 5;
+ maKnownDialogs["modules/simpress/ui/dlgfield.ui"] = 6;
+ maKnownDialogs["modules/sdraw/ui/dlgsnap.ui"] = 7;
+ maKnownDialogs["modules/sdraw/ui/insertlayer.ui"] = 8;
+ maKnownDialogs["modules/sdraw/ui/insertslidesdialog.ui"] = 9;
+ maKnownDialogs["modules/sdraw/ui/crossfadedialog.ui"] = 10;
+ maKnownDialogs["modules/sdraw/ui/bulletsandnumbering.ui"] = 11;
+ maKnownDialogs["modules/sdraw/ui/drawparadialog.ui"] = 12;
+ maKnownDialogs["modules/simpress/ui/presentationdialog.ui"] = 13;
+ maKnownDialogs["modules/simpress/ui/remotedialog.ui"] = 14;
+ maKnownDialogs["modules/sdraw/ui/drawprtldialog.ui"] = 15;
+ maKnownDialogs["modules/simpress/ui/slidedesigndialog.ui"] = 16;
+ maKnownDialogs["modules/sdraw/ui/drawprtldialog.ui"] = 17;
+ maKnownDialogs["modules/simpress/ui/interactiondialog.ui"] = 18;
+ maKnownDialogs["modules/sdraw/ui/vectorize.ui"] = 19;
+ maKnownDialogs["modules/simpress/ui/photoalbum.ui"] = 20;
+ maKnownDialogs["modules/simpress/ui/masterlayoutdlg.ui"] = 21;
+ maKnownDialogs["modules/simpress/ui/headerfooterdialog.ui"] = 22;
+ }
}
SdAbstractDialogFactory* SdDialogsTest::getSdAbstractDialogFactory()
@@ -307,11 +343,6 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
}
case 6:
{
- // CreateAssistentDlg(bool bAutoPilot) has been dropped
- break;
- }
- case 7:
- {
// CreateSdModifyFieldDlg(vcl::Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet) override;
pRetval = getSdAbstractDialogFactory()->CreateSdModifyFieldDlg(
Application::GetDefDialogParent(),
@@ -319,7 +350,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
getEmptySfxItemSet());
break;
}
- case 8:
+ case 7:
{
// CreateSdSnapLineDlg(const SfxItemSet& rInAttrs, ::sd::View* pView) override;
SdDrawDocument* pDrawDoc = getSdXImpressDocument()->GetDoc();
@@ -333,7 +364,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
getDrawView());
break;
}
- case 9:
+ case 8:
{
// CreateSdInsertLayerDlg(const SfxItemSet& rInAttrs, bool bDeletable, const OUString& aStr) override;
SdDrawDocument* pDrawDoc = getSdXImpressDocument()->GetDoc();
@@ -354,7 +385,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
SD_RESSTR(STR_INSERTLAYER) /* alternative: STR_MODIFYLAYER */);
break;
}
- case 10:
+ case 9:
{
// CreateSdInsertPagesObjsDlg(const SdDrawDocument* pDoc, SfxMedium* pSfxMedium, const OUString& rFileName) override;
SdDrawDocument* pDrawDoc = getSdXImpressDocument()->GetDoc();
@@ -367,7 +398,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
aFileName);
break;
}
- case 11:
+ case 10:
{
// CreateMorphDlg(vcl::Window* pParent, const SdrObject* pObj1, const SdrObject* pObj2) override;
SdDrawDocument* pDrawDoc = getSdXImpressDocument()->GetDoc();
@@ -383,7 +414,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
pSdrObj);
break;
}
- case 12:
+ case 11:
{
// CreateSdOutlineBulletTabDlg(const SfxItemSet* pAttr, ::sd::View* pView = nullptr) override;
pRetval = getSdAbstractDialogFactory()->CreateSdOutlineBulletTabDlg(
@@ -392,7 +423,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
getDrawView());
break;
}
- case 13:
+ case 12:
{
// CreateSdParagraphTabDlg(const SfxItemSet* pAttr) override;
pRetval = getSdAbstractDialogFactory()->CreateSdParagraphTabDlg(
@@ -400,7 +431,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
&getEmptySfxItemSet());
break;
}
- case 14:
+ case 13:
{
// CreateSdStartPresentationDlg(vcl::Window* pWindow, const SfxItemSet& rInAttrs, const std::vector<OUString> &rPageNames, SdCustomShowList* pCSList) override;
const std::vector<OUString> aPageNames;
@@ -430,14 +461,14 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
nullptr);
break;
}
- case 15:
+ case 14:
{
// CreateRemoteDialog(vcl::Window* pWindow) override; // ad for RemoteDialog
pRetval = getSdAbstractDialogFactory()->CreateRemoteDialog(
Application::GetDefDialogParent());
break;
}
- case 16:
+ case 15:
{
// CreateSdPresLayoutTemplateDlg(SfxObjectShell* pDocSh, vcl::Window* pParent, const SdResId& DlgId, SfxStyleSheetBase& rStyleBase, PresentationObjects ePO, SfxStyleSheetBasePool* pSSPool) override;
// use STR_PSEUDOSHEET_TITLE configuration, see futempl.cxx for more possible configurations
@@ -455,7 +486,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
pStyleSheetPool);
break;
}
- case 17:
+ case 16:
{
// CreateSdPresLayoutDlg(::sd::DrawDocShell* pDocShell, vcl::Window* pWindow, const SfxItemSet& rInAttrs) override;
pRetval = getSdAbstractDialogFactory()->CreateSdPresLayoutDlg(
@@ -464,7 +495,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
getEmptySfxItemSet());
break;
}
- case 18:
+ case 17:
{
// CreateSdTabTemplateDlg(const SfxObjectShell* pDocShell, SfxStyleSheetBase& rStyleBase, SdrModel* pModel, SdrView* pView) override;
// pretty similar to CreateSdPresLayoutTemplateDlg, see above
@@ -483,7 +514,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
getDrawView());
break;
}
- case 19:
+ case 18:
{
// CreatSdActionDialog(const SfxItemSet* pAttr, ::sd::View* pView) override;
SdDrawDocument* pDrawDoc = getSdXImpressDocument()->GetDoc();
@@ -511,7 +542,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
getDrawView());
break;
}
- case 20:
+ case 19:
{
// CreateSdVectorizeDlg(vcl::Window* pParent, const Bitmap& rBmp, ::sd::DrawDocShell* pDocShell) override;
// works well with empty Bitmap, but my be nicer with setting one
@@ -522,7 +553,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
getDocShell());
break;
}
- case 21:
+ case 20:
{
// CreateSdPhotoAlbumDialog(vcl::Window* pWindow, SdDrawDocument* pDoc) override;
SdDrawDocument* pDrawDoc = getSdXImpressDocument()->GetDoc();
@@ -532,7 +563,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
pDrawDoc);
break;
}
- case 22:
+ case 21:
{
// CreateMasterLayoutDialog(vcl::Window* pParent, SdDrawDocument* pDoc, SdPage*) override;
SdDrawDocument* pDrawDoc = getSdXImpressDocument()->GetDoc();
@@ -545,7 +576,7 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
pSdPage);
break;
}
- case 23:
+ case 22:
{
// CreateHeaderFooterDialog(sd::ViewShell* pViewShell, vcl::Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage) override;
// This is a hard case, for two reasons:
@@ -575,24 +606,47 @@ VclAbstractDialog* SdDialogsTest::createDialogByID(sal_uInt32 nID)
void SdDialogsTest::openAnyDialog()
{
- // example for SfxTabDialog: 5
- // example for TabDialog: 23
- // example for self-adapted wizard: 0
- static sal_uInt32 nStartValue(0);
- static sal_uInt32 nEndValue(24);
-
- // loop and dump all Dialogs from SD for now
- for (sal_uInt32 a(nStartValue); a < nEndValue; a++)
- {
- std::unique_ptr<VclAbstractDialog> pDlg( createDialogByID(a) );
+ static bool bDumpAllKnownDialogs = true;
- if (pDlg)
+ if (bDumpAllKnownDialogs)
+ {
+ // example for SfxTabDialog: 5 -> "modules/sdraw/ui/drawpagedialog.ui"
+ // example for TabDialog: 22 -> "modules/simpress/ui/headerfooterdialog.ui"
+ // example for self-adapted wizard: 0 -> "modules/simpress/ui/publishingdialog.ui"
+ for (mapType::const_iterator i = maKnownDialogs.begin(); i != maKnownDialogs.end(); i++)
{
- dumpDialogToPath(*pDlg);
+ std::unique_ptr<VclAbstractDialog> pDlg(createDialogByID((*i).second));
+
+ if (pDlg)
+ {
+ // known dialog, dump screenshot to path
+ dumpDialogToPath(*pDlg);
+ }
+ else
+ {
+ // unknown dialog, should not happen in this basic loop.
+ // You have probably forgotten to add a case and
+ // implementastion to createDialogByID, please do this
+ }
}
}
+ static bool bCheckFallbackDialog = false;
+ if (bCheckFallbackDialog)
+ {
+ // unknown dialog, try fallback to generic created
+ // VclBuilder-generated instance. Keep in mind that Dialogs
+ // using this mechanism will probably not be layouted well
+ // since the setup/initialization part is missing. Thus,
+ // only use for fallback when only the UI file is available.
+ //
+ // Take any example here, it's only for demonstration - using
+ // even a known one to demonstrate the fallback possibility
+ const OString aUIXMLDescription("modules/sdraw/ui/breakdialog.ui");
+
+ dumpDialogToPath(aUIXMLDescription);
+ }
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdDialogsTest);
diff --git a/test/source/screenshot_test.cxx b/test/source/screenshot_test.cxx
index d02e738..e33cf21 100644
--- a/test/source/screenshot_test.cxx
+++ b/test/source/screenshot_test.cxx
@@ -14,9 +14,10 @@
#include <comphelper/processfactory.hxx>
#include <vcl/abstdlg.hxx>
#include <vcl/pngwrite.hxx>
+#include <vcl/svapp.hxx>
namespace {
- void splitHelpId( OString& rHelpId, OUString& rDirname, OUString &rBasename )
+ void splitHelpId( const OString& rHelpId, OUString& rDirname, OUString &rBasename )
{
sal_Int32 nIndex = rHelpId.lastIndexOf( '/' );
@@ -52,51 +53,118 @@ void ScreenshotTest::tearDown()
test::BootstrapFixture::tearDown();
}
-void ScreenshotTest::saveScreenshot( VclAbstractDialog& rDialog )
+void ScreenshotTest::implSaveScreenshot(const Bitmap& rScreenshot, const OString& rScreenshotId)
{
- const Bitmap aScreenshot(rDialog.createScreenshot());
-
- if (!aScreenshot.IsEmpty())
- {
- OString aScreenshotId = rDialog.GetScreenshotId();
- OUString aDirname, aBasename;
- splitHelpId( aScreenshotId, aDirname, aBasename );
- aDirname = m_aScreenshotDirectory + aDirname;
-
- osl::FileBase::RC err = osl::Directory::createPath( m_directories.getURLFromSrc( aDirname ));
- CPPUNIT_ASSERT_MESSAGE( OUStringToOString( "Failed to create " + aDirname, RTL_TEXTENCODING_UTF8).getStr(),
- (err == osl::FileBase::E_None || err == osl::FileBase::E_EXIST) );
-
- OUString aFullPath = m_directories.getSrcRootPath() + aDirname + "/" + aBasename + ".png";
- SvFileStream aNew(aFullPath, StreamMode::WRITE | StreamMode::TRUNC);
- CPPUNIT_ASSERT_MESSAGE( OUStringToOString( "Failed to open " + OUString::number(aNew.GetErrorCode()), RTL_TEXTENCODING_UTF8).getStr(), aNew.IsOpen() );
-
- vcl::PNGWriter aPNGWriter(aScreenshot);
- aPNGWriter.Write(aNew);
- }
+ OUString aDirname, aBasename;
+ splitHelpId(rScreenshotId, aDirname, aBasename);
+ aDirname = m_aScreenshotDirectory + aDirname;
+
+ osl::FileBase::RC err = osl::Directory::createPath(m_directories.getURLFromSrc(aDirname));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString("Failed to create " + aDirname, RTL_TEXTENCODING_UTF8).getStr(),
+ (err == osl::FileBase::E_None || err == osl::FileBase::E_EXIST));
+
+ OUString aFullPath = m_directories.getSrcRootPath() + aDirname + "/" + aBasename + ".png";
+ SvFileStream aNew(aFullPath, StreamMode::WRITE | StreamMode::TRUNC);
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString("Failed to open " + OUString::number(aNew.GetErrorCode()), RTL_TEXTENCODING_UTF8).getStr(), aNew.IsOpen());
+
+ vcl::PNGWriter aPNGWriter(rScreenshot);
+ aPNGWriter.Write(aNew);
+}
+
+void ScreenshotTest::saveScreenshot(VclAbstractDialog& rDialog)
+{
+ const Bitmap aScreenshot(rDialog.createScreenshot());
+
+ if (!aScreenshot.IsEmpty())
+ {
+ const OString aScreenshotId = rDialog.GetScreenshotId();
+
+ if (!aScreenshotId.isEmpty())
+ {
+ implSaveScreenshot(aScreenshot, aScreenshotId);
+ }
+ }
+}
+
+void ScreenshotTest::saveScreenshot(Dialog& rDialog)
+{
+ const Bitmap aScreenshot(rDialog.createScreenshot());
+
+ if (!aScreenshot.IsEmpty())
+ {
+ const OString aScreenshotId = rDialog.GetScreenshotId();
+
+ if (!aScreenshotId.isEmpty())
+ {
+ implSaveScreenshot(aScreenshot, aScreenshotId);
+ }
+ }
+}
+
+void ScreenshotTest::dumpDialogToPath(VclAbstractDialog& rDialog)
+{
+ const std::vector<OString> aPageDescriptions(rDialog.getAllPageUIXMLDescriptions());
+
+ if (aPageDescriptions.size())
+ {
+ for (sal_uInt32 a(0); a < aPageDescriptions.size(); a++)
+ {
+ if (rDialog.selectPageByUIXMLDescription(aPageDescriptions[a]))
+ {
+ saveScreenshot(rDialog);
+ }
+ else
+ {
+ CPPUNIT_ASSERT(false);
+ }
+ }
+ }
+ else
+ {
+ saveScreenshot(rDialog);
+ }
}
-void ScreenshotTest::dumpDialogToPath( VclAbstractDialog& rDialog )
+void ScreenshotTest::dumpDialogToPath(Dialog& rDialog)
{
- const std::vector<OString> aPageDescriptions(rDialog.getAllPageUIXMLDescriptions());
-
- if (aPageDescriptions.size())
- {
- for (sal_uInt32 a(0); a < aPageDescriptions.size(); a++)
- {
- if (rDialog.selectPageByUIXMLDescription(aPageDescriptions[a]))
- {
- saveScreenshot( rDialog );
- }
- else
- {
- CPPUNIT_ASSERT(false);
- }
- }
- }
- else
- {
- saveScreenshot( rDialog );
- }
+ const std::vector<OString> aPageDescriptions(rDialog.getAllPageUIXMLDescriptions());
+
+ if (aPageDescriptions.size())
+ {
+ for (sal_uInt32 a(0); a < aPageDescriptions.size(); a++)
+ {
+ if (rDialog.selectPageByUIXMLDescription(aPageDescriptions[a]))
+ {
+ saveScreenshot(rDialog);
+ }
+ else
+ {
+ CPPUNIT_ASSERT(false);
+ }
+ }
+ }
+ else
+ {
+ saveScreenshot(rDialog);
+ }
}
+
+void ScreenshotTest::dumpDialogToPath(const OString& rUIXMLDescription)
+{
+ if (!rUIXMLDescription.isEmpty())
+ {
+ VclPtrInstance<Dialog> pDialog(Application::GetDefDialogParent(), WB_STDDIALOG | WB_SIZEABLE, Dialog::InitFlag::NoParent);
+ VclBuilder aBuilder(pDialog, VclBuilderContainer::getUIRootDir(), OStringToOUString(rUIXMLDescription, RTL_TEXTENCODING_UTF8));
+ vcl::Window *pRoot = aBuilder.get_widget_root();
+ Dialog *pRealDialog = dynamic_cast<Dialog*>(pRoot);
+
+ if (!pRealDialog)
+ pRealDialog = pDialog;
+
+ pRealDialog->SetText("LibreOffice DialogScreenshot");
+ pRealDialog->SetStyle(pDialog->GetStyle() | WB_CLOSEABLE);
+ dumpDialogToPath(*pRealDialog);
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list