6 /* example from glib documentation */
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
);
31 GArray
*array
= g_array_new (FALSE
, FALSE
, sizeof (int));
35 g_array_append_val (array
, v
);
37 if (27 != g_array_index (array
, int, 0))
40 g_array_free (array
, TRUE
);
46 test_array_append_zero_terminated ()
48 GArray
*array
= g_array_new (TRUE
, FALSE
, sizeof (int));
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
);
68 GArray
*array
= g_array_new (FALSE
, FALSE
, sizeof (int));
72 return FAILED ("initial array length not zero");
76 g_array_append_val (array
, v
);
79 return FAILED ("array append failed");
81 g_array_free (array
, TRUE
);
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
));
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
);
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);
138 return FAILED ("append_vals fail");
140 g_array_remove_index (array
, 3);
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
);
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
},
163 DEFINE_TEST_GROUP_INIT(array_tests_init
, array_tests
)