X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=eglib%2Ftest%2Fslist.c;h=3f8360ecae9536cc9f3749543a442693071f3afa;hb=998a69a6b11cbc130de5ae124c2482748cd0ebdd;hp=afa58a43d684e80f72c1655389b59de0f56c5780;hpb=1fabd87b02f8d2e359150ed7a9e92613e60383bc;p=mono.git diff --git a/eglib/test/slist.c b/eglib/test/slist.c index afa58a43d68..3f8360ecae9 100644 --- a/eglib/test/slist.c +++ b/eglib/test/slist.c @@ -3,6 +3,66 @@ #include #include "test.h" + +RESULT +test_slist_nth () +{ + char *foo = "foo"; + char *bar = "bar"; + char *baz = "baz"; + GSList *nth, *list; + list = g_slist_prepend (NULL, baz); + list = g_slist_prepend (list, bar); + list = g_slist_prepend (list, foo); + + nth = g_slist_nth (list, 0); + if (nth->data != foo) + return FAILED ("nth failed. #0"); + + nth = g_slist_nth (list, 1); + if (nth->data != bar) + return FAILED ("nth failed. #1"); + + nth = g_slist_nth (list, 2); + if (nth->data != baz) + return FAILED ("nth failed. #2"); + + nth = g_slist_nth (list, 3); + if (nth) + return FAILED ("nth failed. #3: %s", nth->data); + + g_slist_free (list); + return OK; +} + +RESULT +test_slist_index () +{ + int i; + char *foo = "foo"; + char *bar = "bar"; + char *baz = "baz"; + GSList *list; + list = g_slist_prepend (NULL, baz); + list = g_slist_prepend (list, bar); + list = g_slist_prepend (list, foo); + + i = g_slist_index (list, foo); + if (i != 0) + return FAILED ("index failed. #0: %d", i); + + i = g_slist_index (list, bar); + if (i != 1) + return FAILED ("index failed. #1: %d", i); + + i = g_slist_index (list, baz); + if (i != 2) + return FAILED ("index failed. #2: %d", i); + + g_slist_free (list); + return OK; +} + RESULT test_slist_append () { @@ -59,6 +119,34 @@ test_slist_find () return OK; } +static gint +find_custom (gconstpointer a, gconstpointer b) +{ + return(strcmp (a, b)); +} + +RESULT +test_slist_find_custom () +{ + GSList *list = NULL, *found; + char *foo = "foo"; + char *bar = "bar"; + char *baz = "baz"; + + list = g_slist_prepend (list, baz); + list = g_slist_prepend (list, bar); + list = g_slist_prepend (list, foo); + + found = g_slist_find_custom (list, baz, find_custom); + + if (found == NULL) + return FAILED ("Find failed"); + + g_slist_free (list); + + return OK; +} + RESULT test_slist_remove () { @@ -239,9 +327,12 @@ test_slist_sort () } static Test slist_tests [] = { + {"nth", test_slist_nth}, + {"index", test_slist_index}, {"append", test_slist_append}, {"concat", test_slist_concat}, {"find", test_slist_find}, + {"find_custom", test_slist_find_custom}, {"remove", test_slist_remove}, {"remove_link", test_slist_remove_link}, {"insert_sorted", test_slist_insert_sorted},