LCOV - code coverage report
Current view: top level - sw/qa/extras/ooxmlexport - ooxmlfieldexport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 307 307 100.0 %
Date: 2015-06-13 12:38:46 Functions: 666 723 92.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <swmodeltestbase.hxx>
      11             : 
      12             : #include <com/sun/star/awt/XBitmap.hpp>
      13             : #include <com/sun/star/graphic/XGraphic.hpp>
      14             : #include <com/sun/star/frame/XStorable.hpp>
      15             : #include <com/sun/star/drawing/FillStyle.hpp>
      16             : #include <com/sun/star/drawing/LineJoint.hpp>
      17             : #include <com/sun/star/drawing/LineStyle.hpp>
      18             : #include <com/sun/star/drawing/XControlShape.hpp>
      19             : #include <com/sun/star/awt/Gradient.hpp>
      20             : #include <com/sun/star/style/TabStop.hpp>
      21             : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
      22             : #include <com/sun/star/text/RelOrientation.hpp>
      23             : #include <com/sun/star/text/XTextFrame.hpp>
      24             : #include <com/sun/star/text/XTextTable.hpp>
      25             : #include <com/sun/star/text/XTextFramesSupplier.hpp>
      26             : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      27             : #include <com/sun/star/text/XTextSection.hpp>
      28             : #include <com/sun/star/style/CaseMap.hpp>
      29             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      30             : #include <com/sun/star/style/LineSpacing.hpp>
      31             : #include <com/sun/star/style/LineSpacingMode.hpp>
      32             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      33             : #include <com/sun/star/table/BorderLine2.hpp>
      34             : #include <com/sun/star/table/ShadowFormat.hpp>
      35             : #include <com/sun/star/text/GraphicCrop.hpp>
      36             : #include <com/sun/star/text/XPageCursor.hpp>
      37             : #include <com/sun/star/awt/FontWeight.hpp>
      38             : #include <com/sun/star/awt/FontUnderline.hpp>
      39             : #include <com/sun/star/awt/FontSlant.hpp>
      40             : #include <com/sun/star/text/WritingMode2.hpp>
      41             : #include <com/sun/star/text/WrapTextMode.hpp>
      42             : #include <com/sun/star/xml/dom/XDocument.hpp>
      43             : #include <com/sun/star/style/BreakType.hpp>
      44             : #include <unotools/tempfile.hxx>
      45             : #include <comphelper/sequenceashashmap.hxx>
      46             : #include <com/sun/star/text/XDocumentIndex.hpp>
      47             : #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
      48             : #include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
      49             : #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
      50             : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
      51             : #include <com/sun/star/drawing/Hatch.hpp>
      52             : 
      53             : #include <string>
      54             : 
      55         110 : class Test : public SwModelTestBase
      56             : {
      57             : public:
      58         110 :     Test() : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") {}
      59             : 
      60             : protected:
      61             :     /**
      62             :      * Blacklist handling
      63             :      */
      64          55 :     bool mustTestImportOf(const char* filename) const SAL_OVERRIDE {
      65             :         // If the testcase is stored in some other format, it's pointless to test.
      66          55 :         return (OString(filename).endsWith(".docx"));
      67             :     }
      68             : };
      69             : 
      70          17 : DECLARE_OOXMLEXPORT_TEST(testFdo47669, "fdo47669.docx")
      71             : {
      72             :     /*
      73             :      * Problem: we created imbalance </w:hyperlink> which shouldn't be there,
      74             :      * resulting in loading error: missing last character of hyperlink text
      75             :      * and content after it wasn't loaded.
      76             :      */
      77           2 :     getParagraph(1, "This is a hyperlink with anchor. Also, this sentence should be seen.");
      78           2 :     getRun(getParagraph(1), 2, "hyperlink with anchor");
      79           2 :     CPPUNIT_ASSERT_EQUAL(OUString("http://www.google.com/#a"), getProperty<OUString>(getRun(getParagraph(1), 2), "HyperLinkURL"));
      80           2 : }
      81             : 
      82          17 : DECLARE_OOXMLEXPORT_TEST(testN789482, "n789482.docx")
      83             : {
      84             :     // The problem was that w:del was exported before w:hyperlink, resulting in an invalid XML.
      85           2 :     uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
      86           2 :     getRun(xParagraph, 1, "Before. ");
      87             : 
      88           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 2), "RedlineType"));
      89           2 :     CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(getRun(xParagraph, 2), "IsStart"));
      90             : 
      91           2 :     getRun(xParagraph, 3, "www.test.com");
      92           2 :     CPPUNIT_ASSERT_EQUAL(OUString("http://www.test.com/"), getProperty<OUString>(getRun(xParagraph, 3), "HyperLinkURL"));
      93             : 
      94           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 4), "RedlineType"));
      95           2 :     CPPUNIT_ASSERT_EQUAL(sal_False, getProperty<sal_Bool>(getRun(xParagraph, 4), "IsStart"));
      96             : 
      97           2 :     getRun(xParagraph, 5, " After.");
      98           2 : }
      99             : 
     100          16 : DECLARE_OOXMLEXPORT_TEST(testBnc834035, "bnc834035.odt")
     101             : {
     102             :     // Illustration index had wrong hyperlinks: anchor was using Writer's
     103             :     // <seqname>!<index>|sequence syntax, not a bookmark name.
     104           1 :     xmlDocPtr pXmlDoc = parseExport();
     105           1 :     if (!pXmlDoc)
     106           1 :         return;
     107             :     // This was Figure!1|sequence.
     108           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:p[10]/w:hyperlink", "anchor", "_Toc363553908");
     109             : }
     110             : 
     111          16 : DECLARE_OOXMLEXPORT_TEST(testCp1000015, "cp1000015.odt")
     112             : {
     113             :     // Redline and hyperlink end got exported in an incorrect order.
     114           1 :     getParagraph(1, "Hello.");
     115           1 :     getParagraph(2, "http://www.google.com/");
     116           1 : }
     117             : 
     118          17 : DECLARE_OOXMLEXPORT_TEST(testHyperlineIsEnd, "hyperlink.docx")
     119             : {
     120             :     // Check  that the document.xml contents all the tag properly closed.
     121           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     122           2 :     if (!pXmlDoc)
     123           3 :         return;
     124             :     // If  document.xml miss any ending tag then parseExport() returns NULL which fail the test case.
     125           1 :     CPPUNIT_ASSERT(pXmlDoc) ;
     126             :     // Check hyperlink is properly open.
     127           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:hyperlink",1);
     128             : }
     129             : 
     130          17 : DECLARE_OOXMLEXPORT_TEST(testFdo69649, "fdo69649.docx")
     131             : {
     132             :     // The DOCX containing the Table of Contents was not exported with correct page nos
     133           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     134           2 :     if (!pXmlDoc)
     135           3 :         return;
     136             : 
     137           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[21]/w:hyperlink/w:r[5]/w:t", "15");
     138             : }
     139             : 
     140          17 : DECLARE_OOXMLEXPORT_TEST(testFieldFlagO,"TOC_field_f.docx")
     141             : {
     142             :    // This test case is to verify \o flag should come once.
     143           2 :     xmlDocPtr pXmlDoc = parseExport();
     144           2 :     if (!pXmlDoc)
     145           3 :         return;
     146             : 
     147             :     // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
     148             :     // not to insert an empty paragraph before TOC.
     149           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " TOC \\z \\f \\o \"1-3\" \\u \\h");
     150             : }
     151             : 
     152          17 : DECLARE_OOXMLEXPORT_TEST(testTOCFlag_f, "toc_doc.docx")
     153             : {
     154             :     // Export logic for all TOC field flags was enclosed inside
     155             :     // if( nsSwTOXElement::TOX_MARK & pTOX->GetCreateType() ) in ww8atr.cxx which gets true for \f,
     156             :     // this was the reason if there is \f flag present in original doc then only other flags like
     157             :     // \o \h \n used to come after RoundTrip.
     158             :     // This test case is to verify even if there is no \f flag in original doc, \h flag is getting
     159             :     // preserved after RT.
     160           2 :     xmlDocPtr pXmlDoc = parseExport();
     161           2 :     if (!pXmlDoc)
     162           3 :         return;
     163             : 
     164             :     // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
     165             :     // not to insert an empty paragraph before TOC.
     166           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " TOC \\z \\o \"1-3\" \\u \\h");
     167             : }
     168             : 
     169          17 : DECLARE_OOXMLEXPORT_TEST(testPreserveZfield,"preserve_Z_field_TOC.docx")
     170             : {
     171           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     172           2 :     if (!pXmlDoc)
     173           3 :         return;
     174             : 
     175           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[2]/w:instrText", " TOC \\z \\f \\o \"1-3\" \\h");
     176             : }
     177             : 
     178          17 : DECLARE_OOXMLEXPORT_TEST(testPreserveWfieldTOC, "PreserveWfieldTOC.docx")
     179             : {
     180           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     181           2 :     if (!pXmlDoc)
     182           3 :         return;
     183             : 
     184           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\z \\w \\f \\o \"1-3\" \\h");
     185             : }
     186             : 
     187          17 : DECLARE_OOXMLEXPORT_TEST(testFieldFlagB,"TOC_field_b.docx")
     188             : {
     189             :     // This test case is to verify \b flag.
     190           2 :     xmlDocPtr pXmlDoc = parseExport();
     191           2 :     if (!pXmlDoc)
     192           3 :         return;
     193             : 
     194             :     // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
     195             :     // not to insert an empty paragraph before TOC.
     196           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " TOC \\b \"bookmark111\" \\o \"1-9\" \\h");
     197             : }
     198             : 
     199          17 : DECLARE_OOXMLEXPORT_TEST(testPreserveXfieldTOC, "PreserveXfieldTOC.docx")
     200             : {
     201           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     202           2 :     if (!pXmlDoc)
     203           3 :         return;
     204             : 
     205           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\x \\f \\o \"1-3\" \\h");
     206             : }
     207             : 
     208          17 : DECLARE_OOXMLEXPORT_TEST(testFDO77715,"FDO77715.docx")
     209             : {
     210           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     211           2 :     if (!pXmlDoc)
     212           3 :         return;
     213             : 
     214           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:instrText[1]", " TOC \\c ");
     215             : }
     216             : 
     217          17 : DECLARE_OOXMLEXPORT_TEST(testTOCFlag_u,"testTOCFlag_u.docx")
     218             : {
     219             :     // DOCX contaning TOC should preserve code field '\u'.
     220           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     221           2 :     if (!pXmlDoc)
     222           3 :         return;
     223             : 
     224             :     // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
     225             :     // not to insert an empty paragraph before TOC.
     226           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\z \\o \"1-9\" \\u \\h");
     227             : }
     228             : 
     229          17 : DECLARE_OOXMLEXPORT_TEST(testfdo73596_RunInStyle,"fdo73596_RunInStyle.docx")
     230             : {
     231             :     // INDEX should be preserved.
     232           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     233           2 :     if (!pXmlDoc)
     234           3 :         return;
     235             : 
     236           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText[1]", " INDEX \\e \"");
     237             : }
     238             : 
     239          17 : DECLARE_OOXMLEXPORT_TEST(testfdo73596_AlphaSeparator,"fdo73596_AlphaSeparator.docx")
     240             : {
     241             :     // INDEX flag \h "A" should be preserved.
     242           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     243           2 :     if (!pXmlDoc)
     244           3 :         return;
     245             : 
     246           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText[1]", " INDEX \\h \"A\" \\e \"");
     247             : }
     248             : 
     249          17 : DECLARE_OOXMLEXPORT_TEST(testCaption1, "EquationAsScientificNumbering.docx")
     250             : {
     251             :     // fdo#74431 : This test case is to verify the Captions are coming properly
     252             :     // earlier it was coming as "SEQ "scientific"\*ROMAN now it is SEQ scientific\* ROMAN"
     253             : 
     254           2 :     xmlDocPtr pXmlDoc = parseExport();
     255           2 :     if (!pXmlDoc)
     256           3 :         return;
     257             : 
     258           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:instrText", " SEQ scientific \\* ROMAN ");
     259             : }
     260             : 
     261          17 : DECLARE_OOXMLEXPORT_TEST(testCaption2, "EquationWithAboveAndBelowCaption.docx")
     262             : {
     263             :     // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
     264             :     // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
     265           2 :     xmlDocPtr pXmlDoc = parseExport();
     266           2 :     if (!pXmlDoc)
     267           3 :         return;
     268             : 
     269           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[5]/w:r[3]/w:instrText", " SEQ Equation \\* ARABIC ");
     270             : }
     271             : 
     272          17 : DECLARE_OOXMLEXPORT_TEST(testCaption3, "FigureAsLabelPicture.docx")
     273             : {
     274             :     // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
     275             :     // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
     276           2 :     xmlDocPtr pXmlDoc = parseExport();
     277           2 :     if (!pXmlDoc)
     278           3 :         return;
     279             : 
     280           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[3]/w:instrText", " SEQ picture \\* ARABIC ");
     281             : }
     282             : 
     283          17 : DECLARE_OOXMLEXPORT_TEST(testCaption4, "TableWithAboveCaptions.docx")
     284             : {
     285             :     // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
     286             :     // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
     287           2 :     xmlDocPtr pXmlDoc = parseExport();
     288           2 :     if (!pXmlDoc)
     289           3 :         return;
     290             : 
     291           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:instrText", " SEQ Table \\* ARABIC ");
     292             : }
     293             : 
     294          17 : DECLARE_OOXMLEXPORT_TEST(testFooterContainHyperlink,"footer-contain-hyperlink.docx")
     295             : {
     296             :     // Problem is that footer1.xml.rels contains the empty
     297             :     // Target due to which the file get corrupted
     298             :     // in MS Office 2007.
     299             :     // Check for footer1.xml.rels file.
     300           2 :     xmlDocPtr pXmlRels = parseExport("word/_rels/footer1.xml.rels");
     301           2 :     if (!pXmlRels)
     302           3 :         return;
     303             :     // Check the value of Target which is http://www.google.com/.
     304           1 :     assertXPath(pXmlRels,"/rels:Relationships/rels:Relationship","Target","http://www.google.com/");
     305             : }
     306             : 
     307          17 : DECLARE_OOXMLEXPORT_TEST(testAlphabeticalIndex_MultipleColumns,"alphabeticalIndex_MultipleColumns.docx")
     308             : {
     309             :     // Bug :: fdo#73596
     310             :     /*
     311             :      * Index with multiple columns was not imported correctly and
     312             :      * hence not exported correctly...
     313             :      * The column count is given by the \c switch.
     314             :      * If the column count is explicitly specified,
     315             :      * MS Office adds section breaks before and after the Index.
     316             :      */
     317           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     318           2 :     if (!pXmlDoc)
     319           3 :         return;
     320             : 
     321           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:instrText", " INDEX \\c \"4\"\\e \"");
     322             : 
     323             :     // check for section breaks after and before the Index Section
     324           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:sectPr/w:type","val","continuous");
     325           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:sectPr/w:type","val","continuous");
     326             :     // check for "w:space" attribute for the columns in Section Properties
     327           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:sectPr/w:cols/w:col[1]","space","720");
     328             : }
     329             : 
     330          17 : DECLARE_OOXMLEXPORT_TEST(testPageref, "testPageref.docx")
     331             : {
     332             :     // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
     333             :     // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
     334           2 :     xmlDocPtr pXmlDoc = parseExport();
     335           2 :     if (!pXmlDoc)
     336           3 :         return;
     337             : 
     338           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:hyperlink/w:r[3]/w:instrText", "PAGEREF _Toc355095261 \\h");
     339             : }
     340             : 
     341          17 : DECLARE_OOXMLEXPORT_TEST(testAlphabeticalIndex_AutoColumn,"alphabeticalIndex_AutoColumn.docx")
     342             : {
     343             :     // Bug :: fdo#73596
     344             :     /*
     345             :      * When the columns in Index are 0; i.e not specified by the
     346             :      * "\c" switch, don't write back '\c "0"' or the section breaks
     347             :      * before and after the Index Context
     348             :      */
     349           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     350           2 :     if (!pXmlDoc)
     351           3 :         return;
     352             : 
     353           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " INDEX \\e \"");
     354             : 
     355             :     // check for section break doestn't appear for any paragraph
     356           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:sectPr", 0);
     357             : }
     358             : 
     359          17 : DECLARE_OOXMLEXPORT_TEST(testIndexFieldFlagF,"IndexFieldFlagF.docx")
     360             : {
     361             :     // This test case is to verify the Index field flag '\f' with some
     362             :     // Specific Entry Type (ex. "Syn" in our case).
     363           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     364           2 :     if (!pXmlDoc)
     365           3 :         return;
     366             :     // We check the Index field flag '\f'.
     367           1 :     assertXPathContent(pXmlDoc, "/w:document[1]/w:body[1]/w:p[4]/w:r[2]/w:instrText[1]", " INDEX \\c \"2\"\\f \"Syn\" \" \\e \"");
     368             : }
     369             : 
     370          17 : DECLARE_OOXMLEXPORT_TEST(testBibliography,"FDO75133.docx")
     371             : {
     372           2 :     xmlDocPtr pXmlDoc = parseExport();
     373           2 :     if (!pXmlDoc)
     374           3 :         return;
     375             : 
     376           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " BIBLIOGRAPHY ");
     377           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartGallery", "val", "Bibliographies");
     378           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartUnique", 1);
     379             : }
     380             : 
     381          17 : DECLARE_OOXMLEXPORT_TEST(testGenericTextField, "Unsupportedtextfields.docx")
     382             : {
     383             :     // fdo#75158 : This test case is to verify the unsupported textfields are exported properly.
     384             : 
     385           2 :     xmlDocPtr pXmlDoc = parseExport();
     386           2 :     if (!pXmlDoc)
     387           3 :         return;
     388           1 :     xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[2]/w:r[2]/w:instrText");
     389           1 :     xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
     390           1 :     xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
     391           1 :     OUString contents = OUString::createFromAscii(reinterpret_cast<char*>((pXmlNode->children[0]).content));
     392           1 :     CPPUNIT_ASSERT(contents.match("PRINTDATE   \\* MERGEFORMAT"));
     393           1 :     xmlXPathFreeObject(pXmlObj);
     394             : }
     395             : 
     396          17 : DECLARE_OOXMLEXPORT_TEST(test_FieldType, "99_Fields.docx")
     397             : {
     398           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     399           2 :     if (!pXmlDoc)
     400           3 :         return;
     401             :     // Checking for three field types (BIBLIOGRAPHY, BIDIOUTLINE, CITATION) in sequence
     402           1 :     assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[2]/w:r[2]/w:instrText[1]",1);
     403           1 :     assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[5]/w:r[2]/w:instrText[1]",1);
     404           1 :     assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p/w:sdt/w:sdtContent/w:r[2]/w:instrText[1]",1);
     405             : }
     406             : 
     407          17 : DECLARE_OOXMLEXPORT_TEST(testCitation,"FDO74775.docx")
     408             : {
     409           2 :     xmlDocPtr pXmlDoc = parseExport();
     410           2 :     if (!pXmlDoc)
     411           3 :         return;
     412           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:sdt/w:sdtContent/w:r[2]/w:instrText", " CITATION Kra06 \\l 1033 ");
     413           1 :     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:sdt/w:sdtContent/w:r[4]/w:t", "(Kramer & Chen, 2006)");
     414             : }
     415             : 
     416          17 : DECLARE_OOXMLEXPORT_TEST(testHyperLinkTagEnded, "fdo76316.docx")
     417             : {
     418             :     /* XML tag <w:hyperlink> was not getting closed when its inside another
     419             :      * <w:hyperlink> tag.
     420             :      */
     421           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     422             : 
     423           4 :     if (!pXmlDoc) return;
     424             : 
     425           1 :     CPPUNIT_ASSERT(pXmlDoc);
     426           1 :     assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[1]/w:tr[2]/w:tc[1]/w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]/w:tr[7]/w:tc[1]/w:tbl[1]/w:tr[2]/w:tc[6]/w:tbl[1]/w:tr[1]/w:tc[1]/w:p[1]/w:hyperlink[1]/w:hyperlink[1]",1);
     427             : }
     428             : 
     429          17 : DECLARE_OOXMLEXPORT_TEST(testFDO76163 , "fdo76163.docx")
     430             : {
     431           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     432           2 :     if (!pXmlDoc)
     433           3 :         return;
     434             :     //docx file after RT is getting corrupted.
     435           1 :     assertXPath ( pXmlDoc, "/w:document/w:body/w:p[2]/w:hyperlink/w:r[11]/w:fldChar", "fldCharType", "end" );
     436             : }
     437             : 
     438          17 : DECLARE_OOXMLEXPORT_TEST(testFDO78659, "fdo78659.docx")
     439             : {
     440           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     441           2 :     if (!pXmlDoc)
     442           3 :         return;
     443             : 
     444           1 :     assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[1]/w:tr[1]/w:tc[1]/w:p[1]/w:hyperlink[1]/w:r[3]/w:fldChar[1]", 0);
     445             : }
     446             : 
     447          17 : DECLARE_OOXMLEXPORT_TEST(testFDO78654 , "fdo78654.docx")
     448             : {
     449           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     450           2 :     if (!pXmlDoc)
     451           3 :         return;
     452             :     // In case of two "Hyperlink" tags in one paragraph and one of them
     453             :     // contains "PAGEREF" field then field end tag was missing from hyperlink.
     454           1 :     assertXPath ( pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:hyperlink[3]/w:r[5]/w:fldChar", "fldCharType", "end" );
     455             : }
     456             : 
     457             : 
     458          17 : DECLARE_OOXMLEXPORT_TEST(testfdo78599,"fdo78599.docx")
     459             : {
     460           2 :      xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     461           2 :     if (!pXmlDoc)
     462           3 :         return;
     463             :     //docx file after RT is getting corrupted.
     464           1 :     assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:fldChar", "fldCharType", "end" );
     465             : 
     466             :     // Check for automatic hyphenation
     467           1 :     if (xmlDocPtr pSettingsXml = parseExport("word/settings.xml"))
     468             :         // This failed as w:settings had no w:autoHyphenation child.
     469           1 :         assertXPath(pSettingsXml, "/w:settings/w:autoHyphenation");
     470             : }
     471             : 
     472          17 : DECLARE_OOXMLEXPORT_TEST(testfdo78886, "fdo78886.docx")
     473             : {
     474           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     475           2 :     if (!pXmlDoc)
     476           3 :         return;
     477             : 
     478           1 :     assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[2]/w:tr[1]/w:tc[1]/w:p[1]/w:hyperlink[1]/w:r[2]/w:fldChar[1]", 0);
     479             : }
     480             : 
     481          17 : DECLARE_OOXMLEXPORT_TEST(testFdo78910, "fdo78910.docx")
     482             : {
     483           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     484             : 
     485           2 :     if (!pXmlDoc)
     486           3 :         return;
     487             : 
     488             :     // This is to ensure that the fld starts and ends inside a hyperlink...
     489           1 :     assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[1]/w:fldChar", "fldCharType", "begin" );
     490           1 :     assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[5]/w:fldChar", "fldCharType", "end" );
     491             : }
     492             : 
     493          17 : DECLARE_OOXMLEXPORT_TEST(testFDO78590, "FDO78590.docx")
     494             : {
     495           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     496             : 
     497           2 :     if (!pXmlDoc)
     498           3 :         return;
     499             : 
     500             :     // This is to ensure that the fld starts and ends inside a hyperlink...
     501           1 :     assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "w", "9851" );
     502           1 :     assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "h", "1669" );
     503             : }
     504             : 
     505          17 : DECLARE_OOXMLEXPORT_TEST(testSdtCitationRun, "sdt-citation-run.docx")
     506             : {
     507             :     // The problem was that the SDT was around the whole paragraph, not only around the citation field.
     508           2 :     if (xmlDocPtr pXmlDoc = parseExport())
     509             :     {
     510           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:t", "Before sdt.");
     511           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:instrText", " CITATION BBC11 \\l 1033 ");
     512           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:t", "After sdt.");
     513             :     }
     514           2 : }
     515             : 
     516          17 : DECLARE_OOXMLEXPORT_TEST(testParagraphSdt, "paragraph-sdt.docx")
     517             : {
     518             :     // The problem was that the SDT was around the run only, not the whole paragraph.
     519           2 :     if (xmlDocPtr pXmlDoc = parseExport())
     520             :     {
     521             :         // The path to w:sdt contained a w:p.
     522           1 :         assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:sdt");
     523             :     }
     524           2 : }
     525             : 
     526          17 : DECLARE_OOXMLEXPORT_TEST(testSdt2Run, "sdt-2-para.docx")
     527             : {
     528           2 :     if (xmlDocPtr pXmlDoc = parseExport())
     529             :     {
     530             :         // The problem was that <w:sdt> was closed after "first", not after "second", so the second assert failed.
     531           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r/w:t", "first");
     532           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:r/w:t", "second");
     533             :         // Make sure the third paragraph is still outside <w:sdt>.
     534           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r/w:t", "third");
     535             :     }
     536           2 : }
     537             : 
     538          17 : DECLARE_OOXMLEXPORT_TEST(test2Id, "2-id.docx")
     539             : {
     540           2 :     if (xmlDocPtr pXmlDoc = parseExport())
     541             :     {
     542             :         // This was 2, but only one w:id is allowed.
     543           1 :         assertXPath(pXmlDoc, "//w:sdtPr/w:id", 1);
     544             :     }
     545           2 : }
     546             : 
     547          17 : DECLARE_OOXMLEXPORT_TEST(testTableStart2Sdt, "table-start-2-sdt.docx")
     548             : {
     549           2 :     if (xmlDocPtr pXmlDoc = parseExport())
     550             :     {
     551             :         // w:docPartGallery should be a child of <w:docPartObj>, make sure it's not a child of w:text.
     552           1 :         assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:text/w:docPartGallery", 0);
     553             :     }
     554           2 : }
     555             : 
     556          17 : DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx")
     557             : {
     558           2 :     if (xmlDocPtr pXmlDoc = parseExport())
     559             :     {
     560             :         // Single <w:sdt> was exported as 2 <w:sdt> elements.
     561           1 :         assertXPath(pXmlDoc, "//w:sdt", 1);
     562             :     }
     563           2 : }
     564             : 
     565          17 : DECLARE_OOXMLEXPORT_TEST(testFdo81492, "fdo81492.docx")
     566             : {
     567           2 :     if (xmlDocPtr pXmlDoc = parseExport())
     568           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[5]/w:instrText", "ADDIN EN.CITE.DATA");
     569           2 : }
     570             : 
     571          17 : DECLARE_OOXMLEXPORT_TEST(testEditTime, "fdo81341.docx")
     572             : {
     573             :     /* Issue was LO was not able to Import and Export EditTime in seconds format.
     574             :      * It was supporting Time in "HH:MM" format. But if DOCX conatins Time in seconds,
     575             :      * then LO was not able to display time in "HH:MM:SS" format.
     576             :      * While exporting LO was writing plian text instead of field entry.
     577             :      */
     578           2 :     if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
     579             :     {
     580             :         //Ensure that EditTime is written inside w:fldChar in "HH:MM:SS" format.
     581           1 :         assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:fldChar", "fldCharType", "begin");
     582           1 :         assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:fldChar", "fldCharType", "separate");
     583           1 :         assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[4]/w:t", "00:05");
     584           1 :         assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[5]/w:fldChar", "fldCharType", "end");
     585             :     }
     586           2 : }
     587             : 
     588          17 : DECLARE_OOXMLEXPORT_TEST(testFdo81945, "fdo81945.docx")
     589             : {
     590           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     591           2 :     if (!pXmlDoc)
     592           3 :         return;
     593             : 
     594           1 :     assertXPath(pXmlDoc, "//w:sdt//w:sdt", 0);
     595             : }
     596             : 
     597          17 : DECLARE_OOXMLEXPORT_TEST(testfdo82123, "fdo82123.docx")
     598             : {
     599           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     600           2 :     if (!pXmlDoc)
     601           3 :        return;
     602             : 
     603             :     // make sure there is only one run inside first SDT after RT as in the Original file.
     604           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:p/w:sdt[1]/w:sdtContent/w:r",1);
     605             : }
     606             : 
     607          17 : DECLARE_OOXMLEXPORT_TEST(testSdtBeforeField, "sdt-before-field.docx")
     608             : {
     609           2 :     if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
     610             :     {
     611             :         // Make sure the field doesn't sneak inside the SDT: the SDT should contain only a single run (there were 6 ones).
     612           1 :         assertXPath(pXmlDoc, "//w:sdt/w:sdtContent/w:r", 1);
     613             :     }
     614           2 : }
     615             : 
     616          17 : DECLARE_OOXMLEXPORT_TEST(testfdo81946, "fdo81946.docx")
     617             : {
     618           2 :     xmlDocPtr pXmlDoc = parseExport("word/header1.xml");
     619           2 :     if (!pXmlDoc)
     620           3 :        return;
     621             :     // make sure AlternateContent should not present in sdt
     622           1 :     assertXPath(pXmlDoc, "/w:hdr[1]/w:p[1]/w:sdt[1]/w:sdtContent[1]/w:r[2]/mc:AlternateContent[1]",0);
     623             : }
     624             : 
     625          17 : DECLARE_OOXMLEXPORT_TEST(testfdo82492, "fdo82492.docx")
     626             : {
     627           2 :     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     628           2 :     if (!pXmlDoc)
     629           3 :        return;
     630             : 
     631             :     // make sure there is only one run inside first SDT after RT as in the Original file.
     632           1 :     assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt[1]/w:sdtContent/w:r",1);
     633             : }
     634             : 
     635          17 : DECLARE_OOXMLEXPORT_TEST(testSdtHeader, "sdt-header.docx")
     636             : {
     637             :     // Problem was that w:sdt elements in headers were lost on import.
     638           2 :     if (xmlDocPtr pXmlDoc = parseExport("word/header1.xml"))
     639             :         // This was 0, w:sdt (and then w:date) was missing.
     640           1 :         assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date", 1);
     641           2 : }
     642             : 
     643          17 : DECLARE_OOXMLEXPORT_TEST(testSdtCompanyMultipara, "sdt-company-multipara.docx")
     644             : {
     645           2 :     if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
     646             :     {
     647             :         // This was 3, but multiple paragraphs inside "Company" SDT is now allowed.
     648           1 :         assertXPath(pXmlDoc, "//w:sdtContent/w:p", 1);
     649             :     }
     650           2 : }
     651             : 
     652          17 : DECLARE_OOXMLEXPORT_TEST(testFixedDateFields, "fixed-date-field.docx")
     653             : {
     654           2 :     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
     655           4 :     uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
     656           4 :     uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
     657           4 :     uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY);
     658             : 
     659             :     // Check fixed property was imported and date value was parsed correctly
     660           2 :     CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xField, "IsFixed"));
     661           2 :     com::sun::star::util::DateTime date = getProperty<com::sun::star::util::DateTime>(xField, "DateTimeValue");
     662           2 :     CPPUNIT_ASSERT_EQUAL((sal_uInt16)24, date.Day);
     663           2 :     CPPUNIT_ASSERT_EQUAL((sal_uInt16)7, date.Month);
     664           2 :     CPPUNIT_ASSERT_EQUAL((sal_Int16)2014, date.Year);
     665             : 
     666           2 :     if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
     667             :     {
     668             :         // Previously, fixed fields were exported as static text ("Date (fixed)")
     669             :         // Check they are now exported correctly as fldChar with fldLock attribute
     670           1 :         assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:fldChar", "fldLock", "true");
     671           2 :     }
     672           2 : }
     673             : 
     674          16 : DECLARE_OOXMLEXPORT_TEST(testOO34469, "ooo34469-1.odt")
     675             : {
     676           1 :     if (xmlDocPtr pXmlDoc = parseExport())
     677           1 :         assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink[1]", "anchor", "2.9.2.Creating New files|outline");
     678           1 : }
     679             : 
     680          16 : DECLARE_OOXMLEXPORT_TEST(testOO39845, "ooo39845-7.odt")
     681             : {
     682           1 :     if (xmlDocPtr pXmlDoc = parseExport())
     683           1 :         assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink[1]", "anchor", "Figure4|graphic");
     684           1 : }
     685             : 
     686             : 
     687           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     688             : 
     689             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11