bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svtools / qa / unit / testHtmlReader.cxx
blobabda6f2725fc8a52f7ffc162cb6418fc86050ac0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <unotest/bootstrapfixturebase.hxx>
14 #include <svtools/parhtml.hxx>
15 #include <tools/ref.hxx>
16 #include <tools/stream.hxx>
18 namespace
20 /// Subclass of HTMLParser that can sense the import result.
21 class TestHTMLParser : public HTMLParser
23 public:
24 TestHTMLParser(SvStream& rStream);
25 virtual void NextToken(HtmlTokenId nToken) override;
26 /// Make this public for test purposes.
27 using HTMLParser::SetNamespace;
29 OUString m_aDocument;
30 int m_nLineBreakCount = 0;
33 TestHTMLParser::TestHTMLParser(SvStream& rStream)
34 : HTMLParser(rStream)
38 void TestHTMLParser::NextToken(HtmlTokenId nToken)
40 if (nToken == HtmlTokenId::TEXTTOKEN)
41 m_aDocument += aToken;
42 else if (nToken == HtmlTokenId::LINEBREAK)
43 ++m_nLineBreakCount;
46 /// Tests HTMLParser.
47 class Test : public CppUnit::TestFixture
51 CPPUNIT_TEST_FIXTURE(Test, testTdf114428)
53 SvMemoryStream aStream;
54 OString aDocument("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<html>hello</html>");
55 aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
56 aStream.Seek(0);
58 tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
59 xParser->CallParser();
61 // This was '<?xml version="1.0" encoding="utf-8"?> hello', XML declaration
62 // was not ignored.
63 CPPUNIT_ASSERT_EQUAL(OUString("hello"), xParser->m_aDocument.trim());
66 CPPUNIT_TEST_FIXTURE(Test, testLineBreak)
68 SvMemoryStream aStream;
69 OString aDocument("aaa<br></br>bbb");
70 aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
71 aStream.Seek(0);
73 tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
74 xParser->SetNamespace("reqif-xhtml");
75 xParser->CallParser();
77 // This was 2, <br></br> was interpreted as 2 line breaks in XHTML mode.
78 CPPUNIT_ASSERT_EQUAL(1, xParser->m_nLineBreakCount);
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */