Debian Codegraph @

sw/qa/extras/txtencexport/txtencexport.cxx

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10 #include <swmodeltestbase.hxx>
11
12 namespace
13 {
14 class TxtEncExportTest : public SwModelTestBase
15 {
16 public:
17 TxtEncExportTest()
18 : SwModelTestBase(u"/sw/qa/extras/txtencexport/data/"_ustr)
19 {
20 }
21
22 protected:
23 OString readExportedFile()
24 {
25 SvMemoryStream aMemoryStream;
26 SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
27 aStream.ReadStream(aMemoryStream);
28 const char* pData = static_cast<const char*>(aMemoryStream.GetData());
29
30 int offset = 0;
31 if (aMemoryStream.GetSize() > 2 && pData[0] == '\xEF' && pData[1] == '\xBB'
32 && pData[2] == '\xBF')
33 offset = 3;
34
35 return OString(pData + offset, aMemoryStream.GetSize() - offset);
36 }
37 };
38
39 CPPUNIT_TEST_FIXTURE(TxtEncExportTest, testBulletsNotHidden)
40 {
41 createSwDoc("bullets.odt");
42 setFilterOptions(u"UTF8,,,,"_ustr);
43 save(TestFilter::TEXT_ENCODED);
44 OString aData = readExportedFile();
45
46 OUString aString = OStringToOUString(
47 "1 Heading 1" SAL_NEWLINE_STRING "1.A Heading 2" SAL_NEWLINE_STRING
48 "Paragraph" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING
49 " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
50 " \xe2\x80\xa2 Second bullet" SAL_NEWLINE_STRING
51 " \xe2\x97\xa6 Sub-second bullet" SAL_NEWLINE_STRING
52 " Third bullet, but deleted" SAL_NEWLINE_STRING
53 " \xe2\x80\xa2 Fourth bullet" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING
54 "Numbering" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING " 1. First" SAL_NEWLINE_STRING
55 " 2. Second" SAL_NEWLINE_STRING " 1. Second-first" SAL_NEWLINE_STRING
56 " Third, but deleted" SAL_NEWLINE_STRING " 3. Actual third" SAL_NEWLINE_STRING
57 "" SAL_NEWLINE_STRING "Paragraph after numbering" SAL_NEWLINE_STRING
58 "Next paragraph" SAL_NEWLINE_STRING "Hidden paragraph" SAL_NEWLINE_STRING
59 "Final paragraph" SAL_NEWLINE_STRING,
60 RTL_TEXTENCODING_UTF8);
61
62 // To get the stuff back in the system's encoding
63 OString aExpected(OUStringToOString(aString, RTL_TEXTENCODING_UTF8));
64
65 CPPUNIT_ASSERT_EQUAL(aExpected, aData);
66 }
67
68 CPPUNIT_TEST_FIXTURE(TxtEncExportTest, testBulletsHidden)
69 {
70 createSwDoc("bullets.odt");
71 setFilterOptions(u"UTF8,,,,,false"_ustr);
72 save(TestFilter::TEXT_ENCODED);
73 OString aData = readExportedFile();
74
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);
90
91 // To get the stuff back in the system's encoding
92 OString aExpected(OUStringToOString(aString, RTL_TEXTENCODING_UTF8));
93
94 CPPUNIT_ASSERT_EQUAL(aExpected, aData);
95 }
96
97 } // end of anonymous namespace
98 CPPUNIT_PLUGIN_IMPLEMENT();
99
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */