Kaydet (Commit) d843d642 authored tarafından Pallavi Jadhav's avatar Pallavi Jadhav Kaydeden (comit) Markus Mohrhard

Added OOXML Unit Test framework for Chart module for export.

- Referred functions from sw module.

Change-Id: I3ae90d40d92de0d67623e73e1676dabcc8a413f6
üst 71b491fd
...@@ -11,7 +11,10 @@ ...@@ -11,7 +11,10 @@
$(eval $(call gb_CppunitTest_CppunitTest,chart2_export)) $(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, \ $(eval $(call gb_CppunitTest_add_exception_objects,chart2_export, \
chart2/qa/extras/chart2export \ chart2/qa/extras/chart2export \
...@@ -50,6 +53,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_export, \ ...@@ -50,6 +53,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_export, \
vbahelper \ vbahelper \
vcl \ vcl \
xo \ xo \
sw \
$(gb_UWINAPI) \ $(gb_UWINAPI) \
)) ))
...@@ -85,6 +89,9 @@ $(eval $(call gb_CppunitTest_use_components,chart2_export,\ ...@@ -85,6 +89,9 @@ $(eval $(call gb_CppunitTest_use_components,chart2_export,\
sc/util/sc \ sc/util/sc \
sc/util/scd \ sc/util/scd \
sc/util/scfilt \ sc/util/scfilt \
sw/util/sw \
sw/util/swd \
sw/util/msword \
$(if $(filter TRUE,$(DISABLE_SCRIPTING)),, \ $(if $(filter TRUE,$(DISABLE_SCRIPTING)),, \
sc/util/vbaobj) \ sc/util/vbaobj) \
scaddins/source/analysis/analysis \ scaddins/source/analysis/analysis \
...@@ -104,6 +111,7 @@ $(eval $(call gb_CppunitTest_use_components,chart2_export,\ ...@@ -104,6 +111,7 @@ $(eval $(call gb_CppunitTest_use_components,chart2_export,\
unotools/util/utl \ unotools/util/utl \
unoxml/source/rdf/unordf \ unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \ unoxml/source/service/unoxml \
writerfilter/util/writerfilter \
xmloff/util/xo \ xmloff/util/xo \
)) ))
......
...@@ -11,7 +11,10 @@ ...@@ -11,7 +11,10 @@
$(eval $(call gb_CppunitTest_CppunitTest,chart2_import)) $(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, \ $(eval $(call gb_CppunitTest_add_exception_objects,chart2_import, \
chart2/qa/extras/chart2import \ chart2/qa/extras/chart2import \
...@@ -52,6 +55,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_import, \ ...@@ -52,6 +55,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_import, \
utl \ utl \
vbahelper \ vbahelper \
xo \ xo \
sw \
$(gb_UWINAPI) \ $(gb_UWINAPI) \
)) ))
......
...@@ -12,6 +12,13 @@ ...@@ -12,6 +12,13 @@
#include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp>
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
#include <com/sun/star/lang/XServiceName.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 uno::Reference;
using beans::XPropertySet; using beans::XPropertySet;
...@@ -19,19 +26,54 @@ using beans::XPropertySet; ...@@ -19,19 +26,54 @@ using beans::XPropertySet;
class Chart2ExportTest : public ChartTest class Chart2ExportTest : public ChartTest
{ {
public: public:
Chart2ExportTest() : ChartTest() {}
void test(); void test();
void testErrorBarXLSX(); void testErrorBarXLSX();
void testTrendline(); void testTrendline();
void testStockChart(); void testStockChart();
void testBarChart();
CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(test); CPPUNIT_TEST(test);
CPPUNIT_TEST(testErrorBarXLSX); CPPUNIT_TEST(testErrorBarXLSX);
CPPUNIT_TEST(testTrendline); 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(); 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: private:
}; };
...@@ -41,6 +83,69 @@ void Chart2ExportTest::test() ...@@ -41,6 +83,69 @@ void Chart2ExportTest::test()
reload("Calc Office Open XML"); 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 { namespace {
void testErrorBar( Reference< XPropertySet > xErrorBar ) void testErrorBar( Reference< XPropertySet > xErrorBar )
...@@ -258,7 +363,6 @@ void Chart2ExportTest::testTrendline() ...@@ -258,7 +363,6 @@ void Chart2ExportTest::testTrendline()
} }
#if 0 // disable until gerrit 6957 is merged in some form */
void Chart2ExportTest::testStockChart() void Chart2ExportTest::testStockChart()
{ {
/* For attached file Stock_Chart.docx, in chart1.xml, /* For attached file Stock_Chart.docx, in chart1.xml,
...@@ -269,16 +373,26 @@ void Chart2ExportTest::testStockChart() ...@@ -269,16 +373,26 @@ void Chart2ExportTest::testStockChart()
* Which was problem area. * Which was problem area.
*/ */
load("/chart2/qa/extras/data/docx/", "testStockChart.docx"); load("/chart2/qa/extras/data/docx/", "testStockChart.docx");
{
xmlDocPtr pXmlDoc = parseExport("word/charts/chart1.xml"); xmlDocPtr pXmlDoc = parseExport("word/charts/chart1.xml");
if (!pXmlDoc) if (!pXmlDoc)
return; 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:idx", "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"); 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_TEST_SUITE_REGISTRATION(Chart2ExportTest);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -40,29 +40,60 @@ ...@@ -40,29 +40,60 @@
#include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/chart/XChartDocument.hpp>
#include <iostream> #include <iostream>
#include <libxml/xmlwriter.h>
#include <libxml/xpath.h>
using namespace com::sun::star; using namespace com::sun::star;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
class ChartTest : public test::BootstrapFixture, public unotest::MacrosTest class ChartTest : public test::BootstrapFixture, public unotest::MacrosTest
{ {
public: public:
ChartTest()
: mServiceName(),
m_bExported(false)
{
}
void load( const char* pDir, const char* pName ); 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 ); 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 setUp();
virtual void tearDown(); virtual void tearDown();
protected: protected:
Reference< lang::XComponent > mxComponent; 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 ) 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()); 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::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aArgs(1); uno::Sequence<beans::PropertyValue> aArgs(1);
...@@ -72,9 +103,10 @@ void ChartTest::reload(const OUString& rFilterName) ...@@ -72,9 +103,10 @@ void ChartTest::reload(const OUString& rFilterName)
aTempFile.EnableKillingFile(); aTempFile.EnableKillingFile();
xStorable->storeToURL(aTempFile.GetURL(), aArgs); xStorable->storeToURL(aTempFile.GetURL(), aArgs);
mxComponent->dispose(); mxComponent->dispose();
mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument"); mxComponent = loadFromDesktop(aTempFile.GetURL(), mServiceName);
std::cout << aTempFile.GetURL(); std::cout << aTempFile.GetURL();
CPPUNIT_ASSERT(mxComponent.is()); CPPUNIT_ASSERT(mxComponent.is());
return aTempFile;
} }
void ChartTest::setUp() void ChartTest::setUp()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment