]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add unit test for dec2str_buf()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 14 Nov 2017 18:14:09 +0000 (20:14 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 14 Nov 2017 18:14:09 +0000 (20:14 +0200)
src/lib/test-strfuncs.c

index d7ac4bf6ce6bc91a166ad5eba0287eb5714aaed2..3da9c1d3bcb7308a842af39051e5e1fb2bb212c3 100644 (file)
@@ -348,6 +348,26 @@ static void test_mem_equals_timing_safe(void)
        test_end();
 }
 
+static void test_dec2str_buf(void)
+{
+       const uintmax_t test_input[] = {
+               0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+               99, 999, 9999, 65535, 65536, 99999, 999999, 9999999,
+               99999999, 999999999, 4294967295, 4294967296ULL,
+               9999999999999999999ULL,
+               18446744073709551615ULL
+       };
+       char buf[MAX_INT_STRLEN], buf2[MAX_INT_STRLEN];
+
+       test_begin("dec2str_buf()");
+       for (unsigned int i = 0; i < N_ELEMENTS(test_input); i++) {
+               i_snprintf(buf2, sizeof(buf2), "%ju", test_input[i]);
+               test_assert_idx(strcmp(dec2str_buf(buf, test_input[i]),
+                                      buf2) == 0, i);
+       }
+       test_end();
+}
+
 void test_strfuncs(void)
 {
        test_p_strdup();
@@ -363,4 +383,5 @@ void test_strfuncs(void)
        test_t_strarray_join();
        test_p_array_const_string_join();
        test_mem_equals_timing_safe();
+       test_dec2str_buf();
 }