| | #include "unity/unity.h" |
| | #include <libxml/HTMLparser.h> |
| |
|
| | #include <stdlib.h> |
| | #include <string.h> |
| |
|
| | |
| | extern htmlParserCtxtPtr test_htmlCreateDocParserCtxt(const xmlChar *str, const char *url, const char *encoding); |
| |
|
| | static void free_ctxt(htmlParserCtxtPtr ctxt) { |
| | if (ctxt != NULL) { |
| | xmlFreeParserCtxt(ctxt); |
| | } |
| | } |
| |
|
| | void setUp(void) { |
| | |
| | xmlInitParser(); |
| | } |
| |
|
| | void tearDown(void) { |
| | |
| | xmlCleanupParser(); |
| | } |
| |
|
| | void test_htmlCreateDocParserCtxt_null_str_returns_null(void) { |
| | htmlParserCtxtPtr ctxt = test_htmlCreateDocParserCtxt(NULL, NULL, NULL); |
| | TEST_ASSERT_NULL(ctxt); |
| | } |
| |
|
| | void test_htmlCreateDocParserCtxt_simple_html_success(void) { |
| | const xmlChar *str = BAD_CAST "<!DOCTYPE html><html><body>Hello</body></html>"; |
| | htmlParserCtxtPtr ctxt = test_htmlCreateDocParserCtxt(str, NULL, NULL); |
| |
|
| | TEST_ASSERT_NOT_NULL(ctxt); |
| | |
| | TEST_ASSERT_TRUE_MESSAGE(ctxt->inputNr >= 1, "Expected at least one input on the stack"); |
| | free_ctxt(ctxt); |
| | } |
| |
|
| | void test_htmlCreateDocParserCtxt_empty_string_success(void) { |
| | const xmlChar *str = BAD_CAST ""; |
| | htmlParserCtxtPtr ctxt = test_htmlCreateDocParserCtxt(str, NULL, NULL); |
| |
|
| | TEST_ASSERT_NOT_NULL(ctxt); |
| | TEST_ASSERT_TRUE_MESSAGE(ctxt->inputNr >= 1, "Expected at least one input on the stack for empty string"); |
| | free_ctxt(ctxt); |
| | } |
| |
|
| | void test_htmlCreateDocParserCtxt_with_url_success(void) { |
| | const xmlChar *str = BAD_CAST "Hi"; |
| | const char *url = "http://example.com/base/index.html"; |
| | htmlParserCtxtPtr ctxt = test_htmlCreateDocParserCtxt(str, url, NULL); |
| |
|
| | TEST_ASSERT_NOT_NULL(ctxt); |
| | TEST_ASSERT_TRUE_MESSAGE(ctxt->inputNr >= 1, "Expected at least one input on the stack with URL provided"); |
| | free_ctxt(ctxt); |
| | } |
| |
|
| | void test_htmlCreateDocParserCtxt_with_utf8_encoding_success(void) { |
| | |
| | const xmlChar *str = BAD_CAST "Just some text"; |
| | const char *encoding = "UTF-8"; |
| | htmlParserCtxtPtr ctxt = test_htmlCreateDocParserCtxt(str, NULL, encoding); |
| |
|
| | TEST_ASSERT_NOT_NULL(ctxt); |
| | TEST_ASSERT_TRUE_MESSAGE(ctxt->inputNr >= 1, "Expected at least one input on the stack with UTF-8 encoding"); |
| | free_ctxt(ctxt); |
| | } |
| |
|
| | void test_htmlCreateDocParserCtxt_with_iso_8859_1_encoding_success(void) { |
| | |
| | const xmlChar *str = BAD_CAST "Plain ASCII content"; |
| | const char *encoding = "ISO-8859-1"; |
| | htmlParserCtxtPtr ctxt = test_htmlCreateDocParserCtxt(str, NULL, encoding); |
| |
|
| | TEST_ASSERT_NOT_NULL(ctxt); |
| | TEST_ASSERT_TRUE_MESSAGE(ctxt->inputNr >= 1, "Expected at least one input on the stack with ISO-8859-1 encoding"); |
| | free_ctxt(ctxt); |
| | } |
| |
|
| | int main(void) { |
| | UNITY_BEGIN(); |
| |
|
| | RUN_TEST(test_htmlCreateDocParserCtxt_null_str_returns_null); |
| | RUN_TEST(test_htmlCreateDocParserCtxt_simple_html_success); |
| | RUN_TEST(test_htmlCreateDocParserCtxt_empty_string_success); |
| | RUN_TEST(test_htmlCreateDocParserCtxt_with_url_success); |
| | RUN_TEST(test_htmlCreateDocParserCtxt_with_utf8_encoding_success); |
| | RUN_TEST(test_htmlCreateDocParserCtxt_with_iso_8859_1_encoding_success); |
| |
|
| | return UNITY_END(); |
| | } |