summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-09-12 13:29:46 +0200
committerJan Holesovsky <kendy@collabora.com>2017-09-13 08:42:48 +0200
commit3563220f048da5e0e893b8ac7faf5e8f14889fa5 (patch)
tree14e9a362d590c2673f6cc16694db4d64c3bf3119
parenttdf#112191: Don't export bullets when only one paragraph is selected. (diff)
downloadcore-3563220f048da5e0e893b8ac7faf5e8f14889fa5.tar.gz
core-3563220f048da5e0e893b8ac7faf5e8f14889fa5.zip
tdf#112191: Unit test.
This was the hard part of the fix :-) Change-Id: Iae335c9d41d9b3420472b5d02113e2b42ab825da Reviewed-on: https://gerrit.libreoffice.org/42203 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r--sw/qa/extras/txtexport/txtexport.cxx63
1 files changed, 63 insertions, 0 deletions
diff --git a/sw/qa/extras/txtexport/txtexport.cxx b/sw/qa/extras/txtexport/txtexport.cxx
index b9cd02bdf0b5..59e64d215872 100644
--- a/sw/qa/extras/txtexport/txtexport.cxx
+++ b/sw/qa/extras/txtexport/txtexport.cxx
@@ -11,8 +11,41 @@
#include <swmodule.hxx>
#include <swdll.hxx>
+
+#include <shellio.hxx>
+#include <unotextrange.hxx>
#include <usrpref.hxx>
+class TxtImportTest : public SwModelTestBase
+{
+public:
+ TxtImportTest() :
+ SwModelTestBase("/sw/qa/extras/txtexport/data/", "Text")
+ {}
+
+ // Export & assert part of the document (defined by SwPaM).
+ void assertExportedRange(const OString& aExpected, SwPaM& rPaM)
+ {
+ WriterRef rAsciiWriter;
+ GetASCWriter(aEmptyOUStr, OUString(), rAsciiWriter);
+ CPPUNIT_ASSERT(rAsciiWriter.is());
+
+ // no start char
+ rAsciiWriter->bUCS2_WithStartChar = false;
+
+ SvMemoryStream aMemoryStream;
+
+ SwWriter aWriter(aMemoryStream, rPaM);
+ ErrCode nError = aWriter.Write(rAsciiWriter);
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, nError);
+
+ const char* pData = static_cast<const char*>(aMemoryStream.GetData());
+ OString aResult(pData, aMemoryStream.GetSize());
+
+ CPPUNIT_ASSERT_EQUAL(aExpected, aResult);
+ }
+};
+
class TxtExportTest : public SwModelTestBase
{
public:
@@ -36,6 +69,7 @@ protected:
}
};
+#define DECLARE_TXTIMPORT_TEST(TestName, filename) DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, TxtImportTest)
#define DECLARE_TXTEXPORT_TEST(TestName, filename) DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, TxtExportTest)
DECLARE_TXTEXPORT_TEST(testBullets, "bullets.odt")
@@ -71,6 +105,35 @@ DECLARE_TXTEXPORT_TEST(testBullets, "bullets.odt")
CPPUNIT_ASSERT_EQUAL(aExpected, aData);
}
+DECLARE_TXTIMPORT_TEST(testTdf112191, "bullets.odt")
+{
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ // just the 5th paragraph - no bullet
+ uno::Reference<text::XTextRange> xPara(getParagraph(5));
+ SwUnoInternalPaM aPaM(*pDoc);
+ bool bSuccess = sw::XTextRangeToSwPaM(aPaM, xPara);
+ CPPUNIT_ASSERT(bSuccess);
+
+ assertExportedRange(OString("First bullet"), aPaM);
+
+ // but when we extend to the next paragraph - now there are bullets
+ xPara = getParagraph(6);
+ SwUnoInternalPaM aPaM2(*pDoc);
+ bSuccess = sw::XTextRangeToSwPaM(aPaM2, xPara);
+ CPPUNIT_ASSERT(bSuccess);
+
+ OUString aString = OStringToOUString(
+ " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Second bullet", RTL_TEXTENCODING_UTF8);
+
+ SwPaM aPaM3(*aPaM2.GetMark(), *aPaM.GetPoint());
+ assertExportedRange(OUStringToOString(aString, osl_getThreadTextEncoding()), aPaM3);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */