Thu, 15 May 2025 23:56:42 -0500
Add Purple.Protocol:tags and add unit tests for protocol properties
Testing Done:
Ran the tests under valgrind and called in the turtles.
Reviewed at https://reviews.imfreedom.org/r/4006/
--- a/libpurple/purpleprotocol.c Thu May 15 22:55:59 2025 -0500 +++ b/libpurple/purpleprotocol.c Thu May 15 23:56:42 2025 -0500 @@ -36,6 +36,7 @@ PROP_ICON_SEARCH_PATH, PROP_ICON_RESOURCE_PATH, PROP_OPTIONS, + PROP_TAGS, N_PROPERTIES, }; static GParamSpec *properties[N_PROPERTIES] = {NULL, }; @@ -50,6 +51,8 @@ gchar *icon_resource_path; PurpleProtocolOptions options; + + PurpleTags *tags; } PurpleProtocolPrivate; G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(PurpleProtocol, purple_protocol, @@ -211,6 +214,9 @@ case PROP_OPTIONS: g_value_set_flags(value, purple_protocol_get_options(protocol)); break; + case PROP_TAGS: + g_value_set_object(value, purple_protocol_get_tags(protocol)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); break; @@ -255,7 +261,12 @@ } static void -purple_protocol_init(G_GNUC_UNUSED PurpleProtocol *protocol) { +purple_protocol_init(PurpleProtocol *protocol) { + PurpleProtocolPrivate *priv = NULL; + + priv = purple_protocol_get_instance_private(protocol); + + priv->tags = purple_tags_new(); } static void @@ -271,6 +282,7 @@ g_clear_pointer(&priv->icon_name, g_free); g_clear_pointer(&priv->icon_search_path, g_free); g_clear_pointer(&priv->icon_resource_path, g_free); + g_clear_object(&priv->tags); G_OBJECT_CLASS(purple_protocol_parent_class)->finalize(object); } @@ -376,6 +388,18 @@ 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + /** + * PurpleProtocol:tags: + * + * A [class@Tags] instance for the protocol. + * + * Since: 3.0 + */ + properties[PROP_TAGS] = g_param_spec_object( + "tags", NULL, NULL, + PURPLE_TYPE_TAGS, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(obj_class, N_PROPERTIES, properties); } @@ -494,6 +518,17 @@ return priv->options; } +PurpleTags * +purple_protocol_get_tags(PurpleProtocol *protocol) { + PurpleProtocolPrivate *priv = NULL; + + g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL); + + priv = purple_protocol_get_instance_private(protocol); + + return priv->tags; +} + GList * purple_protocol_get_user_splits(PurpleProtocol *protocol) { PurpleProtocolClass *klass = NULL;
--- a/libpurple/purpleprotocol.h Thu May 15 22:55:59 2025 -0500 +++ b/libpurple/purpleprotocol.h Thu May 15 23:56:42 2025 -0500 @@ -34,6 +34,7 @@ #include <birb.h> +#include "purpletags.h" #include "purpleversion.h" #define PURPLE_TYPE_PROTOCOL (purple_protocol_get_type()) @@ -252,6 +253,18 @@ PurpleProtocolOptions purple_protocol_get_options(PurpleProtocol *protocol); /** + * purple_protocol_get_tags: + * + * Gets the tags object from the protocol. + * + * Returns: (transfer none): The tags instance. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +PurpleTags *purple_protocol_get_tags(PurpleProtocol *protocol); + +/** * purple_protocol_get_user_splits: * @protocol: The #PurpleProtocol instance. *
--- a/libpurple/tests/test_protocol.c Thu May 15 22:55:59 2025 -0500 +++ b/libpurple/tests/test_protocol.c Thu May 15 23:56:42 2025 -0500 @@ -144,6 +144,72 @@ } /****************************************************************************** + * General Tests + *****************************************************************************/ +static void +test_purple_protocol_properties(void) { + PurpleProtocol *protocol = NULL; + PurpleProtocolOptions options = 0; + PurpleTags *tags = NULL; + char *description = NULL; + char *icon_name = NULL; + char *icon_resource_path = NULL; + char *icon_search_path = NULL; + char *id = NULL; + char *name = NULL; + + protocol = g_object_new( + TEST_PURPLE_TYPE_PROTOCOL, + "description", "This is a description", + "icon-name", "icon-name", + "icon-resource-path", "resource-path", + "icon-search-path", "search-path", + "id", "test-protocol", + "name", "Test Protocol", + "options", OPT_PROTO_NO_PASSWORD, + NULL); + + birb_assert_type(protocol, TEST_PURPLE_TYPE_PROTOCOL); + + g_object_get( + G_OBJECT(protocol), + "description", &description, + "icon-name", &icon_name, + "icon-resource-path", &icon_resource_path, + "icon-search-path", &icon_search_path, + "id", &id, + "name", &name, + "options", &options, + "tags", &tags, + NULL); + + g_assert_cmpstr(description, ==, "This is a description"); + g_clear_pointer(&description, g_free); + + g_assert_cmpstr(icon_name, ==, "icon-name"); + g_clear_pointer(&icon_name, g_free); + + g_assert_cmpstr(icon_resource_path, ==, "resource-path"); + g_clear_pointer(&icon_resource_path, g_free); + + g_assert_cmpstr(icon_search_path, ==, "search-path"); + g_clear_pointer(&icon_search_path, g_free); + + g_assert_cmpstr(id, ==, "test-protocol"); + g_clear_pointer(&id, g_free); + + g_assert_cmpstr(name, ==, "Test Protocol"); + g_clear_pointer(&name, g_free); + + g_assert_cmphex(options, ==, OPT_PROTO_NO_PASSWORD); + + birb_assert_type(tags, PURPLE_TYPE_TAGS); + g_clear_object(&tags); + + g_assert_finalize_object(protocol); +} + +/****************************************************************************** * TestPurpleProtocol->can_connect Tests *****************************************************************************/ static void @@ -321,6 +387,8 @@ g_test_init(&argc, &argv, NULL); g_test_set_nonfatal_assertions(); + g_test_add_func("/protocol/properties", test_purple_protocol_properties); + g_test_add_func("/protocol/can-connect/error", test_purple_protocol_can_connect_error); g_test_add_func("/protocol/can-connect/false",