Author: gonzalo
Date: 2006-10-18 14:39:12 -0400 (Wed, 18 Oct 2006)
New Revision: 66798

Modified:
   trunk/mono/eglib/ChangeLog
   trunk/mono/eglib/src/garray.c
   trunk/mono/eglib/test/array.c
Log:
2006-10-18 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * test/array.c: new test for insertion in the middle of other values.
        * src/garray.c: fixed destination index.



Modified: trunk/mono/eglib/ChangeLog
===================================================================
--- trunk/mono/eglib/ChangeLog  2006-10-18 18:39:12 UTC (rev 66797)
+++ trunk/mono/eglib/ChangeLog  2006-10-18 18:39:12 UTC (rev 66798)
@@ -1,3 +1,8 @@
+2006-10-18 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * test/array.c: new test for insertion in the middle of other values.
+       * src/garray.c: fixed destination index.
+
 2006-10-18  Miguel de Icaza  <[EMAIL PROTECTED]>
 
        * src/gpath.c (g_build_path): Do not append terminator if the next

Modified: trunk/mono/eglib/src/garray.c
===================================================================
--- trunk/mono/eglib/src/garray.c       2006-10-18 18:39:12 UTC (rev 66797)
+++ trunk/mono/eglib/src/garray.c       2006-10-18 18:39:12 UTC (rev 66798)
@@ -85,6 +85,9 @@
              gboolean free_segment)
 {
        gchar* rv = NULL;
+
+       g_return_val_if_fail (array != NULL, NULL);
+
        if (free_segment)
                g_free (array->data);
        else
@@ -102,6 +105,8 @@
 {
        GArrayPriv *priv = (GArrayPriv*)array;
 
+       g_return_val_if_fail (array != NULL, NULL);
+
        ensure_capacity (priv, priv->array.len + len + (priv->zero_terminated ? 
1 : 0));
   
        memmove (element_offset (priv, priv->array.len),
@@ -126,8 +131,11 @@
                     guint len)
 {
        GArrayPriv *priv = (GArrayPriv*)array;
+       guint extra = (priv->zero_terminated ? 1 : 0);
 
-       ensure_capacity (priv, array->len + len + (priv->zero_terminated ? 1 : 
0));
+       g_return_val_if_fail (array != NULL, NULL);
+
+       ensure_capacity (priv, array->len + len + extra);
   
        /* first move the existing elements out of the way */
        memmove (element_offset (priv, index_ + len),
@@ -135,7 +143,7 @@
                 element_length (priv, array->len - index_));
 
        /* then copy the new elements into the array */
-       memmove (element_offset (priv, array->len),
+       memmove (element_offset (priv, index_),
                 data,
                 element_length (priv, len));
 
@@ -156,6 +164,8 @@
 {
        GArrayPriv *priv = (GArrayPriv*)array;
 
+       g_return_val_if_fail (array != NULL, NULL);
+
        memmove (element_offset (priv, index_),
                 element_offset (priv, index_ + 1),
                 element_length (priv, array->len - index_));
@@ -170,3 +180,4 @@
 
        return array;
 }
+

Modified: trunk/mono/eglib/test/array.c
===================================================================
--- trunk/mono/eglib/test/array.c       2006-10-18 18:39:12 UTC (rev 66797)
+++ trunk/mono/eglib/test/array.c       2006-10-18 18:39:12 UTC (rev 66798)
@@ -84,19 +84,45 @@
 }
 
 RESULT
-test_array_append2 ()
+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 ("The value in the array is incorrect");
+               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;
 }
 
@@ -127,7 +153,7 @@
 static Test array_tests [] = {
        {"big", test_array_big},
        {"append", test_array_append},
-       {"append2", test_array_append2},
+       {"insert_val", test_array_insert_val},
        {"index", test_array_index},
        {"remove", test_array_remove},
        {"append_zero_term", test_array_append_zero_terminated},

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to