diff options
Diffstat (limited to 'chart2/qa/extras/charttest.hxx')
-rw-r--r-- | chart2/qa/extras/charttest.hxx | 228 |
1 files changed, 48 insertions, 180 deletions
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx index 02ad9675d930..db416affaa9f 100644 --- a/chart2/qa/extras/charttest.hxx +++ b/chart2/qa/extras/charttest.hxx @@ -9,9 +9,7 @@ #pragma once -#include <test/bootstrapfixture.hxx> -#include <test/xmltesttools.hxx> -#include <unotest/macros_test.hxx> +#include <test/unoapixml_test.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> @@ -28,7 +26,6 @@ #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/frame/XStorable.hpp> -#include <com/sun/star/packages/zip/ZipFileAccess.hpp> #include <o3tl/string_view.hxx> #include <unotools/tempfile.hxx> @@ -67,8 +64,6 @@ #include <com/sun/star/embed/XVisualObject.hpp> #include <com/sun/star/chart2/RelativeSize.hpp> -#include <unotools/ucbstreamhelper.hxx> - using namespace css; using namespace css::uno; @@ -77,160 +72,27 @@ namespace com::sun::star::chart2 { class XDiagram; } namespace com::sun::star::table { class XTableCharts; } namespace com::sun::star::table { class XTablePivotCharts; } -namespace { - -struct CheckForChartName +class ChartTest : public UnoApiXmlTest { -private: - OUString aDir; - public: - explicit CheckForChartName( const OUString& rDir ): - aDir(rDir) {} - - bool operator()(std::u16string_view rName) + ChartTest(OUString path) + : UnoApiXmlTest(path) { - if(!o3tl::starts_with(rName, aDir)) - return false; - - if(!o3tl::ends_with(rName, u".xml")) - return false; - - return true; } -}; - -OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAccess > const & xNames ) -{ - const uno::Sequence<OUString> aNames = xNames->getElementNames(); - const OUString* pElement = std::find_if(aNames.begin(), aNames.end(), CheckForChartName(rDir)); - - CPPUNIT_ASSERT(pElement != aNames.end()); - return *pElement; -} -} - -class ChartTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools -{ -public: - ChartTest():mbSkipValidation(false) {} - void load( std::u16string_view rDir, const OUString& rFileName ); - std::shared_ptr<utl::TempFile> save( const OUString& rFileName ); - std::shared_ptr<utl::TempFile> reload( const OUString& rFileName ); - uno::Sequence < OUString > getImpressChartColumnDescriptions( std::u16string_view pDir, const char* pName ); - OUString getFileExtension( const OUString& rFileName ); - - uno::Reference< chart::XChartDocument > getChartDocFromImpress( std::u16string_view pDir, const char* pName ); + uno::Sequence < OUString > getImpressChartColumnDescriptions(sal_Int32 nPage, sal_Int32 nShape); uno::Reference<chart::XChartDocument> getChartDocFromDrawImpress( sal_Int32 nPage, sal_Int32 nShape ); + uno::Reference<chart::XChartDocument> getChartDocFromDrawImpressNamed( sal_Int32 nPage, std::u16string_view rName); + uno::Reference<chart::XChartDocument> getChartDocFromWriter( sal_Int32 nShape ); Sequence< OUString > getFormattedDateCategories( const Reference<chart2::XChartDocument>& xChartDoc ); awt::Size getPageSize( const Reference< chart2::XChartDocument > & xChartDoc ); awt::Size getSize(css::uno::Reference<chart2::XDiagram> xDiagram, const awt::Size& rPageSize); - - virtual void setUp() override; - virtual void tearDown() override; - -protected: - Reference< lang::XComponent > mxComponent; - OUString maServiceName; - bool mbSkipValidation; // if you set this flag for a new test I'm going to haunt you! - - /** - * Given that some problem doesn't affect the result in the importer, we - * test the resulting file directly, by opening the zip file, parsing an - * xml stream, and asserting an XPath expression. This method returns the - * xml stream, so that you can do the asserting. - */ - xmlDocUniquePtr parseExport(const OUString& rDir, const OUString& rFilterFormat); }; -OUString ChartTest::getFileExtension( const OUString& aFileName ) -{ - sal_Int32 nDotLocation = aFileName.lastIndexOf('.'); - CPPUNIT_ASSERT(nDotLocation != -1); - return aFileName.copy(nDotLocation+1); // Skip the dot. -} - -void ChartTest::load( std::u16string_view aDir, const OUString& aName ) -{ - OUString extension = getFileExtension(aName); - if (extension == "ods" || extension == "xlsx" || extension == "fods") - { - maServiceName = "com.sun.star.sheet.SpreadsheetDocument"; - } - else if (extension == "docx") - { - maServiceName = "com.sun.star.text.TextDocument"; - } - else if (extension == "odg") - { - maServiceName = "com.sun.star.drawing.DrawingDocument"; - } - if (mxComponent.is()) - mxComponent->dispose(); - mxComponent = loadFromDesktop(m_directories.getURLFromSrc(aDir) + aName, maServiceName); -} - -std::shared_ptr<utl::TempFile> ChartTest::save(const OUString& rFilterName) -{ - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - auto aArgs(::comphelper::InitPropertySequence({ - { "FilterName", Any(rFilterName) } - })); - std::shared_ptr<utl::TempFile> pTempFile = std::make_shared<utl::TempFile>(); - pTempFile->EnableKillingFile(); - xStorable->storeToURL(pTempFile->GetURL(), aArgs); - - return pTempFile; -} - -std::shared_ptr<utl::TempFile> ChartTest::reload(const OUString& rFilterName) -{ - std::shared_ptr<utl::TempFile> pTempFile = save(rFilterName); - mxComponent->dispose(); - mxComponent = loadFromDesktop(pTempFile->GetURL(), maServiceName); - std::cout << pTempFile->GetURL(); - if(rFilterName == "Calc Office Open XML") - { - validate(pTempFile->GetFileName(), test::OOXML); - } - else if(rFilterName == "Office Open XML Text") - { - // validate(pTempFile->GetFileName(), test::OOXML); - } - else if(rFilterName == "calc8") - { - if(!mbSkipValidation) - validate(pTempFile->GetFileName(), test::ODF); - } - else if(rFilterName == "MS Excel 97") - { - if(!mbSkipValidation) - validate(pTempFile->GetFileName(), test::MSBINARY); - } - return pTempFile; -} - -void ChartTest::setUp() -{ - test::BootstrapFixture::setUp(); - - mxDesktop.set( css::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) ) ); -} - -void ChartTest::tearDown() -{ - if(mxComponent.is()) - mxComponent->dispose(); - - test::BootstrapFixture::tearDown(); - -} - -Reference< lang::XComponent > getChartCompFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > const & xComponent ) +Reference< lang::XComponent > getChartCompFromSheet( sal_Int32 nSheet, sal_Int32 nChart, uno::Reference< lang::XComponent > const & xComponent ) { // let us assume that we only have one chart per sheet @@ -244,7 +106,7 @@ Reference< lang::XComponent > getChartCompFromSheet( sal_Int32 nSheet, uno::Refe CPPUNIT_ASSERT(xCharts.is()); uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW); - uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW); + uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(nChart), UNO_QUERY_THROW); uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW); @@ -256,7 +118,7 @@ Reference< lang::XComponent > getChartCompFromSheet( sal_Int32 nSheet, uno::Refe Reference< chart2::XChartDocument > getChartDocFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > const & xComponent ) { - uno::Reference< chart2::XChartDocument > xChartDoc ( getChartCompFromSheet(nSheet, xComponent), UNO_QUERY_THROW ); + uno::Reference< chart2::XChartDocument > xChartDoc ( getChartCompFromSheet(nSheet, 0, xComponent), UNO_QUERY_THROW ); // Update the chart view, so that its draw page is updated and ready for the test css::uno::Reference<css::frame::XModel> xModel(xChartDoc, css::uno::UNO_QUERY_THROW); @@ -524,23 +386,6 @@ std::vector<uno::Sequence<uno::Any> > getDataSeriesLabelsFromChartType( const Re return aRet; } -uno::Reference< chart::XChartDocument > ChartTest::getChartDocFromImpress( std::u16string_view pDir, const char* pName ) -{ - mxComponent = loadFromDesktop(m_directories.getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Draw.PresentationDocument"); - uno::Reference< drawing::XDrawPagesSupplier > xDoc(mxComponent, uno::UNO_QUERY_THROW ); - uno::Reference< drawing::XDrawPage > xPage( - xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xShapeProps( - xPage->getByIndex(0), uno::UNO_QUERY ); - CPPUNIT_ASSERT(xShapeProps.is()); - uno::Reference< frame::XModel > xDocModel; - xShapeProps->getPropertyValue("Model") >>= xDocModel; - CPPUNIT_ASSERT(xDocModel.is()); - uno::Reference< chart::XChartDocument > xChartDoc( xDocModel, uno::UNO_QUERY_THROW ); - - return xChartDoc; -} - uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromDrawImpress( sal_Int32 nPage, sal_Int32 nShape ) { @@ -566,6 +411,42 @@ uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromDrawImpress( return xChartDoc; } +uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromDrawImpressNamed(sal_Int32 nPage, std::u16string_view rName) +{ + uno::Reference<chart::XChartDocument> xChart; + + uno::Reference<drawing::XDrawPagesSupplier> xPages(mxComponent, uno::UNO_QUERY); + if (!xPages.is()) + return xChart; + + uno::Reference<drawing::XDrawPage> xPage(xPages->getDrawPages()->getByIndex(nPage), uno::UNO_QUERY); + if (!xPage.is()) + return xChart; + + for (sal_Int32 i=0; i < xPage->getCount(); ++i) + { + uno::Reference<container::XNamed> xNamedShape(xPage->getByIndex(i), uno::UNO_QUERY); + if (!xNamedShape.is()) + continue; + + if (xNamedShape->getName() != rName) + continue; + + uno::Reference<beans::XPropertySet> xShapeProps(xNamedShape, uno::UNO_QUERY); + if (!xShapeProps.is()) + continue; + + uno::Reference<frame::XModel> xDocModel; + xShapeProps->getPropertyValue("Model") >>= xDocModel; + if (!xDocModel.is()) + continue; + + return uno::Reference<chart::XChartDocument>(xDocModel, uno::UNO_QUERY); + } + + return xChart; +} + uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromWriter( sal_Int32 nShape ) { // DO NOT use XDrawPageSupplier since SwVirtFlyDrawObj are not created @@ -586,9 +467,9 @@ uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromWriter( sal_Int3 return xChartDoc; } -uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( std::u16string_view pDir, const char* pName ) +uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions(sal_Int32 nPage, sal_Int32 nShape) { - uno::Reference< chart::XChartDocument > xChartDoc = getChartDocFromImpress( pDir, pName ); + uno::Reference< chart::XChartDocument > xChartDoc = getChartDocFromDrawImpress( nPage, nShape ); uno::Reference< chart::XChartDataArray > xChartData ( xChartDoc->getData(), uno::UNO_QUERY_THROW); uno::Sequence < OUString > seriesList = xChartData->getColumnDescriptions(); return seriesList; @@ -721,17 +602,4 @@ getShapeByName(const uno::Reference<drawing::XShapes>& rShapes, const OUString& return uno::Reference<drawing::XShape>(); } -xmlDocUniquePtr ChartTest::parseExport(const OUString& rDir, const OUString& rFilterFormat) -{ - std::shared_ptr<utl::TempFile> pTempFile = save(rFilterFormat); - - // Read the XML stream we're interested in. - uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), pTempFile->GetURL()); - uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(findChartFile(rDir, xNameAccess)), uno::UNO_QUERY); - CPPUNIT_ASSERT(xInputStream.is()); - std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); - - return parseXmlStream(pStream.get()); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |