2007-10-19 Marek Habersack <mhabersack@novell.com>
[mono.git] / eglib / test / array.c
index 64f7b427f97dbc58daef41b97f9f0cd32ec2074d..37d5486ace50574f9326296890339d80a748d434 100644 (file)
@@ -83,6 +83,49 @@ test_array_append ()
        return NULL;
 }
 
+RESULT
+test_array_insert_val ()
+{
+       GArray *array = g_array_new (FALSE, FALSE, sizeof (gpointer));
+       gpointer ptr0, ptr1, ptr2, ptr3;
+
+       g_array_insert_val (array, 0, array);
+
+       if (array != g_array_index (array, gpointer, 0))
+               return FAILED ("1 The value in the array is incorrect");
+
+       g_array_insert_val (array, 1, array);
+       if (array != g_array_index (array, gpointer, 1))
+               return FAILED ("2 The value in the array is incorrect");
+
+       g_array_insert_val (array, 2, array);
+       if (array != g_array_index (array, gpointer, 2))
+               return FAILED ("3 The value in the array is incorrect");
+       
+       g_array_free (array, TRUE);
+       array = g_array_new (FALSE, FALSE, sizeof (gpointer));
+       ptr0 = array;
+       ptr1 = array + 1;
+       ptr2 = array + 2;
+       ptr3 = array + 3;
+
+       g_array_insert_val (array, 0, ptr0);
+       g_array_insert_val (array, 1, ptr1);
+       g_array_insert_val (array, 2, ptr2);
+       g_array_insert_val (array, 1, ptr3);
+       if (ptr0 != g_array_index (array, gpointer, 0))
+               return FAILED ("4 The value in the array is incorrect");
+       if (ptr3 != g_array_index (array, gpointer, 1))
+               return FAILED ("5 The value in the array is incorrect");
+       if (ptr1 != g_array_index (array, gpointer, 2))
+               return FAILED ("6 The value in the array is incorrect");
+       if (ptr2 != g_array_index (array, gpointer, 3))
+               return FAILED ("7 The value in the array is incorrect");
+
+       g_array_free (array, TRUE);
+       return NULL;
+}
+
 RESULT
 test_array_remove ()
 {
@@ -108,11 +151,12 @@ test_array_remove ()
 }
 
 static Test array_tests [] = {
-       {"array_big", test_array_big},
-       {"array_append", test_array_append},
-       {"array_index", test_array_index},
-       {"array_remove", test_array_remove},
-       {"array_append_zero_terminated", test_array_append_zero_terminated},
+       {"big", test_array_big},
+       {"append", test_array_append},
+       {"insert_val", test_array_insert_val},
+       {"index", test_array_index},
+       {"remove", test_array_remove},
+       {"append_zero_term", test_array_append_zero_terminated},
        {NULL, NULL}
 };