summaryrefslogtreecommitdiff
path: root/svtools/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-12-13 14:46:26 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-12-14 09:10:20 +0100
commit3fe64261b5658e28e2c0a1630cf878f066f77f0c (patch)
tree47b5a0dd73967a5673876fd34cee5e27eb23570e /svtools/qa
parent14daba5bd0ba64ff53ad98de7a84537ff03024ea (diff)
Related: tdf#114428 svtools HTML import: avoid XML declaration in body text
Just ignore it for now. Change-Id: Idf82af611370d957c6704cce250941a8a0b90637 Reviewed-on: https://gerrit.libreoffice.org/46388 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'svtools/qa')
-rw-r--r--svtools/qa/unit/testHtmlReader.cxx70
1 files changed, 70 insertions, 0 deletions
diff --git a/svtools/qa/unit/testHtmlReader.cxx b/svtools/qa/unit/testHtmlReader.cxx
new file mode 100644
index 000000000000..151976eabc9d
--- /dev/null
+++ b/svtools/qa/unit/testHtmlReader.cxx
@@ -0,0 +1,70 @@
+/* -*- 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 <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <svtools/parhtml.hxx>
+#include <tools/ref.hxx>
+#include <tools/stream.hxx>
+
+namespace
+{
+/// Subclass of HTMLParser that can sense the import result.
+class TestHTMLParser : public HTMLParser
+{
+public:
+ TestHTMLParser(SvStream& rStream);
+ virtual void NextToken(HtmlTokenId nToken) override;
+
+ OUString m_aDocument;
+};
+
+TestHTMLParser::TestHTMLParser(SvStream& rStream)
+ : HTMLParser(rStream)
+{
+}
+
+void TestHTMLParser::NextToken(HtmlTokenId nToken)
+{
+ if (nToken == HtmlTokenId::TEXTTOKEN)
+ m_aDocument += aToken;
+}
+
+/// Tests HTMLParser.
+class Test : public CppUnit::TestFixture
+{
+public:
+ void testTdf114428();
+
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testTdf114428);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void Test::testTdf114428()
+{
+ SvMemoryStream aStream;
+ OString aDocument("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<html>hello</html>");
+ aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
+ aStream.Seek(0);
+
+ tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
+ xParser->CallParser();
+
+ // This was '<?xml version="1.0" encoding="utf-8"?> hello', XML declaration
+ // was not ignored.
+ CPPUNIT_ASSERT_EQUAL(OUString("hello"), xParser->m_aDocument.trim());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */