New test.
[mono.git] / eglib / test / sizes.c
1 /*
2  * Tests to ensure that our type definitions are correct
3  *
4  * These depend on -Werror, -Wall being set to catch the build error.
5  */
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <string.h>
9 #include <glib.h>
10 #include "test.h"
11
12 RESULT
13 test_formats ()
14 {
15         char buffer [1024];
16         gsize a = 1;
17         
18         sprintf (buffer, "%" G_GSIZE_FORMAT, a);
19
20         return NULL;
21 }
22
23 RESULT
24 test_ptrconv ()
25 {
26         int iv, iv2;
27         unsigned int uv, uv2;
28         gpointer ptr;
29
30         iv = G_MAXINT32;
31         ptr = GINT_TO_POINTER (iv);
32         iv2 = GPOINTER_TO_INT (ptr);
33         if (iv != iv2)
34                 return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);
35
36         iv = G_MININT32;
37         ptr = GINT_TO_POINTER (iv);
38         iv2 = GPOINTER_TO_INT (ptr);
39         if (iv != iv2)
40                 return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);
41
42         iv = 1;
43         ptr = GINT_TO_POINTER (iv);
44         iv2 = GPOINTER_TO_INT (ptr);
45         if (iv != iv2)
46                 return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);
47
48         iv = -1;
49         ptr = GINT_TO_POINTER (iv);
50         iv2 = GPOINTER_TO_INT (ptr);
51         if (iv != iv2)
52                 return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);
53
54         iv = 0;
55         ptr = GINT_TO_POINTER (iv);
56         iv2 = GPOINTER_TO_INT (ptr);
57         if (iv != iv2)
58                 return FAILED ("int to pointer and back conversions fail %d != %d", iv, iv2);
59
60         uv = 0;
61         ptr = GUINT_TO_POINTER (iv);
62         uv2 = GPOINTER_TO_UINT (ptr);
63         if (iv != iv2)
64                 return FAILED ("uint to pointer and back conversions fail %u != %d", iv, iv2);
65         
66         uv = 1;
67         ptr = GUINT_TO_POINTER (iv);
68         uv2 = GPOINTER_TO_UINT (ptr);
69         if (iv != iv2)
70                 return FAILED ("uint to pointer and back conversions fail %u != %d", iv, iv2);
71
72         uv = UINT32_MAX;
73         ptr = GUINT_TO_POINTER (iv);
74         uv2 = GPOINTER_TO_UINT (ptr);
75         if (iv != iv2)
76                 return FAILED ("uint to pointer and back conversions fail %u != %d", iv, iv2);
77
78         return NULL;
79         
80 }
81
82 typedef struct {
83         int a;
84         int b;
85 } my_struct;
86
87 RESULT
88 test_offset ()
89 {
90         if (G_STRUCT_OFFSET (my_struct, a) != 0)
91                 return FAILED ("offset of a is not zero");
92         
93         if (G_STRUCT_OFFSET (my_struct, b) != 4 && G_STRUCT_OFFSET (my_struct, b) != 8)
94                 return FAILED ("offset of b is 4 or 8, macro might be busted");
95
96         return OK;
97 }
98
99 static Test size_tests [] = {
100         {"formats", test_formats},
101         {"ptrconv", test_ptrconv},
102         {"g_struct_offset", test_offset},
103         {NULL, NULL}
104 };
105
106 DEFINE_TEST_GROUP_INIT(size_tests_init, size_tests)