Merge branch 'wip/tbaederr/clang-warnings' into 'master'

tests: Don't compare strings by pointer

See merge request GNOME/glib!1408
This commit is contained in:
Philip Withnall 2020-03-05 11:32:38 +00:00
commit c8ad0aad08
2 changed files with 31 additions and 23 deletions

View File

@ -471,23 +471,26 @@ test_delete_link (void)
static void static void
test_prepend (void) test_prepend (void)
{ {
gpointer a = "a";
gpointer b = "b";
gpointer c = "c";
GList *l, *l2; GList *l, *l2;
l = NULL; l = NULL;
l = g_list_prepend (l, "c"); l = g_list_prepend (l, c);
l = g_list_prepend (l, "a"); l = g_list_prepend (l, a);
g_assert (l->data == (gpointer)"a"); g_assert (l->data == a);
g_assert (l->next->data == (gpointer)"c"); g_assert (l->next->data == c);
g_assert (l->next->next == NULL); g_assert (l->next->next == NULL);
l2 = l->next; l2 = l->next;
l2 = g_list_prepend (l2, "b"); l2 = g_list_prepend (l2, b);
g_assert (l2->prev == l); g_assert (l2->prev == l);
g_assert (l->data == (gpointer)"a"); g_assert (l->data == a);
g_assert (l->next->data == (gpointer)"b"); g_assert (l->next->data == b);
g_assert (l->next->next->data == (gpointer)"c"); g_assert (l->next->next->data == c);
g_assert (l->next->next->next == NULL); g_assert (l->next->next->next == NULL);
g_list_free (l); g_list_free (l);

View File

@ -249,6 +249,9 @@ test_slist_remove_all (void)
static void static void
test_slist_insert (void) test_slist_insert (void)
{ {
gpointer a = "a";
gpointer b = "b";
gpointer c = "c";
GSList *slist = NULL; GSList *slist = NULL;
GSList *st; GSList *st;
gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 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); g_slist_free (slist);
slist = g_slist_insert (NULL, "a", 1); slist = g_slist_insert (NULL, a, 1);
g_assert (slist->data == (gpointer)"a"); g_assert (slist->data == a);
g_assert (slist->next == NULL); g_assert (slist->next == NULL);
g_slist_free (slist); g_slist_free (slist);
slist = g_slist_append (NULL, "a"); slist = g_slist_append (NULL, a);
slist = g_slist_append (slist, "b"); slist = g_slist_append (slist, b);
slist = g_slist_insert (slist, "c", 5); 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_assert (slist->next->next->next == NULL);
g_slist_free (slist); g_slist_free (slist);
slist = g_slist_append (NULL, "a"); slist = g_slist_append (NULL, a);
slist = g_slist_insert_before (slist, slist, "b"); slist = g_slist_insert_before (slist, slist, b);
g_assert (slist->data == (gpointer)"b"); g_assert (slist->data == b);
g_assert (slist->next->data == (gpointer)"a"); g_assert (slist->next->data == a);
g_assert (slist->next->next == NULL); g_assert (slist->next->next == NULL);
g_slist_free (slist); g_slist_free (slist);
} }
@ -334,17 +337,19 @@ test_slist_position (void)
static void static void
test_slist_concat (void) test_slist_concat (void)
{ {
gpointer a = "a";
gpointer b = "b";
GSList *s1, *s2, *s; GSList *s1, *s2, *s;
s1 = g_slist_append (NULL, "a"); s1 = g_slist_append (NULL, a);
s2 = g_slist_append (NULL, "b"); s2 = g_slist_append (NULL, b);
s = g_slist_concat (s1, s2); s = g_slist_concat (s1, s2);
g_assert (s->data == (gpointer)"a"); g_assert (s->data == a);
g_assert (s->next->data == (gpointer)"b"); g_assert (s->next->data == b);
g_assert (s->next->next == NULL); g_assert (s->next->next == NULL);
g_slist_free (s); g_slist_free (s);
s1 = g_slist_append (NULL, "a"); s1 = g_slist_append (NULL, a);
s = g_slist_concat (NULL, s1); s = g_slist_concat (NULL, s1);
g_assert_cmpint (g_slist_length (s), ==, 1); g_assert_cmpint (g_slist_length (s), ==, 1);