| | #include "unity/unity.h" |
| | #include <libxml/HTMLparser.h> |
| |
|
| | #include <libxml/parser.h> |
| | #include <libxml/parserInternals.h> |
| | #include <string.h> |
| | #include <stdlib.h> |
| |
|
| | |
| | int test_htmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask); |
| |
|
| | static xmlParserCtxtPtr make_ctxt(void) { |
| | htmlParserCtxtPtr hctxt = htmlNewParserCtxt(); |
| | TEST_ASSERT_NOT_NULL(hctxt); |
| | return (xmlParserCtxtPtr)hctxt; |
| | } |
| |
|
| | void setUp(void) { |
| | xmlInitParser(); |
| | } |
| |
|
| | void tearDown(void) { |
| | |
| | } |
| |
|
| | |
| | void test_htmlCtxtSetOptionsInternal_null_context(void) { |
| | int ret = test_htmlCtxtSetOptionsInternal(NULL, 0, 0); |
| | TEST_ASSERT_EQUAL_INT(-1, ret); |
| | } |
| |
|
| | |
| | void test_htmlCtxtSetOptionsInternal_set_allowed_and_fields(void) { |
| | xmlParserCtxtPtr ctxt = make_ctxt(); |
| |
|
| | int options = HTML_PARSE_RECOVER | HTML_PARSE_NOBLANKS | HTML_PARSE_NOWARNING; |
| | int keepMask = 0; |
| |
|
| | int ret = test_htmlCtxtSetOptionsInternal(ctxt, options, keepMask); |
| | TEST_ASSERT_EQUAL_INT(0, ret); |
| |
|
| | |
| | TEST_ASSERT_TRUE((ctxt->options & HTML_PARSE_RECOVER) != 0); |
| | TEST_ASSERT_TRUE((ctxt->options & HTML_PARSE_NOBLANKS) != 0); |
| | TEST_ASSERT_TRUE((ctxt->options & HTML_PARSE_NOWARNING) != 0); |
| | TEST_ASSERT_EQUAL_INT(options, ctxt->options); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->keepBlanks); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(1, ctxt->recovery); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->dictNames); |
| |
|
| | |
| | TEST_ASSERT_NOT_NULL(ctxt->sax); |
| | TEST_ASSERT(ctxt->sax->ignorableWhitespace == xmlSAX2IgnorableWhitespace); |
| |
|
| | htmlFreeParserCtxt((htmlParserCtxtPtr)ctxt); |
| | } |
| |
|
| | |
| | void test_htmlCtxtSetOptionsInternal_keepmask_preserves_previous(void) { |
| | xmlParserCtxtPtr ctxt = make_ctxt(); |
| |
|
| | |
| | ctxt->options = HTML_PARSE_PEDANTIC | HTML_PARSE_BIG_LINES; |
| |
|
| | int options = 0; |
| | int keepMask = HTML_PARSE_PEDANTIC; |
| |
|
| | int ret = test_htmlCtxtSetOptionsInternal(ctxt, options, keepMask); |
| | TEST_ASSERT_EQUAL_INT(0, ret); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(HTML_PARSE_PEDANTIC, ctxt->options); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(1, ctxt->keepBlanks); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(1, ctxt->recovery); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->dictNames); |
| |
|
| | htmlFreeParserCtxt((htmlParserCtxtPtr)ctxt); |
| | } |
| |
|
| | |
| | void test_htmlCtxtSetOptionsInternal_allows_XML_PARSE_NOENT(void) { |
| | xmlParserCtxtPtr ctxt = make_ctxt(); |
| |
|
| | int options = XML_PARSE_NOENT; |
| | int keepMask = 0; |
| |
|
| | int ret = test_htmlCtxtSetOptionsInternal(ctxt, options, keepMask); |
| | |
| | TEST_ASSERT_EQUAL_INT(0, ret); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->options); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(1, ctxt->keepBlanks); |
| |
|
| | htmlFreeParserCtxt((htmlParserCtxtPtr)ctxt); |
| | } |
| |
|
| | |
| | void test_htmlCtxtSetOptionsInternal_returns_unhandled_bits(void) { |
| | xmlParserCtxtPtr ctxt = make_ctxt(); |
| |
|
| | int options = XML_PARSE_NOENT | XML_PARSE_NOCDATA; |
| | int keepMask = 0; |
| |
|
| | int ret = test_htmlCtxtSetOptionsInternal(ctxt, options, keepMask); |
| | |
| | TEST_ASSERT_EQUAL_INT(XML_PARSE_NOCDATA, ret); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->options); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(1, ctxt->keepBlanks); |
| |
|
| | htmlFreeParserCtxt((htmlParserCtxtPtr)ctxt); |
| | } |
| |
|
| | |
| | void test_htmlCtxtSetOptionsInternal_html5_and_huge_bits(void) { |
| | xmlParserCtxtPtr ctxt = make_ctxt(); |
| |
|
| | int options = HTML_PARSE_HTML5 | HTML_PARSE_HUGE; |
| | int keepMask = 0; |
| |
|
| | int ret = test_htmlCtxtSetOptionsInternal(ctxt, options, keepMask); |
| | TEST_ASSERT_EQUAL_INT(0, ret); |
| |
|
| | TEST_ASSERT_TRUE((ctxt->options & HTML_PARSE_HTML5) != 0); |
| | TEST_ASSERT_TRUE((ctxt->options & HTML_PARSE_HUGE) != 0); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(1, ctxt->keepBlanks); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(1, ctxt->recovery); |
| |
|
| | |
| | TEST_ASSERT_EQUAL_INT(0, ctxt->dictNames); |
| |
|
| | htmlFreeParserCtxt((htmlParserCtxtPtr)ctxt); |
| | } |
| |
|
| | int main(void) { |
| | UNITY_BEGIN(); |
| | RUN_TEST(test_htmlCtxtSetOptionsInternal_null_context); |
| | RUN_TEST(test_htmlCtxtSetOptionsInternal_set_allowed_and_fields); |
| | RUN_TEST(test_htmlCtxtSetOptionsInternal_keepmask_preserves_previous); |
| | RUN_TEST(test_htmlCtxtSetOptionsInternal_allows_XML_PARSE_NOENT); |
| | RUN_TEST(test_htmlCtxtSetOptionsInternal_returns_unhandled_bits); |
| | RUN_TEST(test_htmlCtxtSetOptionsInternal_html5_and_huge_bits); |
| | return UNITY_END(); |
| | } |