mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-08 18:36:17 +01:00
tests: Don't compare strings by pointer
clang complains about this in the form of <source>:6:9: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) if (f == (void *)"a") { ^ ~~~~~~~~~~~ Use variables for the strings instead, which should have the same address.
This commit is contained in:
parent
5892c980bf
commit
662059d18a
@ -471,23 +471,26 @@ test_delete_link (void)
|
||||
static void
|
||||
test_prepend (void)
|
||||
{
|
||||
gpointer a = "a";
|
||||
gpointer b = "b";
|
||||
gpointer c = "c";
|
||||
GList *l, *l2;
|
||||
|
||||
l = NULL;
|
||||
l = g_list_prepend (l, "c");
|
||||
l = g_list_prepend (l, "a");
|
||||
l = g_list_prepend (l, c);
|
||||
l = g_list_prepend (l, a);
|
||||
|
||||
g_assert (l->data == (gpointer)"a");
|
||||
g_assert (l->next->data == (gpointer)"c");
|
||||
g_assert (l->data == a);
|
||||
g_assert (l->next->data == c);
|
||||
g_assert (l->next->next == NULL);
|
||||
|
||||
l2 = l->next;
|
||||
l2 = g_list_prepend (l2, "b");
|
||||
l2 = g_list_prepend (l2, b);
|
||||
g_assert (l2->prev == l);
|
||||
|
||||
g_assert (l->data == (gpointer)"a");
|
||||
g_assert (l->next->data == (gpointer)"b");
|
||||
g_assert (l->next->next->data == (gpointer)"c");
|
||||
g_assert (l->data == a);
|
||||
g_assert (l->next->data == b);
|
||||
g_assert (l->next->next->data == c);
|
||||
g_assert (l->next->next->next == NULL);
|
||||
|
||||
g_list_free (l);
|
||||
|
@ -249,6 +249,9 @@ test_slist_remove_all (void)
|
||||
static void
|
||||
test_slist_insert (void)
|
||||
{
|
||||
gpointer a = "a";
|
||||
gpointer b = "b";
|
||||
gpointer c = "c";
|
||||
GSList *slist = NULL;
|
||||
GSList *st;
|
||||
gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
@ -274,23 +277,23 @@ test_slist_insert (void)
|
||||
|
||||
g_slist_free (slist);
|
||||
|
||||
slist = g_slist_insert (NULL, "a", 1);
|
||||
g_assert (slist->data == (gpointer)"a");
|
||||
slist = g_slist_insert (NULL, a, 1);
|
||||
g_assert (slist->data == a);
|
||||
g_assert (slist->next == NULL);
|
||||
g_slist_free (slist);
|
||||
|
||||
slist = g_slist_append (NULL, "a");
|
||||
slist = g_slist_append (slist, "b");
|
||||
slist = g_slist_insert (slist, "c", 5);
|
||||
slist = g_slist_append (NULL, a);
|
||||
slist = g_slist_append (slist, b);
|
||||
slist = g_slist_insert (slist, c, 5);
|
||||
|
||||
g_assert (slist->next->next->data == (gpointer)"c");
|
||||
g_assert (slist->next->next->data == c);
|
||||
g_assert (slist->next->next->next == NULL);
|
||||
g_slist_free (slist);
|
||||
|
||||
slist = g_slist_append (NULL, "a");
|
||||
slist = g_slist_insert_before (slist, slist, "b");
|
||||
g_assert (slist->data == (gpointer)"b");
|
||||
g_assert (slist->next->data == (gpointer)"a");
|
||||
slist = g_slist_append (NULL, a);
|
||||
slist = g_slist_insert_before (slist, slist, b);
|
||||
g_assert (slist->data == b);
|
||||
g_assert (slist->next->data == a);
|
||||
g_assert (slist->next->next == NULL);
|
||||
g_slist_free (slist);
|
||||
}
|
||||
@ -334,17 +337,19 @@ test_slist_position (void)
|
||||
static void
|
||||
test_slist_concat (void)
|
||||
{
|
||||
gpointer a = "a";
|
||||
gpointer b = "b";
|
||||
GSList *s1, *s2, *s;
|
||||
|
||||
s1 = g_slist_append (NULL, "a");
|
||||
s2 = g_slist_append (NULL, "b");
|
||||
s1 = g_slist_append (NULL, a);
|
||||
s2 = g_slist_append (NULL, b);
|
||||
s = g_slist_concat (s1, s2);
|
||||
g_assert (s->data == (gpointer)"a");
|
||||
g_assert (s->next->data == (gpointer)"b");
|
||||
g_assert (s->data == a);
|
||||
g_assert (s->next->data == b);
|
||||
g_assert (s->next->next == NULL);
|
||||
g_slist_free (s);
|
||||
|
||||
s1 = g_slist_append (NULL, "a");
|
||||
s1 = g_slist_append (NULL, a);
|
||||
|
||||
s = g_slist_concat (NULL, s1);
|
||||
g_assert_cmpint (g_slist_length (s), ==, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user