2006-08-17 Aaron Bockover <abockover@novell.com>
authorAaron Bockover <abockover@novell.com>
Fri, 18 Aug 2006 03:57:07 +0000 (03:57 -0000)
committerAaron Bockover <abockover@novell.com>
Fri, 18 Aug 2006 03:57:07 +0000 (03:57 -0000)
    * src/gptrarray.c: Implemented g_ptr_array_remove and
    g_ptr_array_remove_index

    * test/other: Removed, rewritten in Makefile.am

    * test/Makefile.am: Build test-eglib against local eglib and
    test-glib against GLib 2.0 (replaces 'other')

    * test/ptrarray.c: Added tests for g_ptr_array_remove and
    g_ptr_array_remove_index

svn path=/trunk/mono/; revision=63964

eglib/ChangeLog
eglib/src/gptrarray.c
eglib/test/Makefile.am
eglib/test/other [deleted file]
eglib/test/ptrarray.c

index a35d9e3450a864832e30b1558529aa0ea2e6ee96..76f2c78839f60e1dd5770b67385c8617cbca77c0 100644 (file)
@@ -1,3 +1,16 @@
+2006-08-17  Aaron Bockover  <abockover@novell.com>
+
+       * src/gptrarray.c: Implemented g_ptr_array_remove and 
+       g_ptr_array_remove_index
+
+       * test/other: Removed, rewritten in Makefile.am
+
+       * test/Makefile.am: Build test-eglib against local eglib and 
+       test-glib against GLib 2.0 (replaces 'other')
+
+       * test/ptrarray.c: Added tests for g_ptr_array_remove and
+       g_ptr_array_remove_index
+
 2006-08-17  Duncan Mak  <duncan@a-chinaman.com>
 
        * src/gslist.c: Added MIT license.
index 7f2aea6818d5213294d82a9a9c60375b9256cb49..6f09e7e72b3f09ac7c4fbc03a30d15a70e2f05fe 100644 (file)
@@ -121,6 +121,44 @@ g_ptr_array_add(GPtrArray *array, gpointer data)
        array->pdata[array->len++] = data;
 }
 
+gpointer
+g_ptr_array_remove_index(GPtrArray *array, guint index)
+{
+       gpointer removed_node;
+       
+       g_return_val_if_fail(array != NULL, NULL);
+       g_return_val_if_fail(index >= 0 || index < array->len, NULL);
+
+       removed_node = array->pdata[index];
+
+       if(index != array->len - 1) {
+               g_memmove(array->pdata + index, array->pdata + index + 1,
+                       (array->len - index - 1) * sizeof(gpointer));
+       }
+       
+       array->len -= 1;
+//     array->pdata[array->len - 1] = NULL;
+
+       return removed_node;
+}
+
+gboolean
+g_ptr_array_remove(GPtrArray *array, gpointer data)
+{
+       guint i;
+
+       g_return_val_if_fail(array != NULL, FALSE);
+
+       for(i = 0; i < array->len; i++) {
+               if(array->pdata[i] == data) {
+                       g_ptr_array_remove_index(array, i);
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
 void 
 g_ptr_array_foreach(GPtrArray *array, GFunc func, gpointer user_data)
 {
index 36df80a4007f774835fa408b3a062aa39451ee3e..f8b98668d4c06f6aa9f8db971ca13e2c1f5b9273 100644 (file)
@@ -1,20 +1,24 @@
-noinst_PROGRAMS = test 
+noinst_PROGRAMS = test-eglib test-glib
 
-test_SOURCES =    \
-       test.c          \
-       test.h          \
-       tests.h         \
-       driver.c        \
-       hashtable.c     \
-       string-util.c   \
-       string.c        \
-       slist.c       \
+SOURCES = \
+       test.c \
+       test.h \
+       tests.h \
+       driver.c \
+       hashtable.c \
+       string-util.c \
+       string.c \
+       slist.c \
        ptrarray.c
 
-test_CFLAGS = -Wall -Werror -D_FORTIFY_SOURCE=2
-INCLUDES = -I../src
+test_eglib_SOURCES = $(SOURCES)
+test_glib_SOURCES = $(SOURCES)
 
-test_LDADD = -L../src -leglib
+test_eglib_CFLAGS = -Wall -Werror -D_FORTIFY_SOURCE=2 -I../src
+test_eglib_LDADD = -L../src -leglib
+
+test_glib_CFLAGS = `pkg-config --cflags glib-2.0`
+test_glib_LDFLAGS = `pkg-config --libs glib-2.0`
 
 MAINTAINERCLEANFILES = Makefile.in
 
diff --git a/eglib/test/other b/eglib/test/other
deleted file mode 100755 (executable)
index 05e38dd..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-SOURCES="test.c driver.c hashtable.c string-util.c slist.c string.c ptrarray.c"
-
-OBJS=`echo $SOURCES | sed -e 's/\.c/\.o/g'`
-mkdir o2 >& /dev/null
-
-(cd o2; for i in $SOURCES; do
-       gcc -Wall -Werror -c ../$i `pkg-config --cflags glib-2.0`
-done;
-gcc -o basetest $OBJS `pkg-config --libs glib-2.0`;
-./basetest)
index 370b93b791703da58d17dd9edbd97f6a8e068cb4..615eb7d45a12241ceac3a4609adad95d34e93979 100644 (file)
@@ -149,11 +149,61 @@ char *ptrarray_set_size()
        return NULL;
 }
 
+char *ptrarray_remove_index()
+{
+       GPtrArray *array;
+       gint i;
+       
+       array = ptrarray_alloc_and_fill(&i);
+       
+       g_ptr_array_remove_index(array, 0);
+       if(array->pdata[0] != items[1]) {
+               return g_strdup_printf("First item is not %s, it is %s", items[1],
+                       array->pdata[0]);
+       }
+
+       g_ptr_array_remove_index(array, array->len - 1);
+       
+       if(array->pdata[array->len - 1] != items[array->len]) {
+               return g_strdup_printf("Last item is not %s, it is %s", 
+                       items[array->len - 2], array->pdata[array->len - 1]);
+       }
+
+       return NULL;
+}
+
+char *ptrarray_remove()
+{
+       GPtrArray *array;
+       gint i;
+       
+       array = ptrarray_alloc_and_fill(&i);
+
+       g_ptr_array_remove(array, (gpointer)items[7]);
+
+       if(!g_ptr_array_remove(array, (gpointer)items[4])) {
+               return g_strdup_printf("Item %s not removed", items[4]);
+       }
+
+       if(g_ptr_array_remove(array, (gpointer)items[4])) {
+               return g_strdup_printf("Item %s still in array after removal", 
+                       items[4]);
+       }
+
+       if(array->pdata[array->len - 1] != items[array->len + 1]) {
+               return g_strdup_printf("Last item in GPtrArray not correct");
+       }
+
+       return NULL;
+}
+
 static Test ptrarray_tests [] = {
        {"ptrarray_alloc", ptrarray_alloc},
        {"ptrarray_for_iterate", ptrarray_for_iterate},
        {"ptrarray_foreach_iterate", ptrarray_foreach_iterate},
        {"ptrarray_set_size", ptrarray_set_size},
+       {"ptrarray_remove_index", ptrarray_remove_index},
+       {"ptrarray_remove", ptrarray_remove},
        {NULL, NULL}
 };