diff options
author | Gary Kramlich <grim@reaperworld.com> | 2022-12-12 23:38:47 -0600 |
---|---|---|
committer | Gary Kramlich <grim@reaperworld.com> | 2022-12-12 23:38:47 -0600 |
commit | 9f10f9a1168f322ce8ccdc95b088acfb63caf67d (patch) | |
tree | 9ec0f716d8fc2f005bc023dfeaf5df2107584780 /libpurple/tests | |
parent | a9f24b22eabb8bc6aeb1db10e06fd4f9d1d2c623 (diff) | |
download | pidgin-9f10f9a1168f322ce8ccdc95b088acfb63caf67d.tar.gz |
Create PurpleAvatar to represent avatars
Testing Done:
Ran the unit tests and manually verified the docs.
Reviewed at https://reviews.imfreedom.org/r/2092/
Diffstat (limited to 'libpurple/tests')
-rw-r--r-- | libpurple/tests/meson.build | 1 | ||||
-rw-r--r-- | libpurple/tests/test_avatar.c | 97 |
2 files changed, 98 insertions, 0 deletions
diff --git a/libpurple/tests/meson.build b/libpurple/tests/meson.build index 0fee70bb87..8e29cba4cc 100644 --- a/libpurple/tests/meson.build +++ b/libpurple/tests/meson.build @@ -2,6 +2,7 @@ PROGS = [ 'account_option', 'account_manager', 'authorization_request', + 'avatar', 'circular_buffer', 'contact', 'contact_info', diff --git a/libpurple/tests/test_avatar.c b/libpurple/tests/test_avatar.c new file mode 100644 index 0000000000..b7dbe3b212 --- /dev/null +++ b/libpurple/tests/test_avatar.c @@ -0,0 +1,97 @@ +/* + * Purple - Internet Messaging Library + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <https://www.gnu.org/licenses/>. + */ + +#include <glib.h> + +#include <purple.h> + +/****************************************************************************** + * Tests + *****************************************************************************/ +static void +test_purple_avatar_new(void) { + PurpleAvatar *avatar = NULL; + GdkPixbuf *pixbuf = NULL; + + pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); + avatar = purple_avatar_new("filename", pixbuf); + + g_assert_true(PURPLE_IS_AVATAR(avatar)); + + g_assert_cmpstr(purple_avatar_get_filename(avatar), ==, "filename"); + g_assert_true(purple_avatar_get_pixbuf(avatar) == pixbuf); + + g_clear_object(&avatar); + g_clear_object(&pixbuf); +} + +static void +test_purple_avatar_properties(void) { + PurpleAvatar *avatar = NULL; + PurpleTags *tags = NULL; + GdkPixbuf *pixbuf = NULL; + GdkPixbuf *pixbuf1 = NULL; + gchar *filename = NULL; + + pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); + + /* Use g_object_new so we can test setting properties by name. All of them + * call the setter methods, so by doing it this way we exercise more of the + * code. + */ + avatar = g_object_new( + PURPLE_TYPE_AVATAR, + "filename", "filename", + "pixbuf", pixbuf, + NULL); + + /* Now use g_object_get to read all of the properties. */ + g_object_get(avatar, + "filename", &filename, + "pixbuf", &pixbuf1, + "tags", &tags, + NULL); + + /* Compare all the things. */ + g_assert_cmpstr(filename, ==, "filename"); + g_assert_true(pixbuf1 == pixbuf); + g_assert_nonnull(tags); + + /* Free/unref all the things. */ + g_clear_pointer(&filename, g_free); + g_clear_object(&pixbuf1); + g_clear_object(&tags); + + g_clear_object(&avatar); + g_clear_object(&pixbuf); +} + +/****************************************************************************** + * Main + *****************************************************************************/ +gint +main(gint argc, gchar *argv[]) { + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/avatar/new", + test_purple_avatar_new); + g_test_add_func("/avatar/properties", + test_purple_avatar_properties); + + return g_test_run(); +} |