summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-05-02 18:02:20 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2017-05-03 20:05:29 +0200
commitacfda3dd7cab2a27780a162310bd8a457f9bfa33 (patch)
tree8dd23edf17e9d3840351f7fe8354f130be3e89f6 /sw
parent946f3f491d3f7e47be6c5b943e725009b4cf2d16 (diff)
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@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/Library_msword.mk1
-rw-r--r--sw/Library_sw.mk1
-rw-r--r--sw/inc/shellio.hxx1
-rw-r--r--sw/qa/extras/uiwriter/data/autotext-empty.dotxbin0 -> 11390 bytes
-rw-r--r--sw/qa/extras/uiwriter/data/autotext-multiple.dotxbin0 -> 18470 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx61
-rw-r--r--sw/source/filter/basflt/fltini.cxx5
7 files changed, 68 insertions, 1 deletions
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
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/autotext-empty.dotx
Binary files 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
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/autotext-multiple.dotx
Binary files 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 )