dovecot-2.2: lib: test-str-sanitize - tighten tests
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 28 13:54:30 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/e5157203e96d
changeset: 17657:e5157203e96d
user: Phil Carmody <phil at dovecot.fi>
date: Mon Jul 28 16:49:47 2014 +0300
description:
lib: test-str-sanitize - tighten tests
Check that the identical string is returned in the no-change case, not
just a copy.
Signed-off-by: Phil Carmody <phil at dovecot.fi>
diffstat:
src/lib/test-str-sanitize.c | 46 ++++++++++++++++++--------------------------
1 files changed, 19 insertions(+), 27 deletions(-)
diffs (67 lines):
diff -r ec534d652137 -r e5157203e96d src/lib/test-str-sanitize.c
--- a/src/lib/test-str-sanitize.c Mon Jul 28 16:45:33 2014 +0300
+++ b/src/lib/test-str-sanitize.c Mon Jul 28 16:49:47 2014 +0300
@@ -3,44 +3,36 @@
#include "test-lib.h"
#include "str-sanitize.h"
-struct str_sanitize_input {
+struct str_sanitize_test {
const char *str;
unsigned int max_len;
+ const char *sanitized; /* NULL for no change */
};
void test_str_sanitize(void)
{
- static struct str_sanitize_input input[] = {
- { NULL, 2 },
- { "", 2 },
- { "a", 2 },
- { "ab", 2 },
- { "abc", 2 },
- { "abcd", 3 },
- { "abcde", 4 },
- { "с", 10 },
- { "с", 1 },
- { "\001x\x1fy\x81", 10 }
- };
- static const char *output[] = {
- NULL,
- "",
- "a",
- "ab",
- "...",
- "...",
- "a...",
- "с",
- "с",
- "?x?y?"
+ static struct str_sanitize_test tests[] = {
+ { NULL, 2, NULL },
+ { "", 2, NULL },
+ { "a", 2, NULL },
+ { "ab", 2, NULL },
+ { "abc", 2, "..." },
+ { "abcd", 3, "..." },
+ { "abcde", 4, "a..." },
+ { "с", 10, NULL },
+ { "с", 1, NULL },
+ { "\001x\x1fy\x81", 10, "?x?y?" }
};
const char *str;
unsigned int i;
test_begin("str_sanitize");
- for (i = 0; i < N_ELEMENTS(input); i++) {
- str = str_sanitize(input[i].str, input[i].max_len);
- test_assert(null_strcmp(output[i], str) == 0);
+ for (i = 0; i < N_ELEMENTS(tests); i++) {
+ str = str_sanitize(tests[i].str, tests[i].max_len);
+ if (tests[i].sanitized != NULL)
+ test_assert_idx(null_strcmp(str, tests[i].sanitized) == 0, i);
+ else
+ test_assert_idx(str == tests[i].str, i);
}
test_end();
}
More information about the dovecot-cvs
mailing list