1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
20 /// Subclass of HTMLParser that can sense the import result.
21 class TestHTMLParser
: public HTMLParser
24 TestHTMLParser(SvStream
& rStream
);
25 virtual void NextToken(HtmlTokenId nToken
) override
;
26 /// Make this public for test purposes.
27 using HTMLParser::SetNamespace
;
30 int m_nLineBreakCount
= 0;
33 TestHTMLParser::TestHTMLParser(SvStream
& rStream
)
38 void TestHTMLParser::NextToken(HtmlTokenId nToken
)
40 if (nToken
== HtmlTokenId::TEXTTOKEN
)
41 m_aDocument
+= aToken
;
42 else if (nToken
== HtmlTokenId::LINEBREAK
)
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());
58 tools::SvRef
<TestHTMLParser
> xParser
= new TestHTMLParser(aStream
);
59 xParser
->CallParser();
61 // This was '<?xml version="1.0" encoding="utf-8"?> hello', XML declaration
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());
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: */