[Libreoffice-commits] core.git: sw/inc sw/Library_msword.mk sw/Library_sw.mk sw/qa sw/source

Szymon Kłos szymon.klos at collabora.com
Wed May 3 18:06:04 UTC 2017


 sw/Library_msword.mk                              |    1 
 sw/Library_sw.mk                                  |    1 
 sw/inc/shellio.hxx                                |    1 
 sw/qa/extras/uiwriter/data/autotext-empty.dotx    |binary
 sw/qa/extras/uiwriter/data/autotext-multiple.dotx |binary
 sw/qa/extras/uiwriter/uiwriter.cxx                |   61 ++++++++++++++++++++++
 sw/source/filter/basflt/fltini.cxx                |    5 +
 7 files changed, 68 insertions(+), 1 deletion(-)

New commits:
commit acfda3dd7cab2a27780a162310bd8a457f9bfa33
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Tue May 2 18:02:20 2017 +0200

    AutoText: first tests & windows fix
    
    First tests for AutoText DOCX import:
    + checking if nothing will be imported when
      there is no AutoText, only normal content
    + checking count of loaded entries
    + checking names of entries
    + checking first and last paragraph
    
    Windows fix: Added swdocxreader to msword library
    
    Change-Id: I3cf02572dd85e72b1566ce523e373753a4bd346c
    Reviewed-on: https://gerrit.libreoffice.org/37176
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/sw/Library_msword.mk b/sw/Library_msword.mk
index 3f14c215f62f..c468fbdc8e43 100644
--- a/sw/Library_msword.mk
+++ b/sw/Library_msword.mk
@@ -70,6 +70,7 @@ $(eval $(call gb_Library_use_externals,msword,\
 ))
 
 $(eval $(call gb_Library_add_exception_objects,msword,\
+    sw/source/filter/docx/swdocxreader \
     sw/source/filter/rtf/swparrtf \
     sw/source/filter/ww8/docxattributeoutput \
     sw/source/filter/ww8/docxexport \
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 6b99a22983cb..3c6c671efeb2 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -499,7 +499,6 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/filter/basflt/fltshell \
     sw/source/filter/basflt/iodetect \
     sw/source/filter/basflt/shellio \
-    sw/source/filter/docx/swdocxreader \
     sw/source/filter/html/SwAppletImpl \
     sw/source/filter/html/css1atr \
     sw/source/filter/html/css1kywd \
diff --git a/sw/inc/shellio.hxx b/sw/inc/shellio.hxx
index 7410fe5307ed..a84c73c568fd 100644
--- a/sw/inc/shellio.hxx
+++ b/sw/inc/shellio.hxx
@@ -535,6 +535,7 @@ struct SwReaderWriterEntry
 namespace SwReaderWriter
 {
     SW_DLLPUBLIC Reader* GetRtfReader();
+    SW_DLLPUBLIC Reader* GetDOCXReader();
 
     /// Return reader based on the name.
     Reader* GetReader( const OUString& rFltName );
diff --git a/sw/qa/extras/uiwriter/data/autotext-empty.dotx b/sw/qa/extras/uiwriter/data/autotext-empty.dotx
new file mode 100644
index 000000000000..0d9f51dc2a4a
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/autotext-empty.dotx differ
diff --git a/sw/qa/extras/uiwriter/data/autotext-multiple.dotx b/sw/qa/extras/uiwriter/data/autotext-multiple.dotx
new file mode 100644
index 000000000000..83b083992a08
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/autotext-multiple.dotx differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 2b4764b7b998..89229db942a4 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -120,6 +120,8 @@ public:
     void testFdo70807();
     void testImportRTF();
     void testExportRTF();
+    void testDOCXAutoTextEmpty();
+    void testDOCXAutoTextMultiple();
     void testTdf67238();
     void testFdo75110();
     void testFdo75898();
@@ -248,6 +250,8 @@ public:
     CPPUNIT_TEST(testFdo70807);
     CPPUNIT_TEST(testImportRTF);
     CPPUNIT_TEST(testExportRTF);
+    CPPUNIT_TEST(testDOCXAutoTextEmpty);
+    CPPUNIT_TEST(testDOCXAutoTextMultiple);
     CPPUNIT_TEST(testTdf67238);
     CPPUNIT_TEST(testFdo75110);
     CPPUNIT_TEST(testFdo75898);
@@ -370,6 +374,7 @@ public:
 
 private:
     SwDoc* createDoc(const char* pName = nullptr);
+    SwTextBlocks* readDOCXAutotext(const OUString& sFileName, bool bEmpty = false);
 };
 
 SwDoc* SwUiWriterTest::createDoc(const char* pName)
@@ -384,6 +389,23 @@ SwDoc* SwUiWriterTest::createDoc(const char* pName)
     return pTextDoc->GetDocShell()->GetDoc();
 }
 
+SwTextBlocks* SwUiWriterTest::readDOCXAutotext(const OUString& sFileName, bool bEmpty)
+{
+    OUString rURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + sFileName;
+
+    SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ);
+    SwDoc* pDoc = createDoc();
+
+    SwReader aReader(*pSrcMed, rURL, pDoc);
+    Reader* pDOCXReader = SwReaderWriter::GetDOCXReader();
+    SwTextBlocks* pGlossary = new SwTextBlocks(rURL);
+
+    CPPUNIT_ASSERT(pDOCXReader != nullptr);
+    CPPUNIT_ASSERT_EQUAL(!bEmpty, aReader.ReadGlossaries(*pDOCXReader, *pGlossary, false));
+
+    return pGlossary;
+}
+
 //Replacement tests
 
 static void lcl_selectCharacters(SwPaM& rPaM, sal_Int32 first, sal_Int32 end)
@@ -745,6 +767,45 @@ void SwUiWriterTest::testExportRTF()
     CPPUNIT_ASSERT(aData.endsWith("bbb}" SAL_NEWLINE_STRING "}"));
 }
 
+void SwUiWriterTest::testDOCXAutoTextEmpty()
+{
+    // file contains normal content but no AutoText
+    SwTextBlocks* pGlossary = readDOCXAutotext("autotext-empty.dotx", true);
+    CPPUNIT_ASSERT(pGlossary != nullptr);
+}
+
+void SwUiWriterTest::testDOCXAutoTextMultiple()
+{
+    // file contains three AutoText entries
+    SwTextBlocks* pGlossary = readDOCXAutotext("autotext-multiple.dotx");
+
+    // check entries count
+    CPPUNIT_ASSERT_EQUAL((sal_uInt16)3, pGlossary->GetCount());
+
+    // check names of entries, sorted order
+    CPPUNIT_ASSERT_EQUAL(OUString("Anothercomplex"), pGlossary->GetLongName(0));
+    CPPUNIT_ASSERT_EQUAL(OUString("Multiple"), pGlossary->GetLongName(1));
+    CPPUNIT_ASSERT_EQUAL(OUString("Second  Autotext"), pGlossary->GetLongName(2));
+
+    // check if previously loaded content is correct (eg. doesn't contain title)
+    SwDoc* pDoc = pGlossary->GetDoc();
+    CPPUNIT_ASSERT(pDoc != nullptr);
+
+    SwNodeIndex aDocEnd(pDoc->GetNodes().GetEndOfContent());
+    SwNodeIndex aStart(*aDocEnd.GetNode().StartOfSectionNode(), 1);
+
+    CPPUNIT_ASSERT(aStart < aDocEnd);
+
+    // first line
+    SwNode& rNode = aStart.GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("Another "), rNode.GetTextNode()->GetText());
+
+    // last line
+    SwNodeIndex aLast(*aDocEnd.GetNode().EndOfSectionNode(), -1);
+    SwNode& rLastNode = aLast.GetNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("complex"), rLastNode.GetTextNode()->GetText());
+}
+
 void SwUiWriterTest::testFdo74981()
 {
     // create a document with an input field
diff --git a/sw/source/filter/basflt/fltini.cxx b/sw/source/filter/basflt/fltini.cxx
index 8c46c757e454..a1459c780fa3 100644
--- a/sw/source/filter/basflt/fltini.cxx
+++ b/sw/source/filter/basflt/fltini.cxx
@@ -164,6 +164,11 @@ Reader* GetRtfReader()
     return aReaderWriter[READER_WRITER_RTF].GetReader();
 }
 
+Reader* GetDOCXReader()
+{
+    return aReaderWriter[READER_WRITER_DOCX].GetReader();
+}
+
 void GetWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
 {
     for( int n = 0; n < MAXFILTER; ++n )


More information about the Libreoffice-commits mailing list