2010-04-16 Sebastien Pouliot <sebastien@ximian.com>
[mono/afaerber.git] / eglib / test / sizes.c
blob585cc113779009048e775123a80643319e6c3cd0
1 /*
2 * Tests to ensure that our type definitions are correct
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"
14 RESULT
15 test_formats ()
17 char buffer [1024];
18 gsize a = 1;
20 sprintf (buffer, "%" G_GSIZE_FORMAT, a);
22 return NULL;
25 RESULT
26 test_ptrconv ()
28 int iv, iv2;
29 unsigned int uv, uv2;
30 gpointer ptr;
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);
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);
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);
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);
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);
62 uv = 0;
63 ptr = GUINT_TO_POINTER (iv);
64 uv2 = GPOINTER_TO_UINT (ptr);
65 if (iv != iv2)
66 return FAILED ("uint to pointer and back conversions fail %u != %d", iv, iv2);
68 uv = 1;
69 ptr = GUINT_TO_POINTER (iv);
70 uv2 = GPOINTER_TO_UINT (ptr);
71 if (iv != iv2)
72 return FAILED ("uint to pointer and back conversions fail %u != %d", iv, iv2);
74 uv = UINT32_MAX;
75 ptr = GUINT_TO_POINTER (iv);
76 uv2 = GPOINTER_TO_UINT (ptr);
77 if (iv != iv2)
78 return FAILED ("uint to pointer and back conversions fail %u != %d", iv, iv2);
80 return NULL;
84 typedef struct {
85 int a;
86 int b;
87 } my_struct;
89 RESULT
90 test_offset ()
92 if (G_STRUCT_OFFSET (my_struct, a) != 0)
93 return FAILED ("offset of a is not zero");
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");
98 return OK;
101 static Test size_tests [] = {
102 {"formats", test_formats},
103 {"ptrconv", test_ptrconv},
104 {"g_struct_offset", test_offset},
105 {NULL, NULL}
108 DEFINE_TEST_GROUP_INIT(size_tests_init, size_tests)