"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lib/test-strfuncs.c" between
dovecot-2.3.16.tar.gz and dovecot-2.3.17.tar.gz

About: Dovecot is an IMAP and POP3 server, written with security primarily in mind.

test-strfuncs.c  (dovecot-2.3.16):test-strfuncs.c  (dovecot-2.3.17)
skipping to change at line 19 skipping to change at line 19
test_assert(p_strdup(default_pool, NULL) == NULL); test_assert(p_strdup(default_pool, NULL) == NULL);
const char *src = "foo"; const char *src = "foo";
char *str = p_strdup(default_pool, src); char *str = p_strdup(default_pool, src);
test_assert(str != src && str != NULL && strcmp(src, str) == 0); test_assert(str != src && str != NULL && strcmp(src, str) == 0);
p_free(default_pool, str); p_free(default_pool, str);
test_end(); test_end();
} }
static void test_p_strndup(void)
{
struct {
const char *input;
const char *output;
size_t len;
} tests[] = {
{ "foo", "fo", 2 },
{ "foo", "foo", 3 },
{ "foo", "foo", 4 },
{ "foo\0more", "foo", 8 },
};
test_begin("p_strndup()");
for (unsigned int i = 0; i < N_ELEMENTS(tests); i++) {
char *str = p_strndup(default_pool, tests[i].input,
tests[i].len);
test_assert_strcmp_idx(str, tests[i].output, i);
p_free(default_pool, str);
}
test_end();
}
static void test_p_strdup_empty(void) static void test_p_strdup_empty(void)
{ {
test_begin("p_strdup_empty()"); test_begin("p_strdup_empty()");
test_assert(p_strdup_empty(default_pool, NULL) == NULL); test_assert(p_strdup_empty(default_pool, NULL) == NULL);
test_assert(p_strdup_empty(default_pool, "") == NULL); test_assert(p_strdup_empty(default_pool, "") == NULL);
const char *src = "foo"; const char *src = "foo";
char *str = p_strdup_empty(default_pool, src); char *str = p_strdup_empty(default_pool, src);
test_assert(str != src && str != NULL && strcmp(src, str) == 0); test_assert(str != src && str != NULL && strcmp(src, str) == 0);
p_free(default_pool, str); p_free(default_pool, str);
skipping to change at line 475 skipping to change at line 498
/* This is just 2 ways of wording the same test, but that also /* This is just 2 ways of wording the same test, but that also
sanity tests the match values above. */ sanity tests the match values above. */
test_assert_idx(str_begins(tests[i].s1, tests[i].s2) == test_assert_idx(str_begins(tests[i].s1, tests[i].s2) ==
(str_begins(tests[i].s1, tests[i].s2)), i); (str_begins(tests[i].s1, tests[i].s2)), i);
test_assert_idx(str_begins(tests[i].s1, tests[i].s2) == test_assert_idx(str_begins(tests[i].s1, tests[i].s2) ==
(strlen(tests[i].s2) == tests[i].match), i); (strlen(tests[i].s2) == tests[i].match), i);
} }
test_end(); test_end();
} }
static void test_memspn(void)
{
#undef TEST_CASE
/* we substract 1 to ensure we don't include the final \0 byte */
#define TEST_CASE(a, b, r) { \
.input = (const unsigned char*)((a)), .input_len = sizeof((a))-1, \
.accept = (const unsigned char*)((b)), .accept_len = sizeof((b))-1, \
.result = r, \
}
static struct {
const unsigned char *input;
size_t input_len;
const unsigned char *accept;
size_t accept_len;
size_t result;
} tests[] = {
TEST_CASE("", "", 0),
TEST_CASE("", "123456789", 0),
TEST_CASE("123456789", "", 0),
TEST_CASE("hello, world", "helo", 5),
TEST_CASE("hello, uuuuu", "helo", 5),
TEST_CASE("\0\0\0\0\0hello", "\0", 5),
TEST_CASE("\r\r\r\r", "\r", 4),
TEST_CASE("aaa", "a", 3),
TEST_CASE("bbb", "a", 0),
/* null safety test */
{
.input = NULL, .accept = NULL,
.input_len = 0, .accept_len = 0,
.result = 0,
}
};
test_begin("i_memspn");
for (unsigned int i = 0; i < N_ELEMENTS(tests); i++) {
size_t a = i_memspn(tests[i].input, tests[i].input_len,
tests[i].accept, tests[i].accept_len);
test_assert_ucmp_idx(a, ==, tests[i].result, i);
if (tests[i].input == NULL)
continue;
a = i_memspn(tests[i].input, strlen((const char*)tests[i].input),
tests[i].accept, strlen((const char*)tests[i].accept
));
size_t b = strspn((const char*)tests[i].input,
(const char*)tests[i].accept);
test_assert_ucmp_idx(a, ==, b, i);
}
test_end();
}
static void test_memcspn(void)
{
#undef TEST_CASE
/* we substract 1 to ensure we don't include the final \0 byte */
#define TEST_CASE(a, b, r) { \
.input = (const unsigned char*)((a)), .input_len = sizeof((a))-1, \
.reject = (const unsigned char*)((b)), .reject_len = sizeof((b))-1, \
.result = r, \
}
static struct {
const unsigned char *input;
size_t input_len;
const unsigned char *reject;
size_t reject_len;
size_t result;
} tests[] = {
TEST_CASE("", "", 0),
TEST_CASE("hello", "", 5),
TEST_CASE("uuuuu, hello", "helo", 7),
TEST_CASE("\0\0\0\0\0\0hello", "u", 11),
TEST_CASE("this\0is\0test", "\0", 4),
TEST_CASE("hello, world\r", "\r", 12),
TEST_CASE("aaa", "a", 0),
TEST_CASE("bbb", "a", 3),
/* null safety test */
{
.input = NULL, .reject = NULL,
.input_len = 0, .reject_len = 0,
.result = 0,
}
};
test_begin("i_memcspn");
for (unsigned int i = 0; i < N_ELEMENTS(tests); i++) {
size_t a = i_memcspn(tests[i].input, tests[i].input_len,
tests[i].reject, tests[i].reject_len);
test_assert_ucmp_idx(a, ==, tests[i].result, i);
if (tests[i].input == NULL)
continue;
a = i_memcspn(tests[i].input, strlen((const char*)tests[i].input)
,
tests[i].reject, strlen((const char*)tests[i].rejec
t));
size_t b = strcspn((const char*)tests[i].input,
(const char*)tests[i].reject);
test_assert_ucmp_idx(a, ==, b, i);
}
test_end();
}
void test_strfuncs(void) void test_strfuncs(void)
{ {
test_p_strdup(); test_p_strdup();
test_p_strndup();
test_p_strdup_empty(); test_p_strdup_empty();
test_p_strdup_until(); test_p_strdup_until();
test_p_strarray_dup(); test_p_strarray_dup();
test_t_strsplit(); test_t_strsplit();
test_t_strsplit_spaces(); test_t_strsplit_spaces();
test_t_str_replace(); test_t_str_replace();
test_t_str_oneline(); test_t_str_oneline();
test_t_str_trim(); test_t_str_trim();
test_t_str_ltrim(); test_t_str_ltrim();
test_t_str_rtrim(); test_t_str_rtrim();
test_t_strarray_join(); test_t_strarray_join();
test_p_array_const_string_join(); test_p_array_const_string_join();
test_mem_equals_timing_safe(); test_mem_equals_timing_safe();
test_str_equals_timing_almost_safe(); test_str_equals_timing_almost_safe();
test_dec2str_buf(); test_dec2str_buf();
test_str_match(); test_str_match();
test_memspn();
test_memcspn();
}
enum fatal_test_state fatal_strfuncs(unsigned int stage)
{
switch (stage) {
case 0:
test_begin("fatal p_strndup()");
test_expect_fatal_string("(str != NULL)");
(void)p_strndup(default_pool, NULL, 100);
return FATAL_TEST_FAILURE;
case 1:
test_expect_fatal_string("(max_chars != SIZE_MAX)");
(void)p_strndup(default_pool, "foo", SIZE_MAX);
return FATAL_TEST_FAILURE;
}
test_end();
return FATAL_TEST_FINISHED;
} }
 End of changes. 4 change blocks. 
0 lines changed or deleted 149 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)