1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <swmodeltestbase.hxx>
12 class TxtEncExportTest
: public SwModelTestBase
15 TxtEncExportTest(const OUString
& rFilterOptions
)
16 : SwModelTestBase("/sw/qa/extras/txtencexport/data/", "Text (encoded)")
18 setFilterOptions(rFilterOptions
);
22 OString
readExportedFile()
24 SvMemoryStream aMemoryStream
;
25 SvFileStream
aStream(maTempFile
.GetURL(), StreamMode::READ
);
26 aStream
.ReadStream(aMemoryStream
);
27 const char* pData
= static_cast<const char*>(aMemoryStream
.GetData());
30 if (aMemoryStream
.GetSize() > 2 && pData
[0] == '\xEF' && pData
[1] == '\xBB'
31 && pData
[2] == '\xBF')
34 return OString(pData
+ offset
, aMemoryStream
.GetSize() - offset
);
38 #define DECLARE_TXTENCEXPORT_TEST(TestName, filename, filterOptions, ClassName) \
39 class ClassName : public TxtEncExportTest { \
41 ClassName() : TxtEncExportTest(filterOptions) {} \
43 DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, ClassName)
45 DECLARE_TXTENCEXPORT_TEST(testBulletsNotHidden
, "bullets.odt", "UTF8,,,,", TxtEncExportNotHiddenTest
)
47 OString aData
= readExportedFile();
49 OUString aString
= OStringToOUString(
50 "1 Heading 1" SAL_NEWLINE_STRING
"1.A Heading 2" SAL_NEWLINE_STRING
51 "Paragraph" SAL_NEWLINE_STRING
"" SAL_NEWLINE_STRING
52 " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
53 " \xe2\x80\xa2 Second bullet" SAL_NEWLINE_STRING
54 " \xe2\x97\xa6 Sub-second bullet" SAL_NEWLINE_STRING
55 " Third bullet, but deleted" SAL_NEWLINE_STRING
56 " \xe2\x80\xa2 Fourth bullet" SAL_NEWLINE_STRING
"" SAL_NEWLINE_STRING
57 "Numbering" SAL_NEWLINE_STRING
"" SAL_NEWLINE_STRING
" 1. First" SAL_NEWLINE_STRING
58 " 2. Second" SAL_NEWLINE_STRING
" 1. Second-first" SAL_NEWLINE_STRING
59 " Third, but deleted" SAL_NEWLINE_STRING
" 3. Actual third" SAL_NEWLINE_STRING
60 "" SAL_NEWLINE_STRING
"Paragraph after numbering" SAL_NEWLINE_STRING
61 "Next paragraph" SAL_NEWLINE_STRING
"Hidden paragraph" SAL_NEWLINE_STRING
62 "Final paragraph" SAL_NEWLINE_STRING
,
63 RTL_TEXTENCODING_UTF8
);
65 // To get the stuff back in the system's encoding
66 OString
aExpected(OUStringToOString(aString
, RTL_TEXTENCODING_UTF8
));
68 CPPUNIT_ASSERT_EQUAL(aExpected
, aData
);
71 DECLARE_TXTENCEXPORT_TEST(testBulletsHidden
, "bullets.odt", "UTF8,,,,,false", TxtEncExportHiddenTest
)
73 OString aData
= readExportedFile();
75 OUString aString
= OStringToOUString(
76 "1 Heading 1" SAL_NEWLINE_STRING
"1.A Heading 2" SAL_NEWLINE_STRING
77 "Paragraph" SAL_NEWLINE_STRING
"" SAL_NEWLINE_STRING
78 " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
79 " \xe2\x80\xa2 Second bullet" SAL_NEWLINE_STRING
80 " \xe2\x97\xa6 Sub-second bullet" SAL_NEWLINE_STRING
81 " Third bullet, but deleted" SAL_NEWLINE_STRING
82 " \xe2\x80\xa2 Fourth bullet" SAL_NEWLINE_STRING
"" SAL_NEWLINE_STRING
83 "Numbering" SAL_NEWLINE_STRING
"" SAL_NEWLINE_STRING
" 1. First" SAL_NEWLINE_STRING
84 " 2. Second" SAL_NEWLINE_STRING
" 1. Second-first" SAL_NEWLINE_STRING
85 " Third, but deleted" SAL_NEWLINE_STRING
" 3. Actual third" SAL_NEWLINE_STRING
86 "" SAL_NEWLINE_STRING
"Paragraph after numbering" SAL_NEWLINE_STRING
87 "Next paragraph" SAL_NEWLINE_STRING
88 "Final paragraph" SAL_NEWLINE_STRING
,
89 RTL_TEXTENCODING_UTF8
);
91 // To get the stuff back in the system's encoding
92 OString
aExpected(OUStringToOString(aString
, RTL_TEXTENCODING_UTF8
));
94 CPPUNIT_ASSERT_EQUAL(aExpected
, aData
);
97 CPPUNIT_PLUGIN_IMPLEMENT();
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */