+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.
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)
{
-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
+++ /dev/null
-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)
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}
};