test-strnum.c revision bee4935fb14a078052e4524070910fd0b8135ef7
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Copyright (c) 2014-2014 Dovecot authors, see the included COPYING file */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define VALID(n) { #n, 0, n }
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainenstatic void test_str_to_u64(void)
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen unsigned int i;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const struct {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen VALID(000000000000000000000000000000000000000000000000000000000000000),
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen { "000000000000000000000000000000000000000000000000000001000000001", 0, 1000000001 },
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen { "18446744073709551615", 0, 18446744073709551615ULL },
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen INVALID(20496382304121724010), /* 2^64*10/9 doesn't wrap */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen INVALID(20496382304121724017), /* 2^64*10/9 wraps only after addition */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen INVALID(20496382304121724020), /* 2^64*10/9 wraps on multiply*/
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int ret = str_to_uint64(u64tests[i].input, &val);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen test_assert_idx(val == 0xBADBEEF15BADF00D, i);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *longer = t_strconcat(u64tests[i].input, "x", NULL);
static void test_str_to_u32(void)
const char *input;
int ret;
} u32tests[] = {
VALID(0),
INVALID(-0),
if (ret == 0)
test_end();
static void test_str_to_llong(void)
const char *input;
int ret;
long long val;
} i64tests[] = {
VALID(0),
VALID(-0),
INVALID(--0),
if (ret == 0)
test_end();
static void test_str_to_i32(void)
const char *input;
int ret;
int val;
} i32tests[] = {
VALID(0),
VALID(-0),
INVALID(--0),
if (ret == 0)
test_end();
void test_strnum(void)