/* we compile as C90 but use snprintf */ #define _ISOC99_SOURCE #include #include #include #include "minunit.h" #include "modp_xml.h" /** * Test empty input to decode */ static char* testXmlDecodeEmpty(void) { size_t d; char buf[1000]; buf[0] = 1; d = modp_xml_decode(buf, "", (size_t)0); mu_assert_int_equals(d, 0); mu_assert(buf[0] == 0); return 0; } /** * Test characters that should be unchanged * Mostly a copy from URL encoding */ static char* testXmlDecodeUntouched(void) { const char* lower = "abcdefghijklmnopqrstuvwxyz"; const char* upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char* digits = "0123456789"; const char* special = ".-_~!$()*,;:@/?"; char buf[1000]; size_t d = 0; memset(buf, 0, sizeof(buf)); d = modp_xml_decode(buf, lower, strlen(lower)); mu_assert_int_equals(d, strlen(lower)); mu_assert_str_equals(buf, lower); memset(buf, 0, sizeof(buf)); d = modp_xml_decode(buf, upper, strlen(upper)); mu_assert_int_equals(d, strlen(upper)); mu_assert_str_equals(buf, upper); memset(buf, 0, sizeof(buf)); d = modp_xml_decode(buf, digits, strlen(digits)); mu_assert_int_equals(d, strlen(digits)); mu_assert_str_equals(buf, digits); memset(buf, 0, sizeof(buf)); d = modp_xml_decode(buf, special, strlen(special)); mu_assert_int_equals(d, strlen(special)); mu_assert_str_equals(buf, special); return 0; } /** * Test characters that should be unchanged * Mostly a copy from URL encoding */ static char* testXmlDecodeNames(void) { const char* strin = "X"X'X&X>X<X"; const char* strout = "X\"X'X&X>X