mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-19 12:39:11 +00:00
Codechange: Pass NWidgetParts as span instead of begin/end pointers. (#12779)
This commit is contained in:
@@ -48,7 +48,7 @@ TEST_CASE("WindowDesc - ini_key validity")
|
||||
const WindowDesc *window_desc = GENERATE(from_range(std::begin(*_window_descs), std::end(*_window_descs)));
|
||||
|
||||
bool has_inikey = window_desc->ini_key != nullptr;
|
||||
bool has_widget = std::any_of(window_desc->nwid_begin, window_desc->nwid_end, [](const NWidgetPart &part) { return part.type == WWT_DEFSIZEBOX || part.type == WWT_STICKYBOX; });
|
||||
bool has_widget = std::any_of(std::begin(window_desc->nwid_parts), std::end(window_desc->nwid_parts), [](const NWidgetPart &part) { return part.type == WWT_DEFSIZEBOX || part.type == WWT_STICKYBOX; });
|
||||
|
||||
INFO(fmt::format("{}:{}", window_desc->source_location.file_name(), window_desc->source_location.line()));
|
||||
CAPTURE(has_inikey);
|
||||
@@ -60,16 +60,15 @@ TEST_CASE("WindowDesc - ini_key validity")
|
||||
/**
|
||||
* Test if a NWidgetTree is properly closed, meaning the number of container-type parts matches the number of
|
||||
* EndContainer() parts.
|
||||
* @param nwid_begin Pointer to beginning of nested widget parts.
|
||||
* @param nwid_end Pointer to ending of nested widget parts.
|
||||
* @param nwid_parts Span of nested widget parts.
|
||||
* @return True iff nested tree is properly closed.
|
||||
*/
|
||||
static bool IsNWidgetTreeClosed(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end)
|
||||
static bool IsNWidgetTreeClosed(std::span<const NWidgetPart> nwid_parts)
|
||||
{
|
||||
int depth = 0;
|
||||
for (; nwid_begin < nwid_end; ++nwid_begin) {
|
||||
if (IsContainerWidgetType(nwid_begin->type)) ++depth;
|
||||
if (nwid_begin->type == WPT_ENDCONTAINER) --depth;
|
||||
for (const auto nwid : nwid_parts) {
|
||||
if (IsContainerWidgetType(nwid.type)) ++depth;
|
||||
if (nwid.type == WPT_ENDCONTAINER) --depth;
|
||||
}
|
||||
return depth == 0;
|
||||
}
|
||||
@@ -80,7 +79,7 @@ TEST_CASE("WindowDesc - NWidgetParts properly closed")
|
||||
|
||||
INFO(fmt::format("{}:{}", window_desc->source_location.file_name(), window_desc->source_location.line()));
|
||||
|
||||
CHECK(IsNWidgetTreeClosed(window_desc->nwid_begin, window_desc->nwid_end));
|
||||
CHECK(IsNWidgetTreeClosed(window_desc->nwid_parts));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(WindowDescTestsFixture, "WindowDesc - NWidgetPart validity")
|
||||
@@ -92,6 +91,6 @@ TEST_CASE_METHOD(WindowDescTestsFixture, "WindowDesc - NWidgetPart validity")
|
||||
NWidgetStacked *shade_select = nullptr;
|
||||
std::unique_ptr<NWidgetBase> root = nullptr;
|
||||
|
||||
REQUIRE_NOTHROW(root = MakeWindowNWidgetTree(window_desc->nwid_begin, window_desc->nwid_end, &shade_select));
|
||||
REQUIRE_NOTHROW(root = MakeWindowNWidgetTree(window_desc->nwid_parts, &shade_select));
|
||||
CHECK((root != nullptr));
|
||||
}
|
||||
|
Reference in New Issue
Block a user