summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
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: */