dovecot-2.2: lib-imap: Added unit tests for imap_append_[an]stri...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Nov 30 11:15:59 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/326711633532
changeset: 19436:326711633532
user: Timo Sirainen <tss at iki.fi>
date: Mon Nov 30 13:15:44 2015 +0200
description:
lib-imap: Added unit tests for imap_append_[an]string()
diffstat:
src/lib-imap/test-imap-quote.c | 66 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 66 insertions(+), 0 deletions(-)
diffs (80 lines):
diff -r 9eab653f5b94 -r 326711633532 src/lib-imap/test-imap-quote.c
--- a/src/lib-imap/test-imap-quote.c Mon Nov 30 13:14:29 2015 +0200
+++ b/src/lib-imap/test-imap-quote.c Mon Nov 30 13:15:44 2015 +0200
@@ -37,10 +37,76 @@
test_end();
}
+static void test_imap_append_astring(void)
+{
+ static struct {
+ const char *input, *output;
+ } tests[] = {
+ { "", "\"\"" },
+ { "NIL", "\"NIL\"" },
+ { "niL", "\"niL\"" },
+ { "ni", "ni" },
+ { "\\", "\"\\\\\"" },
+ { "\\\\", "\"\\\\\\\\\"" },
+ { "\\\\\\", "\"\\\\\\\\\\\\\"" },
+ { "\\\\\\\\", "\"\\\\\\\\\\\\\\\\\"" },
+ { "\\\\\\\\\\", "{5}\r\n\\\\\\\\\\" },
+ { "\\\\\\\\\\\\", "{6}\r\n\\\\\\\\\\\\" },
+ { "\"", "\"\\\"\"" },
+ { "\"\"", "\"\\\"\\\"\"" },
+ { "\"\"\"", "\"\\\"\\\"\\\"\"" },
+ { "\"\"\"\"", "\"\\\"\\\"\\\"\\\"\"" },
+ { "\"\"\"\"\"", "{5}\r\n\"\"\"\"\"" },
+ { "\"\"\"\"\"\"", "{6}\r\n\"\"\"\"\"\"" },
+ { "\r", "{1}\r\n\r" },
+ { "\n", "{1}\r\n\n" },
+ { "\r\n", "{2}\r\n\r\n" },
+ { "\x7f", "\"\x7f\"" },
+ { "\x80", "{1}\r\n\x80" },
+ { "\xff", "{1}\r\n\xff" },
+ };
+ string_t *str = t_str_new(128);
+ unsigned int i;
+
+ test_begin("test_imap_append_astring()");
+
+ for (i = 0; i < N_ELEMENTS(tests); i++) {
+ str_truncate(str, 0);
+ imap_append_astring(str, tests[i].input);
+ test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i);
+ }
+ test_end();
+}
+
+static void test_imap_append_nstring(void)
+{
+ static struct {
+ const char *input, *output;
+ } tests[] = {
+ { "", "\"\"" },
+ { NULL, "NIL" },
+ { "NIL", "\"NIL\"" },
+ { "ni", "\"ni\"" }
+ };
+ string_t *str = t_str_new(128);
+ unsigned int i;
+
+ test_begin("test_imap_append_nstring()");
+
+ for (i = 0; i < N_ELEMENTS(tests); i++) {
+ str_truncate(str, 0);
+ imap_append_nstring(str, tests[i].input);
+ test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i);
+ }
+ test_end();
+}
+
int main(void)
{
static void (*test_functions[])(void) = {
test_imap_append_string_for_humans,
+ test_imap_append_astring,
+ test_imap_append_nstring,
NULL
};
return test_run(test_functions);
More information about the dovecot-cvs
mailing list