summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorArmin Le Grand <Armin.Le.Grand@cib.de>2016-07-15 15:25:59 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2016-08-18 02:39:11 +0200
commitd098f0c957824bd5dec89a799398d587ce9fb96f (patch)
treeca0f4ebf78b2a1bf2d6a3ee5e5c278738fc3b4e2 /test
parent836a77e5d6fdad5b74d296d5b55a6b0c8f016ade (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/source/screenshot_test.cxx154
1 files changed, 111 insertions, 43 deletions
diff --git a/test/source/screenshot_test.cxx b/test/source/screenshot_test.cxx
index d02e73841827..e33cf21b6545 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: */