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