| | #include "unity/unity.h" |
| | #include <libxml/HTMLparser.h> |
| | #include <libxml/parserInternals.h> |
| |
|
| | #include <stdlib.h> |
| | #include <string.h> |
| |
|
| | |
| | extern int test_htmlParseLookupCommentEnd(htmlParserCtxtPtr ctxt); |
| |
|
| | static htmlParserCtxtPtr makeCtxtFromString(const char *s) { |
| | htmlParserCtxtPtr ctxt = htmlNewParserCtxt(); |
| | TEST_ASSERT_NOT_NULL_MESSAGE(ctxt, "htmlNewParserCtxt failed"); |
| |
|
| | xmlParserInputPtr in = xmlNewStringInputStream((xmlParserCtxtPtr)ctxt, (const xmlChar *)s); |
| | TEST_ASSERT_NOT_NULL_MESSAGE(in, "xmlNewStringInputStream failed"); |
| |
|
| | int pushed = inputPush((xmlParserCtxtPtr)ctxt, in); |
| | TEST_ASSERT_TRUE_MESSAGE(pushed >= 1, "inputPush failed"); |
| |
|
| | |
| | ctxt->checkIndex = 0; |
| |
|
| | return ctxt; |
| | } |
| |
|
| | void setUp(void) { |
| | |
| | } |
| |
|
| | void tearDown(void) { |
| | |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_simple_end_arrow(void) { |
| | const char *s = "<!-->"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(2, ret); |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->checkIndex); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_bang_invalid(void) { |
| | const char *s = "<!--!>"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(-1, ret); |
| | |
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_dash_bang_invalid(void) { |
| | const char *s = "<!---!>"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(-1, ret); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_dash_dash_bang_valid(void) { |
| | const char *s = "<!----!>"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(4, ret); |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->checkIndex); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_incomplete_needs_more_offset2(void) { |
| | const char *s = "<!--"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(-1, ret); |
| | TEST_ASSERT_EQUAL_INT(2, ctxt->checkIndex); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_incomplete_after_bang(void) { |
| | const char *s = "<!--!"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(-1, ret); |
| | TEST_ASSERT_EQUAL_INT(2, ctxt->checkIndex); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_skip_non_terminators_then_close(void) { |
| | const char *s = "<!---a-->"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(6, ret); |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->checkIndex); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_skip_false_bang_then_close(void) { |
| | const char *s = "<!--!x-->"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(6, ret); |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->checkIndex); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | |
| | void test_htmlParseLookupCommentEnd_no_hyphens(void) { |
| | const char *s = "<!>"; |
| | htmlParserCtxtPtr ctxt = makeCtxtFromString(s); |
| |
|
| | int ret = test_htmlParseLookupCommentEnd(ctxt); |
| | TEST_ASSERT_EQUAL_INT(-1, ret); |
| |
|
| | htmlFreeParserCtxt(ctxt); |
| | } |
| |
|
| | int main(void) { |
| | UNITY_BEGIN(); |
| |
|
| | RUN_TEST(test_htmlParseLookupCommentEnd_simple_end_arrow); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_bang_invalid); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_dash_bang_invalid); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_dash_dash_bang_valid); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_incomplete_needs_more_offset2); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_incomplete_after_bang); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_skip_non_terminators_then_close); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_skip_false_bang_then_close); |
| | RUN_TEST(test_htmlParseLookupCommentEnd_no_hyphens); |
| |
|
| | return UNITY_END(); |
| | } |