");
TEST_ASSERT_TRUE_MESSAGE(ctxt->nameNr > 0, "Expected open elements before testing HTML5 early return");
int before_nameNr = ctxt->nameNr;
ctxt->options |= HTML_PARSE_HTML5;
test_htmlAutoCloseOnEnd(ctxt);
/* Should be unchanged and no callbacks should be invoked */
TEST_ASSERT_EQUAL_INT(before_nameNr, ctxt->nameNr);
TEST_ASSERT_EQUAL_INT(0, rec.call_count);
htmlFreeParserCtxt(ctxt);
}
/* Test: with NULL SAX handler, the function still empties the stack but doesn't call endElement */
void test_htmlAutoCloseOnEnd_handles_null_sax_handler(void) {
EndRec rec = {0};
htmlParserCtxtPtr ctxt = create_push_ctxt(&rec);
TEST_ASSERT_NOT_NULL(ctxt);
feed_chunk(ctxt, "");
TEST_ASSERT_TRUE_MESSAGE(ctxt->nameNr > 0, "Expected open elements before null SAX test");
int initial_nameNr = ctxt->nameNr;
/* Remove SAX handler to simulate NULL sax/endElement */
ctxt->sax = NULL;
test_htmlAutoCloseOnEnd(ctxt);
TEST_ASSERT_EQUAL_INT(0, ctxt->nameNr);
TEST_ASSERT_EQUAL_INT(0, rec.call_count); /* no callbacks since sax is NULL */
(void)initial_nameNr; /* suppress unused warning if not used in some configs */
htmlFreeParserCtxt(ctxt);
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_htmlAutoCloseOnEnd_no_open_elements_noop);
RUN_TEST(test_htmlAutoCloseOnEnd_closes_stack_and_calls_endElement_reverse_order);
RUN_TEST(test_htmlAutoCloseOnEnd_returns_early_with_HTML5_option);
RUN_TEST(test_htmlAutoCloseOnEnd_handles_null_sax_handler);
return UNITY_END();
}