From 39dd9b64ddb0afefab88c8d6627c9f9c13b4ed37 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 19 Feb 2013 21:03:48 +0100 Subject: testcase for 349e9248f801d23735478abafe5328f79dfe4378 Change-Id: I27ca3b21427cb4d6e6b54ae5f0b3b86e18b550a2 --- sw/qa/extras/ooxmlexport/data/cell-btlr.docx | Bin 0 -> 4392 bytes sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 62 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 sw/qa/extras/ooxmlexport/data/cell-btlr.docx (limited to 'sw/qa') diff --git a/sw/qa/extras/ooxmlexport/data/cell-btlr.docx b/sw/qa/extras/ooxmlexport/data/cell-btlr.docx new file mode 100644 index 000000000000..f05f114da095 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/cell-btlr.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index d39489a9b7aa..433160fd4a07 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -41,8 +41,13 @@ #include #include +#include +#include #include +#include +#include + class Test : public SwModelTestBase { public: @@ -74,6 +79,7 @@ public: void testTextFrames(); void testTextFrameBorders(); void testTextframeGradient(); + void testCellBtlr(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -116,6 +122,7 @@ void Test::run() {"textframes.odt", &Test::testTextFrames}, {"textframe-borders.docx", &Test::testTextFrameBorders}, {"textframe-gradient.docx", &Test::testTextframeGradient}, + {"cell-btlr.docx", &Test::testCellBtlr}, }; // Don't test the first import of these, for some reason those tests fail const char* aBlacklist[] = { @@ -564,6 +571,61 @@ void Test::testTextframeGradient() CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style); } +void Test::testCellBtlr() +{ + /* + * The problem was that the exporter didn't mirror the workaround of the + * importer, regarding the btLr text direction: the token was completely missing in the output. + * + * Given that this 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 can be extracted to a helper + * method, once it's clear what is common in such tests. + */ + + // Create the zip file. + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + uno::Sequence aFilterArgs(1); + aFilterArgs[0].Name = "FilterName"; + aFilterArgs[0].Value <<= OUString("Office Open XML Text"); + xStorable->storeToURL(aTempFile.GetURL(), aFilterArgs); + + // Read the XML stream we're interested in. + uno::Sequence aArgs(1); + aArgs[0] <<= OUString(aTempFile.GetURL()); + uno::Reference xNameAccess(m_xSFactory->createInstanceWithArguments("com.sun.star.packages.zip.ZipFileAccess", aArgs), uno::UNO_QUERY); + uno::Reference xInputStream(xNameAccess->getByName("word/document.xml"), uno::UNO_QUERY); + boost::shared_ptr 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. + xmlDocPtr pXmlDoc = xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength()); + + // Assert the XPath expression. + xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main")); + OString aXPath = "/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:textDirection"; + xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathCtx); + xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval; + CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes)); + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + OString aAttribute = "val"; + OUString aValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttribute.getStr()))); + CPPUNIT_ASSERT_EQUAL(OUString("btLr"), aValue); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit