Kaydet (Commit) 3563220f authored tarafından Jan Holesovsky's avatar Jan Holesovsky

tdf#112191: Unit test.

This was the hard part of the fix :-)

Change-Id: Iae335c9d41d9b3420472b5d02113e2b42ab825da
Reviewed-on: https://gerrit.libreoffice.org/42203Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst 9ead8726
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment