summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorPallavi Jadhav <pallavi.jadhav@synerzip.com>2013-12-06 18:13:49 +0530
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-12-13 20:05:14 +0100
commitd843d64283c311f02ff663cb02d7ac5a4e744bfc (patch)
treec105718a6b42f2828d250f4f4149c403facf56c7 /chart2
parent71b491fd71f5ad1aa61f917992462009a6d1bb6b (diff)
Added OOXML Unit Test framework for Chart module for export.
- Referred functions from sw module. Change-Id: I3ae90d40d92de0d67623e73e1676dabcc8a413f6
Diffstat (limited to 'chart2')
-rw-r--r--chart2/CppunitTest_chart2_export.mk10
-rw-r--r--chart2/CppunitTest_chart2_import.mk6
-rw-r--r--chart2/qa/extras/chart2export.cxx138
-rw-r--r--chart2/qa/extras/charttest.hxx42
-rw-r--r--chart2/qa/extras/data/docx/testBarChart.docxbin0 -> 23955 bytes
5 files changed, 177 insertions, 19 deletions
diff --git a/chart2/CppunitTest_chart2_export.mk b/chart2/CppunitTest_chart2_export.mk
index a861693f33f1..41b751493d5a 100644
--- a/chart2/CppunitTest_chart2_export.mk
+++ b/chart2/CppunitTest_chart2_export.mk
@@ -11,7 +11,10 @@
$(eval $(call gb_CppunitTest_CppunitTest,chart2_export))
-$(eval $(call gb_CppunitTest_use_external,chart2_export,boost_headers))
+$(eval $(call gb_CppunitTest_use_externals,chart2_export, \
+ boost_headers \
+ libxml2 \
+))
$(eval $(call gb_CppunitTest_add_exception_objects,chart2_export, \
chart2/qa/extras/chart2export \
@@ -50,6 +53,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_export, \
vbahelper \
vcl \
xo \
+ sw \
$(gb_UWINAPI) \
))
@@ -85,6 +89,9 @@ $(eval $(call gb_CppunitTest_use_components,chart2_export,\
sc/util/sc \
sc/util/scd \
sc/util/scfilt \
+ sw/util/sw \
+ sw/util/swd \
+ sw/util/msword \
$(if $(filter TRUE,$(DISABLE_SCRIPTING)),, \
sc/util/vbaobj) \
scaddins/source/analysis/analysis \
@@ -104,6 +111,7 @@ $(eval $(call gb_CppunitTest_use_components,chart2_export,\
unotools/util/utl \
unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
+ writerfilter/util/writerfilter \
xmloff/util/xo \
))
diff --git a/chart2/CppunitTest_chart2_import.mk b/chart2/CppunitTest_chart2_import.mk
index 2c74eb52cae1..2ca91f74395f 100644
--- a/chart2/CppunitTest_chart2_import.mk
+++ b/chart2/CppunitTest_chart2_import.mk
@@ -11,7 +11,10 @@
$(eval $(call gb_CppunitTest_CppunitTest,chart2_import))
-$(eval $(call gb_CppunitTest_use_external,chart2_import,boost_headers))
+$(eval $(call gb_CppunitTest_use_externals,chart2_import, \
+ boost_headers \
+ libxml2 \
+))
$(eval $(call gb_CppunitTest_add_exception_objects,chart2_import, \
chart2/qa/extras/chart2import \
@@ -52,6 +55,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_import, \
utl \
vbahelper \
xo \
+ sw \
$(gb_UWINAPI) \
))
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 7ae449a2bf8f..d122d8c0f147 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -12,6 +12,13 @@
#include <com/sun/star/chart/ErrorBarStyle.hpp>
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
#include <com/sun/star/lang/XServiceName.hpp>
+#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
+
+#include <unotools/ucbstreamhelper.hxx>
+#include <rtl/strbuf.hxx>
+
+#include <libxml/xpathInternals.h>
+#include <libxml/parserInternals.h>
using uno::Reference;
using beans::XPropertySet;
@@ -19,19 +26,54 @@ using beans::XPropertySet;
class Chart2ExportTest : public ChartTest
{
public:
+ Chart2ExportTest() : ChartTest() {}
void test();
void testErrorBarXLSX();
void testTrendline();
-
void testStockChart();
+ void testBarChart();
CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(test);
CPPUNIT_TEST(testErrorBarXLSX);
CPPUNIT_TEST(testTrendline);
-// CPPUNIT_TEST(testStockChart); disable pending necessary patch from gerrit 6957
+ CPPUNIT_TEST(testStockChart); disable pending necessary patch from gerrit 6957
+ CPPUNIT_TEST(testBarChart);
+
CPPUNIT_TEST_SUITE_END();
+protected:
+ /**
+ * 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.
+ */
+ xmlDocPtr parseExport(const OUString& rStreamName);
+
+ /**
+ * Helper method to return nodes represented by rXPath.
+ */
+ xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath);
+
+ /**
+ * Assert that rXPath exists, and returns exactly one node.
+ * In case rAttribute is provided, the rXPath's attribute's value must
+ * equal to the rExpected value.
+ */
+ void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute = OString(), const OUString& rExpectedValue = OUString());
+
+ /**
+ * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes.
+ * Useful for checking that we do _not_ export some node (nNumberOfNodes == 0).
+ */
+ void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes);
+
+ /**
+ * Same as the assertXPath(), but don't assert: return the string instead.
+ */
+ OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute);
+
private:
};
@@ -41,6 +83,69 @@ void Chart2ExportTest::test()
reload("Calc Office Open XML");
}
+xmlDocPtr Chart2ExportTest::parseExport(const OUString& rStreamName)
+{
+ if (!m_bExported)
+ return 0;
+ utl::TempFile aTempFile = reload("Office Open XML Text");
+
+ // Read the XML stream we're interested in.
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), aTempFile.GetURL());
+ uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(rStreamName), uno::UNO_QUERY);
+ boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
+ pStream->Seek(STREAM_SEEK_TO_END);
+ sal_Size nSize = pStream->Tell();
+ pStream->Seek(0);
+ OStringBuffer aDocument(nSize);
+ char ch;
+ for (sal_Size i = 0; i < nSize; ++i)
+ {
+ *pStream >> ch;
+ aDocument.append(ch);
+ }
+
+ // Parse the XML.
+ return xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength());
+}
+
+xmlNodeSetPtr Chart2ExportTest::getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
+{
+ xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml"));
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/chart"));
+ xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
+ return pXmlXpathObj->nodesetval;
+}
+
+void Chart2ExportTest::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue)
+{
+ OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ OString("Attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(),
+ rExpectedValue, aValue);
+}
+
+void Chart2ExportTest::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes)
+{
+ xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+ nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
+}
+
+OUString Chart2ExportTest::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute)
+{
+ xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+ 1, xmlXPathNodeSetGetLength(pXmlNodes));
+ if (rAttribute.isEmpty())
+ return OUString();
+ xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+ return OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
+}
+
namespace {
void testErrorBar( Reference< XPropertySet > xErrorBar )
@@ -258,7 +363,6 @@ void Chart2ExportTest::testTrendline()
}
-#if 0 // disable until gerrit 6957 is merged in some form */
void Chart2ExportTest::testStockChart()
{
/* For attached file Stock_Chart.docx, in chart1.xml,
@@ -269,16 +373,26 @@ void Chart2ExportTest::testStockChart()
* Which was problem area.
*/
load("/chart2/qa/extras/data/docx/", "testStockChart.docx");
- {
- xmlDocPtr pXmlDoc = parseExport("word/charts/chart1.xml");
- if (!pXmlDoc)
- return;
- assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:idx", "val", "1");
- assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:order", "val", "1");
- assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v", "Open");
- }
+
+ xmlDocPtr pXmlDoc = parseExport("word/charts/chart1.xml");
+ if (!pXmlDoc)
+ return;
+
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:idx", "val", "1");
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:order", "val", "1");
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v", "Open");
}
-#endif
+
+void Chart2ExportTest::testBarChart()
+{
+ load("/chart2/qa/extras/data/docx/", "testBarChart.docx");
+ xmlDocPtr pXmlDoc = parseExport("word/charts/chart1.xml");
+ if (!pXmlDoc)
+ return;
+
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:barDir", "val", "col");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx
index 637cfe07a9f0..fdabb9c0b654 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -40,29 +40,60 @@
#include <com/sun/star/chart/XChartDocument.hpp>
#include <iostream>
+#include <libxml/xmlwriter.h>
+#include <libxml/xpath.h>
+
using namespace com::sun::star;
using namespace com::sun::star::uno;
+
class ChartTest : public test::BootstrapFixture, public unotest::MacrosTest
{
public:
+ ChartTest()
+ : mServiceName(),
+ m_bExported(false)
+ {
+ }
void load( const char* pDir, const char* pName );
- void reload( const OUString& rFilterName );
+ utl::TempFile reload( const OUString& rFilterName );
uno::Sequence < OUString > getImpressChartColumnDescriptions( const char* pDir, const char* pName );
+ OUString getFileExtension( const char* pName );
+ void loadDocx(const char* pDir, const char* pName);
+ utl::TempFile reloadDocx();
virtual void setUp();
virtual void tearDown();
+
protected:
Reference< lang::XComponent > mxComponent;
-};
+ const char* mServiceName;
+ bool m_bExported; ///< Does m_aTempFile already contain something useful?
+};
+OUString ChartTest::getFileExtension( const char* pName )
+{
+ OUString fileName = OUString::createFromAscii(pName);
+ sal_Int32 dotLocation = fileName.lastIndexOf(L'.');
+ return fileName.copy(dotLocation);
+}
void ChartTest::load( const char* pDir, const char* pName )
{
- mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.sheet.SpreadsheetDocument");
+ OUString extension = getFileExtension(pName);
+ if(extension.equals("ods"))
+ {
+ mServiceName = "com.sun.star.sheet.SpreadsheetDocument";
+ }
+ else if(extension.equals("docx"))
+ {
+ mServiceName = "com.sun.star.text.TextDocument";
+
+ }
+ mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), mServiceName);
CPPUNIT_ASSERT(mxComponent.is());
}
-void ChartTest::reload(const OUString& rFilterName)
+utl::TempFile ChartTest::reload(const OUString& rFilterName)
{
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aArgs(1);
@@ -72,9 +103,10 @@ void ChartTest::reload(const OUString& rFilterName)
aTempFile.EnableKillingFile();
xStorable->storeToURL(aTempFile.GetURL(), aArgs);
mxComponent->dispose();
- mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument");
+ mxComponent = loadFromDesktop(aTempFile.GetURL(), mServiceName);
std::cout << aTempFile.GetURL();
CPPUNIT_ASSERT(mxComponent.is());
+ return aTempFile;
}
void ChartTest::setUp()
diff --git a/chart2/qa/extras/data/docx/testBarChart.docx b/chart2/qa/extras/data/docx/testBarChart.docx
new file mode 100644
index 000000000000..b92260f71848
--- /dev/null
+++ b/chart2/qa/extras/data/docx/testBarChart.docx
Binary files differ