pidgin/pidgin

4af13de1fee2
Parents ed15916ec9ed
Children 21858f98040c
Finish up the unit tests for the attention cleanup
--- a/libpurple/tests/meson.build Thu Jan 18 23:46:05 2018 -0600
+++ b/libpurple/tests/meson.build Thu Jan 25 22:58:24 2018 -0600
@@ -1,5 +1,7 @@
PROGS = [
+ 'attention_type',
'image',
+ 'protocol_attention',
'protocol_xfer',
'smiley',
'smiley_list',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_attention_type.c Thu Jan 25 22:58:24 2018 -0600
@@ -0,0 +1,181 @@
+/*
+ * Purple
+ *
+ * Purple is the legal property of its developers, whose names are too
+ * numerous to list here. Please refer to the COPYRIGHT file distributed
+ * with this source distribution
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include <purple.h>
+
+#include "dbus-server.h"
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_purple_attention_type_new(void) {
+ PurpleAttentionType *type = NULL;
+
+ type = purple_attention_type_new("id", "name", "incoming", "outgoing");
+
+ /* check the values new sets */
+ g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type), ==, "id");
+ g_assert_cmpstr(purple_attention_type_get_name(type), ==, "name");
+ g_assert_cmpstr(purple_attention_type_get_incoming_desc(type), ==, "incoming");
+ g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type), ==, "outgoing");
+
+ /* check that default values are correct */
+ g_assert_cmpstr(purple_attention_type_get_icon_name(type), ==, NULL);
+
+ g_free(type);
+}
+
+static void
+test_purple_attention_type_copy(void) {
+ PurpleAttentionType *type1 = NULL, *type2 = NULL;
+
+ type1 = purple_attention_type_new("id", "name", "incoming", "outgoing");
+
+ type2 = purple_attention_type_copy(type1);
+
+ /* check the values new sets */
+ g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type2), ==, "id");
+ g_assert_cmpstr(purple_attention_type_get_name(type2), ==, "name");
+ g_assert_cmpstr(purple_attention_type_get_incoming_desc(type2), ==, "incoming");
+ g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type2), ==, "outgoing");
+
+ /* check that default values are correct */
+ g_assert_cmpstr(purple_attention_type_get_icon_name(type2), ==, NULL);
+
+ g_free(type1);
+ g_free(type2);
+}
+
+static void
+test_purple_attention_type_set_unlocalized_name(void) {
+ PurpleAttentionType *type = NULL;
+
+ type = purple_attention_type_new("id", "name", "incoming", "outgoing");
+
+ purple_attention_type_set_unlocalized_name(type, "this-is-my-id");
+ g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type), ==, "this-is-my-id");
+
+ g_free(type);
+}
+
+static void
+test_purple_attention_type_set_name(void) {
+ PurpleAttentionType *type = NULL;
+
+ type = purple_attention_type_new("id", "name", "incoming", "outgoing");
+
+ purple_attention_type_set_name(type, "this-is-my-name");
+ g_assert_cmpstr(purple_attention_type_get_name(type), ==, "this-is-my-name");
+
+ g_free(type);
+}
+
+static void
+test_purple_attention_type_set_incoming_desc(void) {
+ PurpleAttentionType *type = NULL;
+
+ type = purple_attention_type_new("id", "name", "incoming", "outgoing");
+
+ purple_attention_type_set_incoming_desc(type, "this-is-my-incoming-desc");
+ g_assert_cmpstr(purple_attention_type_get_incoming_desc(type), ==, "this-is-my-incoming-desc");
+
+ g_free(type);
+}
+
+static void
+test_purple_attention_type_set_outgoing_desc(void) {
+ PurpleAttentionType *type = NULL;
+
+ type = purple_attention_type_new("id", "name", "incoming", "outgoing");
+
+ purple_attention_type_set_outgoing_desc(type, "this-is-my-outgoing-desc");
+ g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type), ==, "this-is-my-outgoing-desc");
+
+ g_free(type);
+}
+
+static void
+test_purple_attention_type_set_icon_name(void) {
+ PurpleAttentionType *type = NULL;
+
+ type = purple_attention_type_new("id", "name", "incoming", "outgoing");
+
+ purple_attention_type_set_icon_name(type, "this-is-my-icon-name");
+ g_assert_cmpstr(purple_attention_type_get_icon_name(type), ==, "this-is-my-icon-name");
+
+ g_free(type);
+}
+
+/******************************************************************************
+ * Main
+ *****************************************************************************/
+gint
+main(gint argc, gchar **argv) {
+ gint res = 0;
+
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_set_nonfatal_assertions();
+
+ g_test_add_func(
+ "/attention-type/new",
+ test_purple_attention_type_new
+ );
+
+ g_test_add_func(
+ "/attention-type/copy",
+ test_purple_attention_type_copy
+ );
+
+ g_test_add_func(
+ "/attention-type/set-unlocalized-name",
+ test_purple_attention_type_set_unlocalized_name
+ );
+
+ g_test_add_func(
+ "/attention-type/set-name",
+ test_purple_attention_type_set_name
+ );
+
+ g_test_add_func(
+ "/attention-type/set-incoming-desc",
+ test_purple_attention_type_set_incoming_desc
+ );
+
+ g_test_add_func(
+ "/attention-type/set-outgoing-desc",
+ test_purple_attention_type_set_outgoing_desc
+ );
+
+ g_test_add_func(
+ "/attention-type/set-icon-name",
+ test_purple_attention_type_set_icon_name
+ );
+
+ res = g_test_run();
+
+ return res;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_protocol_attention.c Thu Jan 25 22:58:24 2018 -0600
@@ -0,0 +1,156 @@
+/*
+ * Purple
+ *
+ * Purple is the legal property of its developers, whose names are too
+ * numerous to list here. Please refer to the COPYRIGHT file distributed
+ * with this source distribution
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include <purple.h>
+
+#include "dbus-server.h"
+
+#include "test_ui.h"
+
+/******************************************************************************
+ * PurpleProtcolAttention Implementations
+ *****************************************************************************/
+static GType test_purple_protocol_attention_get_type(void);
+
+typedef struct {
+ PurpleProtocol parent;
+
+ gboolean send_called;
+} TestPurpleProtocolAttention;
+
+typedef struct {
+ PurpleProtocolClass parent;
+} TestPurpleProtocolAttentionClass;
+
+
+static gboolean
+test_purple_protocol_attention_send(PurpleProtocolAttention *attn, PurpleConnection *c, const gchar *username, guint type) {
+ TestPurpleProtocolAttention *test_attn = (TestPurpleProtocolAttention *)attn;
+
+ test_attn->send_called = TRUE;
+
+ return TRUE;
+}
+
+static GList *
+test_purple_protocol_attention_get_types(PurpleProtocolAttention *attn, PurpleAccount *acct) {
+ GList *types = NULL;
+
+ types = g_list_append(types, purple_attention_type_new("id", "name", "incoming", "outgoing"));
+
+ return types;
+}
+
+static void
+test_purple_protocol_attention_iface_init(PurpleProtocolAttentionInterface *iface) {
+ iface->send = test_purple_protocol_attention_send;
+ iface->get_types = test_purple_protocol_attention_get_types;
+}
+
+G_DEFINE_TYPE_WITH_CODE(
+ TestPurpleProtocolAttention,
+ test_purple_protocol_attention,
+ PURPLE_TYPE_PROTOCOL,
+ G_IMPLEMENT_INTERFACE(
+ PURPLE_TYPE_PROTOCOL_ATTENTION,
+ test_purple_protocol_attention_iface_init
+ )
+);
+
+static void
+test_purple_protocol_attention_init(TestPurpleProtocolAttention *prplattn) {
+ PurpleProtocol *prpl = PURPLE_PROTOCOL(prplattn);
+
+ prpl->id = "prpl-attention";
+}
+
+static void
+test_purple_protocol_attention_class_init(TestPurpleProtocolAttentionClass *klass) {
+}
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_purple_protocol_attention_can_send(void) {
+ TestPurpleProtocolAttention *attn = g_object_new(test_purple_protocol_attention_get_type(), NULL);
+ PurpleAccount *a = purple_account_new("prpl-attn-can-send", "prpl-attn");
+ PurpleConnection *c = g_object_new(PURPLE_TYPE_CONNECTION, "account", a, NULL);
+ gboolean actual = FALSE;
+
+ attn->send_called = FALSE;
+ actual = purple_protocol_attention_send(PURPLE_PROTOCOL_ATTENTION(attn), c, "someguy", 0);
+ g_assert_true(actual);
+
+ g_assert_true(attn->send_called);
+}
+
+static void
+test_purple_protocol_attention_can_get_types(void) {
+ TestPurpleProtocolAttention *attn = g_object_new(test_purple_protocol_attention_get_type(), NULL);
+ PurpleAccount *a = purple_account_new("prpl-attn-can-get-types", "prpl-attn");
+ GList *types = NULL;
+ PurpleAttentionType *type = NULL;
+
+ types = purple_protocol_attention_get_types(PURPLE_PROTOCOL_ATTENTION(attn), a);
+ g_assert_true(g_list_length(types) == 1);
+
+ // take the first item and cast it into type
+ type = (PurpleAttentionType *)(types->data);
+ g_assert(type);
+
+ g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type), ==, "id");
+ g_assert_cmpstr(purple_attention_type_get_name(type), ==, "name");
+ g_assert_cmpstr(purple_attention_type_get_incoming_desc(type), ==, "incoming");
+ g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type), ==, "outgoing");
+}
+
+/******************************************************************************
+ * Main
+ *****************************************************************************/
+gint
+main(gint argc, gchar **argv) {
+ gint res = 0;
+
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_set_nonfatal_assertions();
+
+ test_ui_purple_init();
+
+ g_test_add_func(
+ "/protocol-attention/send",
+ test_purple_protocol_attention_can_send
+ );
+
+ g_test_add_func(
+ "/protocol-attention/get-types",
+ test_purple_protocol_attention_can_get_types
+ );
+
+ res = g_test_run();
+
+ return res;
+}