Mercurial > dovecot > core-2.2
changeset 19676:286e4218fb07
lib: Add tests for str_is_float
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Fri, 29 Jan 2016 10:29:05 +0200 |
parents | 364874711d5b |
children | a904c19c42ff |
files | src/lib/test-strnum.c |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/test-strnum.c Fri Jan 29 10:28:53 2016 +0200 +++ b/src/lib/test-strnum.c Fri Jan 29 10:29:05 2016 +0200 @@ -358,6 +358,32 @@ test_end(); } +static void test_str_is_float(void) +{ + test_begin("str_is_float accepts integer"); + /* accepts integer */ + test_assert(str_is_float("0",'\0')); + test_assert(str_is_float("1234",'\0')); + test_end(); + test_begin("str_is_float accepts float"); + test_assert(str_is_float("0.0",'\0')); + test_assert(str_is_float("1234.0",'\0')); + test_assert(str_is_float("0.1234",'\0')); + test_assert(str_is_float("1234.1234",'\0')); + test_assert(str_is_float("0.1234 ",' ')); + test_assert(str_is_float("1234.1234",'.')); + test_end(); + test_begin("str_is_float refuses invalid values"); + test_assert(!str_is_float(".",'\0')); + test_assert(!str_is_float(".1234",'\0')); + test_assert(!str_is_float("1234.",'\0')); + test_assert(!str_is_float("i am not a float at all",'\0')); + test_assert(!str_is_float("0x1234.0x1234",'\0')); + test_assert(!str_is_float(".0",'\0')); + test_assert(!str_is_float("0.",'\0')); + test_end(); +} + void test_strnum(void) { /* If the above isn't true, then we do expect some failures possibly */ @@ -368,4 +394,5 @@ test_str_to_u32(); test_str_to_llong(); test_str_to_i32(); + test_str_is_float(); }