summaryrefslogtreecommitdiffstats
path: root/sw/qa/extras/txtencexport
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sw/qa/extras/txtencexport
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--sw/qa/extras/txtencexport/data/bullets.odtbin0 -> 10827 bytes
-rw-r--r--sw/qa/extras/txtencexport/txtencexport.cxx99
2 files changed, 99 insertions, 0 deletions
diff --git a/sw/qa/extras/txtencexport/data/bullets.odt b/sw/qa/extras/txtencexport/data/bullets.odt
new file mode 100644
index 000000000..aec2b52cb
--- /dev/null
+++ b/sw/qa/extras/txtencexport/data/bullets.odt
Binary files differ
diff --git a/sw/qa/extras/txtencexport/txtencexport.cxx b/sw/qa/extras/txtencexport/txtencexport.cxx
new file mode 100644
index 000000000..7db93ba3a
--- /dev/null
+++ b/sw/qa/extras/txtencexport/txtencexport.cxx
@@ -0,0 +1,99 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+class TxtEncExportTest : public SwModelTestBase
+{
+public:
+ TxtEncExportTest(const OUString & rFilterOptions)
+ : SwModelTestBase("/sw/qa/extras/txtencexport/data/", "Text (encoded)")
+ {
+ setFilterOptions(rFilterOptions);
+ }
+
+protected:
+ OString readExportedFile()
+ {
+ SvMemoryStream aMemoryStream;
+ SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
+ aStream.ReadStream(aMemoryStream);
+ const char* pData = static_cast<const char*>(aMemoryStream.GetData());
+
+ int offset = 0;
+ if (aMemoryStream.GetSize() > 2 && pData[0] == '\xEF' && pData[1] == '\xBB'
+ && pData[2] == '\xBF')
+ offset = 3;
+
+ return OString(pData + offset, aMemoryStream.GetSize() - offset);
+ }
+};
+
+#define DECLARE_TXTENCEXPORT_TEST(TestName, filename, filterOptions, ClassName) \
+ class ClassName : public TxtEncExportTest { \
+ public: \
+ ClassName() : TxtEncExportTest(filterOptions) {} \
+ }; \
+ DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, ClassName)
+
+DECLARE_TXTENCEXPORT_TEST(testBulletsNotHidden, "bullets.odt", "UTF8,,,,", TxtEncExportNotHiddenTest)
+{
+ OString aData = readExportedFile();
+
+ OUString aString = OStringToOUString(
+ "1 Heading 1" SAL_NEWLINE_STRING "1.A Heading 2" SAL_NEWLINE_STRING
+ "Paragraph" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Second bullet" SAL_NEWLINE_STRING
+ " \xe2\x97\xa6 Sub-second bullet" SAL_NEWLINE_STRING
+ " Third bullet, but deleted" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Fourth bullet" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING
+ "Numbering" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING " 1. First" SAL_NEWLINE_STRING
+ " 2. Second" SAL_NEWLINE_STRING " 1. Second-first" SAL_NEWLINE_STRING
+ " Third, but deleted" SAL_NEWLINE_STRING " 3. Actual third" SAL_NEWLINE_STRING
+ "" SAL_NEWLINE_STRING "Paragraph after numbering" SAL_NEWLINE_STRING
+ "Next paragraph" SAL_NEWLINE_STRING "Hidden paragraph" SAL_NEWLINE_STRING
+ "Final paragraph" SAL_NEWLINE_STRING,
+ RTL_TEXTENCODING_UTF8);
+
+ // To get the stuff back in the system's encoding
+ OString aExpected(OUStringToOString(aString, RTL_TEXTENCODING_UTF8));
+
+ CPPUNIT_ASSERT_EQUAL(aExpected, aData);
+}
+
+DECLARE_TXTENCEXPORT_TEST(testBulletsHidden, "bullets.odt", "UTF8,,,,,false", TxtEncExportHiddenTest)
+{
+ OString aData = readExportedFile();
+
+ OUString aString = OStringToOUString(
+ "1 Heading 1" SAL_NEWLINE_STRING "1.A Heading 2" SAL_NEWLINE_STRING
+ "Paragraph" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Second bullet" SAL_NEWLINE_STRING
+ " \xe2\x97\xa6 Sub-second bullet" SAL_NEWLINE_STRING
+ " Third bullet, but deleted" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Fourth bullet" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING
+ "Numbering" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING " 1. First" SAL_NEWLINE_STRING
+ " 2. Second" SAL_NEWLINE_STRING " 1. Second-first" SAL_NEWLINE_STRING
+ " Third, but deleted" SAL_NEWLINE_STRING " 3. Actual third" SAL_NEWLINE_STRING
+ "" SAL_NEWLINE_STRING "Paragraph after numbering" SAL_NEWLINE_STRING
+ "Next paragraph" SAL_NEWLINE_STRING
+ "Final paragraph" SAL_NEWLINE_STRING,
+ RTL_TEXTENCODING_UTF8);
+
+ // To get the stuff back in the system's encoding
+ OString aExpected(OUStringToOString(aString, RTL_TEXTENCODING_UTF8));
+
+ CPPUNIT_ASSERT_EQUAL(aExpected, aData);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */