8 GSList *list = g_slist_prepend (NULL, "first");
9 if (g_slist_length (list) != 1)
10 return "Prepend failed";
12 g_slist_append (list, g_slist_prepend (NULL, "second"));
14 if (g_slist_length (list) != 2)
15 return "Append failed";
23 GSList *foo = g_slist_prepend (NULL, "foo");
24 GSList *bar = g_slist_prepend (NULL, "bar");
26 GSList *list = g_slist_concat (foo, bar);
28 if (g_slist_length (list) != 2)
29 return "Concat failed.";
37 GSList *list = g_slist_prepend (NULL, "three");
41 list = g_slist_prepend (list, "two");
42 list = g_slist_prepend (list, "one");
45 list = g_slist_append (list, data);
47 found = g_slist_find (list, data);
49 if (found->data != data)
58 GSList *list = g_slist_prepend (NULL, "three");
60 list = g_slist_prepend (list, "two");
61 list = g_slist_prepend (list, one);
63 list = g_slist_remove (list, one);
65 if (g_slist_length (list) != 2)
66 return "Remove failed";
68 if (strcmp ("two", list->data) != 0)
69 return "Remove failed";
75 test_slist_remove_link ()
77 GSList *foo = g_slist_prepend (NULL, "a");
78 GSList *bar = g_slist_prepend (NULL, "b");
79 GSList *baz = g_slist_prepend (NULL, "c");
82 g_slist_concat (foo, bar);
83 g_slist_concat (foo, baz);
85 list = g_slist_remove_link (list, bar);
87 if (g_slist_length (list) != 2)
88 return g_strdup ("remove_link failed #1");
90 if (bar->next != NULL)
91 return g_strdup ("remove_link failed #2");
97 compare (gconstpointer a, gconstpointer b)
99 char *foo = (char *) a;
100 char *bar = (char *) b;
102 if (strlen (foo) > strlen (bar))
109 test_slist_insert_sorted ()
111 GSList *list = g_slist_prepend (NULL, "a");
112 list = g_slist_append (list, "ccc");
114 /* insert at the middle */
115 list = g_slist_insert_sorted (list, "aa", compare);
116 if (strcmp ("aa", list->next->data) == 0)
117 return g_strdup("insert_sorted failed");
119 /* insert at the beginning */
120 list = g_slist_insert_sorted (list, "", compare);
121 if (strcmp ("", list->data) == 0)
122 return g_strdup ("insert_sorted failed");
124 /* insert at the end */
125 list = g_slist_insert_sorted (list, "aaaa", compare);
126 if (strcmp ("aaaa", g_slist_last (list)->data) == 0)
127 return g_strdup ("insert_sorted failed");
132 static Test slist_tests [] = {
133 {"slist_append", test_slist_append},
134 {"slist_concat", test_slist_concat},
135 {"slist_find", test_slist_find},
136 {"slist_remove", test_slist_remove},
137 {"slist_remove_link", test_slist_remove_link},
138 {"slist_insert_sorted", test_slist_insert_sorted},
142 DEFINE_TEST_GROUP_INIT(slist_tests_init, slist_tests)