Kaydet (Commit) d098f0c9 authored tarafından Armin Le Grand's avatar Armin Le Grand Kaydeden (comit) Thorsten Behrens

screenshots: 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
üst 836a77e5
......@@ -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;
};
......
......@@ -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
}
}
}
}
......
This diff is collapsed.
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment