1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
#include <errno.h>
#include <string.h>
#include <glib.h>
static void
test_uint64 (const gchar *str,
const gchar *end,
gint base,
guint64 result,
gint error)
{
guint64 actual;
gchar *endptr = NULL;
gint err;
errno = 0;
actual = g_ascii_strtoull (str, &endptr, base);
err = errno;
g_assert (actual == result);
g_assert (strcmp (end, endptr) == 0);
g_assert (err == error);
}
static void
test_int64 (const gchar *str,
const gchar *end,
gint base,
gint64 result,
gint error)
{
gint64 actual;
gchar *endptr = NULL;
gint err;
errno = 0;
actual = g_ascii_strtoll (str, &endptr, base);
err = errno;
g_assert (actual == result);
g_assert (strcmp (end, endptr) == 0);
g_assert (err == error);
}
int
main (int argc, char *argv[])
{
test_uint64 ("0", "", 10, 0, 0);
test_uint64 ("+0", "", 10, 0, 0);
test_uint64 ("-0", "", 10, 0, 0);
test_uint64 ("18446744073709551615", "", 10, G_MAXUINT64, 0);
test_uint64 ("18446744073709551616", "", 10, G_MAXUINT64, ERANGE);
test_uint64 ("20xyz", "xyz", 10, 20, 0);
test_uint64 ("-1", "", 10, G_MAXUINT64, 0);
test_int64 ("0", "", 10, 0, 0);
test_int64 ("9223372036854775807", "", 10, G_MAXINT64, 0);
test_int64 ("9223372036854775808", "", 10, G_MAXINT64, ERANGE);
test_int64 ("-9223372036854775808", "", 10, G_MININT64, 0);
test_int64 ("-9223372036854775809", "", 10, G_MININT64, ERANGE);
test_int64 ("32768", "", 10, 32768, 0);
test_int64 ("-32768", "", 10, -32768, 0);
test_int64 ("001", "", 10, 1, 0);
test_int64 ("-001", "", 10, -1, 0);
return 0;
}
|