diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-03-01 16:01:48 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-03-02 13:25:40 +0000 |
commit | d913584909c2e0a235546a5f800baf45c3446d8b (patch) | |
tree | ce6367c54108a0cde6245ff1b36bce85b5a46731 /test | |
parent | add155dc2377a853b5281db8afb8818cb175c71a (diff) |
UnoApiXmlTest: merge parseExport from ChartTest
Reuse existing mechanism to handle chart file names in tests.
See https://lists.freedesktop.org/archives/libreoffice/2023-February/089995.html
and 5f7861e6ce212f47420533aed302fa4b5510557d
"fix chart export tests correctly
we have a static counter that increments chart export file names. So
only the first exported file gets the file name chart1.xml and all the
following charts are incremented by one even if they are in a different
file."
Also add an assert to warn developers only 1 chart is allow per sample
document when parsing them.
Adapt a few tests to follow this rule and change file document
from testMultipleChart.docx to testExternalData.docx because
the name was misleading
Change-Id: Id7282049796f2b05492ab70b50c80065a99439be
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148065
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/source/unoapixml_test.cxx | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/test/source/unoapixml_test.cxx b/test/source/unoapixml_test.cxx index 23dc826cbc97..c80ceb616665 100644 --- a/test/source/unoapixml_test.cxx +++ b/test/source/unoapixml_test.cxx @@ -11,9 +11,13 @@ #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/packages/zip/ZipFileAccess.hpp> #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> +#include <o3tl/string_view.hxx> +#include <unotools/ucbstreamhelper.hxx> + #include <sfx2/app.hxx> #include <sfx2/objsh.hxx> #include <utility> @@ -28,9 +32,46 @@ UnoApiXmlTest::UnoApiXmlTest(OUString path) xmlDocUniquePtr UnoApiXmlTest::parseExport(OUString const& rStreamName) { - std::unique_ptr<SvStream> const pStream(parseExportStream(maTempFile.GetURL(), rStreamName)); - xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); - return pXmlDoc; + if (rStreamName.indexOf("chart") == -1) + { + std::unique_ptr<SvStream> const pStream( + parseExportStream(maTempFile.GetURL(), rStreamName)); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + return pXmlDoc; + } + else + { + // we have a static counter that increments chart export file names. So + // only the first exported file gets the file name chart1.xml and all the + // following charts are incremented by one even if they are in a different file. + OUString aStreamName(rStreamName); + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL( + comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); + const uno::Sequence<OUString> aNames = xNameAccess->getElementNames(); + + if (aStreamName.endsWith(".xml")) + // remove "1.xml" + aStreamName = aStreamName.copy(0, aStreamName.getLength() - 5); + + uno::Reference<io::XInputStream> xInputStream; + + int nCount = 0; + for (const auto& rElementName : aNames) + { + if (o3tl::starts_with(rElementName, aStreamName)) + { + xInputStream.set(xNameAccess->getByName(rElementName), uno::UNO_QUERY); + ++nCount; + assert(nCount == 1 && "Only use one chart per document"); + } + } + + 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: */ |