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