Add TLS offset probing to mach-amd64 in the same way it's done on x86.
[mono-project.git] / eglib / test / array.c
blob37d5486ace50574f9326296890339d80a748d434
1 #include <stdio.h>
2 #include <string.h>
3 #include <glib.h>
4 #include "test.h"
6 /* example from glib documentation */
7 RESULT
8 test_array_big ()
10 GArray *garray;
11 gint i;
13 /* We create a new array to store gint values.
14 We don't want it zero-terminated or cleared to 0's. */
15 garray = g_array_new (FALSE, FALSE, sizeof (gint));
16 for (i = 0; i < 10000; i++)
17 g_array_append_val (garray, i);
19 for (i = 0; i < 10000; i++)
20 if (g_array_index (garray, gint, i) != i)
21 return FAILED ("array value didn't match");
23 g_array_free (garray, TRUE);
25 return NULL;
28 RESULT
29 test_array_index ()
31 GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
32 int v;
34 v = 27;
35 g_array_append_val (array, v);
37 if (27 != g_array_index (array, int, 0))
38 return FAILED ("");
40 g_array_free (array, TRUE);
42 return NULL;
45 RESULT
46 test_array_append_zero_terminated ()
48 GArray *array = g_array_new (TRUE, FALSE, sizeof (int));
49 int v;
51 v = 27;
52 g_array_append_val (array, v);
54 if (27 != g_array_index (array, int, 0))
55 return FAILED ("g_array_append_val failed");
57 if (0 != g_array_index (array, int, 1))
58 return FAILED ("zero_terminated didn't append a zero element");
60 g_array_free (array, TRUE);
62 return NULL;
65 RESULT
66 test_array_append ()
68 GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
69 int v;
71 if (0 != array->len)
72 return FAILED ("initial array length not zero");
74 v = 27;
76 g_array_append_val (array, v);
78 if (1 != array->len)
79 return FAILED ("array append failed");
81 g_array_free (array, TRUE);
83 return NULL;
86 RESULT
87 test_array_insert_val ()
89 GArray *array = g_array_new (FALSE, FALSE, sizeof (gpointer));
90 gpointer ptr0, ptr1, ptr2, ptr3;
92 g_array_insert_val (array, 0, array);
94 if (array != g_array_index (array, gpointer, 0))
95 return FAILED ("1 The value in the array is incorrect");
97 g_array_insert_val (array, 1, array);
98 if (array != g_array_index (array, gpointer, 1))
99 return FAILED ("2 The value in the array is incorrect");
101 g_array_insert_val (array, 2, array);
102 if (array != g_array_index (array, gpointer, 2))
103 return FAILED ("3 The value in the array is incorrect");
105 g_array_free (array, TRUE);
106 array = g_array_new (FALSE, FALSE, sizeof (gpointer));
107 ptr0 = array;
108 ptr1 = array + 1;
109 ptr2 = array + 2;
110 ptr3 = array + 3;
112 g_array_insert_val (array, 0, ptr0);
113 g_array_insert_val (array, 1, ptr1);
114 g_array_insert_val (array, 2, ptr2);
115 g_array_insert_val (array, 1, ptr3);
116 if (ptr0 != g_array_index (array, gpointer, 0))
117 return FAILED ("4 The value in the array is incorrect");
118 if (ptr3 != g_array_index (array, gpointer, 1))
119 return FAILED ("5 The value in the array is incorrect");
120 if (ptr1 != g_array_index (array, gpointer, 2))
121 return FAILED ("6 The value in the array is incorrect");
122 if (ptr2 != g_array_index (array, gpointer, 3))
123 return FAILED ("7 The value in the array is incorrect");
125 g_array_free (array, TRUE);
126 return NULL;
129 RESULT
130 test_array_remove ()
132 GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
133 int v[] = {30, 29, 28, 27, 26, 25};
135 g_array_append_vals (array, v, 6);
137 if (6 != array->len)
138 return FAILED ("append_vals fail");
140 g_array_remove_index (array, 3);
142 if (5 != array->len)
143 return FAILED ("remove_index failed to update length");
145 if (26 != g_array_index (array, int, 3))
146 return FAILED ("remove_index failed to update the array");
148 g_array_free (array, TRUE);
150 return NULL;
153 static Test array_tests [] = {
154 {"big", test_array_big},
155 {"append", test_array_append},
156 {"insert_val", test_array_insert_val},
157 {"index", test_array_index},
158 {"remove", test_array_remove},
159 {"append_zero_term", test_array_append_zero_terminated},
160 {NULL, NULL}
163 DEFINE_TEST_GROUP_INIT(array_tests_init, array_tests)