summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-12-14 11:39:35 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-12-14 11:41:30 +0100
commit5f7861e6ce212f47420533aed302fa4b5510557d (patch)
treece269a34e58b06ba72de96129e44c1e14cdf4209 /chart2
parent007bf2b8c04090920b54e914ac75fc13720b450c (diff)
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. Change-Id: Iceaecb554bcb8d134eef7f7e3b11564a68794517
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2export.cxx43
1 files changed, 38 insertions, 5 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 8088894c6ba6..645febe5b2e4 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -20,6 +20,8 @@
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
+#include <algorithm>
+
using uno::Reference;
using beans::XPropertySet;
@@ -49,7 +51,7 @@ protected:
* xml stream, and asserting an XPath expression. This method returns the
* xml stream, so that you can do the asserting.
*/
- xmlDocPtr parseExport(const OUString& rStreamName, const OUString& rFilterFormat);
+ xmlDocPtr parseExport(const OUString& rDir, const OUString& rFilterFormat);
/**
* Helper method to return nodes represented by rXPath.
@@ -83,13 +85,44 @@ void Chart2ExportTest::test()
reload("Calc Office Open XML");
}
-xmlDocPtr Chart2ExportTest::parseExport(const OUString& rStreamName, const OUString& rFilterFormat)
+struct CheckForChartName
+{
+private:
+ OUString aDir;
+
+public:
+ CheckForChartName( const OUString& rDir ):
+ aDir(rDir) {}
+
+ bool operator()(const OUString& rName)
+ {
+ if(!rName.startsWith(aDir))
+ return false;
+
+ if(!rName.endsWith(".xml"))
+ return false;
+
+ return true;
+ }
+};
+
+OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAccess > xNames )
+{
+ uno::Sequence<OUString> rNames = xNames->getElementNames();
+ OUString* pElement = std::find_if(rNames.begin(), rNames.end(), CheckForChartName(rDir));
+
+ CPPUNIT_ASSERT(pElement);
+ CPPUNIT_ASSERT(pElement != rNames.end());
+ return *pElement;
+}
+
+xmlDocPtr Chart2ExportTest::parseExport(const OUString& rDir, const OUString& rFilterFormat)
{
boost::shared_ptr<utl::TempFile> pTempFile = reload(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(rStreamName), uno::UNO_QUERY);
+ uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(findChartFile(rDir, xNameAccess)), uno::UNO_QUERY);
CPPUNIT_ASSERT(xInputStream.is());
boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
pStream->Seek(STREAM_SEEK_TO_END);
@@ -373,7 +406,7 @@ void Chart2ExportTest::testStockChart()
*/
load("/chart2/qa/extras/data/docx/", "testStockChart.docx");
- xmlDocPtr pXmlDoc = parseExport("word/charts/chart1.xml", "Office Open XML Text");
+ xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
if (!pXmlDoc)
return;
@@ -385,7 +418,7 @@ void Chart2ExportTest::testStockChart()
void Chart2ExportTest::testBarChart()
{
load("/chart2/qa/extras/data/docx/", "testBarChart.docx");
- xmlDocPtr pXmlDoc = parseExport("word/charts/chart1.xml", "Office Open XML Text");
+ xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
if (!pXmlDoc)
return;