mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00

A challenge for getting LibTest working on Windows has always been CrashTest. It implements death tests similar to Google Test where a child process is cloned to invoke the expression that should abort/terminate the program. Then the exit code of the child is used by the parent test process to verify if the application correctly aborted/terminated due to invoking the expression. The problem was that finding an equivalent way to port Crash::run() to Windows was not looking very likely as publicly exposed Win32/ Native APIs have no equivalent to fork(); however, Windows actually does have native support for process cloning via undocumented NT APIs that clever people reverse engineered and published, see `NtCreateUserProcess()`. All that being said, this `EXPECT_DEATH()` implementation avoids needing to use a child process in general, allowing us to remove CrashTest in favour of a single cross-platform solution for death tests.
47 lines
1.9 KiB
C++
47 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibTest/TestCase.h>
|
|
#include <LibXML/Parser/Parser.h>
|
|
|
|
TEST_CASE(char_data_ending)
|
|
{
|
|
EXPECT_NO_DEATH("parsing character data ending by itself should not crash", [] {
|
|
// After seeing `<C>`, the parser will start parsing the content of the element. The content parser will then parse any character data it sees.
|
|
// The character parser would see the first two `]]` and consume them. Then, it would see the `>` and set the state machine to say we have seen this,
|
|
// but it did _not_ consume it and would instead tell GenericLexer that it should stop consuming characters. Therefore, we only consumed 2 characters.
|
|
// Then, it would see that we are in the state where we've seen the full `]]>` and try to take off three characters from the end of the consumed
|
|
// input when we only have 2 characters, causing an assertion failure as we are asking to take off more characters than there really is.
|
|
XML::Parser parser("<C>]]>"sv);
|
|
(void)parser.parse();
|
|
}());
|
|
}
|
|
|
|
TEST_CASE(character_reference_integer_overflow)
|
|
{
|
|
EXPECT_NO_DEATH("parsing character references that do not fit in 32 bits should not crash", [] {
|
|
XML::Parser parser("<G>�"sv);
|
|
(void)parser.parse();
|
|
}());
|
|
}
|
|
|
|
TEST_CASE(predefined_character_reference)
|
|
{
|
|
XML::Parser parser("<a>Well hello &, <, >, ', and "!</a>"sv);
|
|
auto document = MUST(parser.parse());
|
|
|
|
auto const& node = document.root().content.get<XML::Node::Element>();
|
|
EXPECT_EQ(node.name, "a");
|
|
|
|
auto const& content = node.children[0]->content.get<XML::Node::Text>();
|
|
EXPECT_EQ(content.builder.string_view(), "Well hello &, <, >, ', and \"!");
|
|
}
|
|
|
|
TEST_CASE(unicode_name)
|
|
{
|
|
XML::Parser parser("<div 中文=\"\"></div>"sv);
|
|
TRY_OR_FAIL(parser.parse());
|
|
}
|