[msvc] Update csproj files
[mono.git] / eglib / test / list.c
index 46be8c4484a91e4ec3bececedba42c32f71c4aa2..68dadee612afd0912105c7d880468529ee79173f 100644 (file)
@@ -306,20 +306,22 @@ test_list_insert_before ()
        return OK;
 }
 
-#define N_ELEMS 100
+#define N_ELEMS 101
 
 static int intcompare (gconstpointer p1, gconstpointer p2)
 {
        return GPOINTER_TO_INT (p1) - GPOINTER_TO_INT (p2);
 }
 
-static gboolean verify_sort (GList *list)
+static gboolean verify_sort (GList *list, int len)
 {
-       list = g_list_sort (list, intcompare);
+       int prev;
+
        if (list->prev)
                return FALSE;
 
-       int prev = GPOINTER_TO_INT (list->data);
+       prev = GPOINTER_TO_INT (list->data);
+       len--;
        for (list = list->next; list; list = list->next) {
                int curr = GPOINTER_TO_INT (list->data);
                if (prev > curr)
@@ -328,19 +330,24 @@ static gboolean verify_sort (GList *list)
 
                if (!list->prev || list->prev->next != list)
                        return FALSE;
+
+               if (len == 0)
+                       return FALSE;
+               len--;
        }
-       return TRUE;
+       return len == 0;
 }
 
 RESULT
 test_list_sort ()
 {
-       int i = 0;
+       int i, j, mul;
        GList *list = NULL;
 
        for (i = 0; i < N_ELEMS; ++i)
                list = g_list_prepend (list, GINT_TO_POINTER (i));
-       if (!verify_sort (list))
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, N_ELEMS))
                return FAILED ("decreasing list");
 
        g_list_free (list);
@@ -348,26 +355,67 @@ test_list_sort ()
        list = NULL;
        for (i = 0; i < N_ELEMS; ++i)
                list = g_list_prepend (list, GINT_TO_POINTER (-i));
-       if (!verify_sort (list))
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, N_ELEMS))
                return FAILED ("increasing list");
 
        g_list_free (list);
 
+       list = g_list_prepend (NULL, GINT_TO_POINTER (0));
+       for (i = 1; i < N_ELEMS; ++i) {
+               list = g_list_prepend (list, GINT_TO_POINTER (i));
+               list = g_list_prepend (list, GINT_TO_POINTER (-i));
+       }
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, 2*N_ELEMS-1))
+               return FAILED ("alternating list");
+
+       g_list_free (list);
+
        list = NULL;
-       int mul = 1;
-       for (i = 0; i < N_ELEMS; ++i) {
-               list = g_list_prepend (list, GINT_TO_POINTER (mul * i));
+       mul = 1;
+       for (i = 1; i < N_ELEMS; ++i) {
                mul = -mul;
+               for (j = 0; j < i; ++j)
+                       list = g_list_prepend (list, GINT_TO_POINTER (mul * j));
        }
-
-       if (!verify_sort (list))
-               return FAILED ("alternating list");
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, (N_ELEMS*N_ELEMS - N_ELEMS)/2))
+               return FAILED ("wavering list");
 
        g_list_free (list);
 
        return OK;
 }
 
+static gint
+find_custom (gconstpointer a, gconstpointer b)
+{
+       return(strcmp (a, b));
+}
+
+RESULT
+test_list_find_custom ()
+{
+       GList *list = NULL, *found;
+       char *foo = "foo";
+       char *bar = "bar";
+       char *baz = "baz";
+       
+       list = g_list_prepend (list, baz);
+       list = g_list_prepend (list, bar);
+       list = g_list_prepend (list, foo);
+       
+       found = g_list_find_custom (list, baz, find_custom);
+       
+       if (found == NULL)
+               return FAILED ("Find failed");
+       
+       g_list_free (list);
+       
+       return OK;
+}
+
 static Test list_tests [] = {
        {       "length", test_list_length},
        {          "nth", test_list_nth},
@@ -383,6 +431,7 @@ static Test list_tests [] = {
        {  "remove_link", test_list_remove_link},
        {  "remove_link", test_list_remove_link},
        {         "sort", test_list_sort},
+       {  "find_custom", test_list_find_custom},
        {NULL, NULL}
 };