summaryrefslogtreecommitdiffstats
path: root/tools/qa
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-10-18 15:00:02 +0300
committerXisco Fauli <xiscofauli@libreoffice.org>2022-10-25 21:07:19 +0200
commit92c774afadec0019059536dba3f941b986489246 (patch)
treeb04901025bf0155ce8dac73feab1e181a1d25ce0 /tools/qa
parenttdf#151545: Restrict JvmfwkUtil_isLoadableJVM to macOS x86-64 (diff)
downloadcore-92c774afadec0019059536dba3f941b986489246.tar.gz
core-92c774afadec0019059536dba3f941b986489246.zip
Fix StartWritingUnicodeText
Its comment in include/tools/stream.hxx tells: Switch to no endian swapping and write 0xfeff It was introduced in commit 3c2105e07d29b2069349e1a54e08463d359f988f Author Eike Rathke <er@openoffice.org> Date Fri Dec 22 00:19:05 2000 +0000 new: read/write Unicode or Bytecode and included a call to SetEndianSwap( FALSE ). That call was dropped in commit 8130714148d58dd2bf1ef12dcc6dd6d5838be0d1 Author Noel Grandin <noel@peralex.com> Date Mon Jan 05 08:47:31 2015 +0200 fdo#84938: replace NUMBERFORMAT_INT_ constants with 'enum class' (likely by accident). To simplify the fix, drop redundant m_nEndian: m_isSwap is enough. Change-Id: Ia9a0fe2d55563e7ba21bd4cf17c4ca999c6feaf7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141521 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141777
Diffstat (limited to 'tools/qa')
-rw-r--r--tools/qa/cppunit/test_stream.cxx40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx
index 4672af6c70c9..02fe22343130 100644
--- a/tools/qa/cppunit/test_stream.cxx
+++ b/tools/qa/cppunit/test_stream.cxx
@@ -12,6 +12,7 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <tools/stream.hxx>
+#include <unotools/tempfile.hxx>
#include <sstream>
//Tests for eofbit/badbit/goodbit/failbit
@@ -27,6 +28,7 @@ namespace
void test_read_cstring();
void test_read_pstring();
void test_readline();
+ void test_write_unicode();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(test_stdstream);
@@ -34,6 +36,7 @@ namespace
CPPUNIT_TEST(test_read_cstring);
CPPUNIT_TEST(test_read_pstring);
CPPUNIT_TEST(test_readline);
+ CPPUNIT_TEST(test_write_unicode);
CPPUNIT_TEST_SUITE_END();
};
@@ -275,6 +278,43 @@ namespace
CPPUNIT_ASSERT(issB.eof()); //<-- diff A
}
+ void Test::test_write_unicode()
+ {
+ const OUString write("abc");
+ utl::TempFile aTempFile(u"test_write_unicode");
+ aTempFile.EnableKillingFile();
+ {
+ SvStream& s = *aTempFile.GetStream(StreamMode::WRITE);
+ s.SetEndian(SvStreamEndian::BIG);
+ if (!s.IsEndianSwap())
+ s.SetEndian(SvStreamEndian::LITTLE);
+ CPPUNIT_ASSERT(s.IsEndianSwap());
+ // StartWritingUnicodeText must switch to no endian swapping and write 0xfeff
+ s.StartWritingUnicodeText();
+ // Without the fix in place, this would fail
+ CPPUNIT_ASSERT(!s.IsEndianSwap());
+ s.WriteUnicodeOrByteText(write, RTL_TEXTENCODING_UNICODE);
+ aTempFile.CloseStream();
+ }
+ {
+ SvStream& s = *aTempFile.GetStream(StreamMode::READ);
+ s.SetEndian(SvStreamEndian::BIG);
+ if (!s.IsEndianSwap())
+ s.SetEndian(SvStreamEndian::LITTLE);
+ CPPUNIT_ASSERT(s.IsEndianSwap());
+ s.StartReadingUnicodeText(RTL_TEXTENCODING_DONTKNOW);
+ CPPUNIT_ASSERT(!s.IsEndianSwap());
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(2), s.Tell()); // after BOM
+ OUString read;
+ CPPUNIT_ASSERT(s.ReadUniOrByteStringLine(read, RTL_TEXTENCODING_UNICODE));
+ // Without the fix in place, this would fail with
+ // - Expected: abc
+ // - Actual : 愀戀挀
+ CPPUNIT_ASSERT_EQUAL(write, read);
+ aTempFile.CloseStream();
+ }
+ }
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}