|
|
#include "unity/unity.h" |
|
|
#include <libxml/HTMLparser.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
extern int test_htmlCharEncCheckAsciiCompatible(htmlParserCtxt *ctxt, const xmlChar *encoding); |
|
|
|
|
|
static htmlParserCtxtPtr make_ctxt(void) { |
|
|
htmlParserCtxtPtr ctxt = htmlNewParserCtxt(); |
|
|
TEST_ASSERT_NOT_NULL_MESSAGE(ctxt, "Failed to create HTML parser context"); |
|
|
return ctxt; |
|
|
} |
|
|
|
|
|
void setUp(void) { |
|
|
|
|
|
} |
|
|
|
|
|
void tearDown(void) { |
|
|
|
|
|
} |
|
|
|
|
|
void test_htmlCharEncCheckAsciiCompatible_utf8_returns_0(void) { |
|
|
htmlParserCtxtPtr ctxt = make_ctxt(); |
|
|
|
|
|
int ret = test_htmlCharEncCheckAsciiCompatible(ctxt, (const xmlChar *)"UTF-8"); |
|
|
TEST_ASSERT_EQUAL_INT_MESSAGE(0, ret, "UTF-8 must be treated as ASCII-compatible"); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
} |
|
|
|
|
|
void test_htmlCharEncCheckAsciiCompatible_utf8_mixed_case_returns_0(void) { |
|
|
htmlParserCtxtPtr ctxt = make_ctxt(); |
|
|
|
|
|
int ret = test_htmlCharEncCheckAsciiCompatible(ctxt, (const xmlChar *)"uTf-8"); |
|
|
TEST_ASSERT_EQUAL_INT_MESSAGE(0, ret, "Case-insensitive UTF-8 must be ASCII-compatible"); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
} |
|
|
|
|
|
void test_htmlCharEncCheckAsciiCompatible_us_ascii_returns_0(void) { |
|
|
htmlParserCtxtPtr ctxt = make_ctxt(); |
|
|
|
|
|
int ret = test_htmlCharEncCheckAsciiCompatible(ctxt, (const xmlChar *)"US-ASCII"); |
|
|
|
|
|
TEST_ASSERT_EQUAL_INT_MESSAGE(0, ret, "US-ASCII must be ASCII-compatible"); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
} |
|
|
|
|
|
void test_htmlCharEncCheckAsciiCompatible_utf16_returns_minus1(void) { |
|
|
htmlParserCtxtPtr ctxt = make_ctxt(); |
|
|
|
|
|
int ret = test_htmlCharEncCheckAsciiCompatible(ctxt, (const xmlChar *)"UTF-16"); |
|
|
TEST_ASSERT_EQUAL_INT_MESSAGE(-1, ret, "UTF-16 is not ASCII-compatible and should be rejected"); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
} |
|
|
|
|
|
void test_htmlCharEncCheckAsciiCompatible_unknown_encoding_returns_minus1(void) { |
|
|
htmlParserCtxtPtr ctxt = make_ctxt(); |
|
|
|
|
|
int ret = test_htmlCharEncCheckAsciiCompatible(ctxt, (const xmlChar *)"X-DOES-NOT-EXIST"); |
|
|
TEST_ASSERT_EQUAL_INT_MESSAGE(-1, ret, "Unknown encodings should be rejected"); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
} |
|
|
|
|
|
int main(void) { |
|
|
|
|
|
xmlInitParser(); |
|
|
|
|
|
UNITY_BEGIN(); |
|
|
RUN_TEST(test_htmlCharEncCheckAsciiCompatible_utf8_returns_0); |
|
|
RUN_TEST(test_htmlCharEncCheckAsciiCompatible_utf8_mixed_case_returns_0); |
|
|
RUN_TEST(test_htmlCharEncCheckAsciiCompatible_us_ascii_returns_0); |
|
|
RUN_TEST(test_htmlCharEncCheckAsciiCompatible_utf16_returns_minus1); |
|
|
RUN_TEST(test_htmlCharEncCheckAsciiCompatible_unknown_encoding_returns_minus1); |
|
|
int rc = UNITY_END(); |
|
|
|
|
|
xmlCleanupParser(); |
|
|
return rc; |
|
|
} |