diff --git a/src/test/regression.c b/src/test/regression.c index 8faf2713..c0f81b1a 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -4640,6 +4640,104 @@ static void test_builtin_compat_tzid (void) icaltimezone_free_builtin_timezones(); } +static void print_lines_marked(const char *lines) +{ + const char *ptr, *next = NULL; + + if(!lines) { + printf(" null\n"); + return; + } + + for(ptr = lines; ptr && *ptr; ptr = next) { + next = strchr(ptr, '\n'); + if(next) { + int dec_cr = ptr < next && next[-1] == '\r'; + printf(" \"%.*s\"\n", (int) (next - ptr - (dec_cr ? 1 : 0)), ptr); + next++; + } else { + printf(" \"%s\"\n", ptr); + } + } +} + +static void test_whitespace_in_text_property(void) +{ + const char *value1 = " a b c "; + /* The next two require value folding */ + const char *value2 = "a b\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + " " + " c"; + const char *value3 = "\ta b\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + " " + " c "; + icalcomponent *comp; + char *str; + + /* Short string with trailing white-space */ + comp = icalcomponent_new_vevent(); + icalcomponent_set_description(comp, value1); + ok("[Short] Read back is what had been set", (strcmp(icalcomponent_get_description(comp), value1) == 0)); + str = icalcomponent_as_ical_string_r(comp); + if(VERBOSE) { + printf("[Short] Exported as:\n"); + print_lines_marked(str); + } + icalcomponent_free(comp); + + comp = icalcomponent_new_from_string(str); + ok("[Short] Read parsed is what had been set", (strcmp(icalcomponent_get_description(comp), value1) == 0)); + if(VERBOSE) { + printf("[Short] Re-exported as:\n"); + print_lines_marked(icalcomponent_as_ical_string(comp)); + } + icalcomponent_free(comp); + + free(str); + + /* Folded string without trailing white-space */ + comp = icalcomponent_new_vevent(); + icalcomponent_set_description(comp, value2); + ok("[Folded no trailing] Read back is what had been set", (strcmp(icalcomponent_get_description(comp), value2) == 0)); + str = icalcomponent_as_ical_string_r(comp); + if(VERBOSE) { + printf("[Folded no trailing] Exported as:\n"); + print_lines_marked(str); + } + icalcomponent_free(comp); + + comp = icalcomponent_new_from_string(str); + ok("[Folded no trailing] Read parsed is what had been set", (strcmp(icalcomponent_get_description(comp), value2) == 0)); + if(VERBOSE) { + printf("[Folded no trailing] Re-exported as:\n"); + print_lines_marked(icalcomponent_as_ical_string(comp)); + } + icalcomponent_free(comp); + + free(str); + + /* Folded string with trailing white-space */ + comp = icalcomponent_new_vevent(); + icalcomponent_set_description(comp, value3); + ok("[Folded with trailing] Read back is what had been set", (strcmp(icalcomponent_get_description(comp), value3) == 0)); + str = icalcomponent_as_ical_string_r(comp); + if(VERBOSE) { + printf("[Folded with trailing] Exported as:\n"); + print_lines_marked(str); + } + icalcomponent_free(comp); + + comp = icalcomponent_new_from_string(str); + ok("[Folded with trailing] Read parsed is what had been set", (strcmp(icalcomponent_get_description(comp), value3) == 0)); + if(VERBOSE) { + printf("[Folded with trailing] Re-exported as:\n"); + print_lines_marked(icalcomponent_as_ical_string(comp)); + } + icalcomponent_free(comp); + + free(str); +} + int main(int argc, char *argv[]) { #if !defined(HAVE_UNISTD_H) @@ -4778,6 +4876,7 @@ int main(int argc, char *argv[]) test_run("Test icalcomponent_normalize", test_icalcomponent_normalize, do_test, do_header); test_run("Test builtin compat TZID", test_builtin_compat_tzid, do_test, do_header); + test_run("Test white space in TEXT property", test_whitespace_in_text_property, do_test, do_header); /** OPTIONAL TESTS go here... **/