| | #include "unity/unity.h" |
| | #include <libxml/HTMLparser.h> |
| | #include <libxml/xmlstring.h> |
| | #include <string.h> |
| | #include <stdlib.h> |
| |
|
| | |
| | #ifndef LIBXML_TEST_FOR_EXTERN_PROTOTYPE |
| | int htmlIsScriptAttribute(const xmlChar *name); |
| | #endif |
| |
|
| | void setUp(void) { |
| | |
| | } |
| |
|
| | void tearDown(void) { |
| | |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_null_returns0(void) { |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute(NULL)); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_empty_string_returns0(void) { |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"")); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_non_on_prefix_returns0(void) { |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"href")); |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"class")); |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"data-test")); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_known_script_attributes_return1(void) { |
| | TEST_ASSERT_EQUAL_INT(1, htmlIsScriptAttribute((const xmlChar *)"onclick")); |
| | TEST_ASSERT_EQUAL_INT(1, htmlIsScriptAttribute((const xmlChar *)"onload")); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_case_sensitivity(void) { |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"onClick")); |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"ONLOAD")); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_exact_match_only(void) { |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"onclicked")); |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"onclick ")); |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)" onload")); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_only_on_is_not_script(void) { |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"on")); |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"o")); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_on_prefix_but_not_known_returns0(void) { |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"onfoobar")); |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)"on____not_real____attr")); |
| | } |
| |
|
| | void test_htmlIsScriptAttribute_long_nonmatch_returns0(void) { |
| | char buf[2048]; |
| | memset(buf, 'x', sizeof(buf)); |
| | buf[0] = 'o'; |
| | buf[1] = 'n'; |
| | buf[sizeof(buf) - 1] = '\0'; |
| | TEST_ASSERT_EQUAL_INT(0, htmlIsScriptAttribute((const xmlChar *)buf)); |
| | } |
| |
|
| | int main(void) { |
| | UNITY_BEGIN(); |
| | RUN_TEST(test_htmlIsScriptAttribute_null_returns0); |
| | RUN_TEST(test_htmlIsScriptAttribute_empty_string_returns0); |
| | RUN_TEST(test_htmlIsScriptAttribute_non_on_prefix_returns0); |
| | RUN_TEST(test_htmlIsScriptAttribute_known_script_attributes_return1); |
| | RUN_TEST(test_htmlIsScriptAttribute_case_sensitivity); |
| | RUN_TEST(test_htmlIsScriptAttribute_exact_match_only); |
| | RUN_TEST(test_htmlIsScriptAttribute_only_on_is_not_script); |
| | RUN_TEST(test_htmlIsScriptAttribute_on_prefix_but_not_known_returns0); |
| | RUN_TEST(test_htmlIsScriptAttribute_long_nonmatch_returns0); |
| | return UNITY_END(); |
| | } |