]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add tests for str_is_float
authorAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 29 Jan 2016 08:29:05 +0000 (10:29 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 29 Jan 2016 08:58:15 +0000 (10:58 +0200)
src/lib/test-strnum.c

index 637bdf852a0d84604805e71b4d78d1df7c3586f1..c2925dc254594ddc7c53f75bdf8eeeff7a295100 100644 (file)
@@ -358,6 +358,32 @@ static void test_str_to_i32(void)
        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 @@ void test_strnum(void)
        test_str_to_u32();
        test_str_to_llong();
        test_str_to_i32();
+       test_str_is_float();
 }