diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-01-18 12:23:03 -0500 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-01-19 16:24:40 -0500 |
commit | 26d77d70c6f7f52efb2dd7a829416015d87ee26c (patch) | |
tree | c1a5242b0f6b8c011867181a1df9256eb2467235 | |
parent | 7439e7a8b2bd37141b7c1591bc4ffce8909bf6a6 (diff) |
Refactored TplEntity and added unit-test
-rw-r--r-- | telepathy-logger/channel-text.c | 95 | ||||
-rw-r--r-- | telepathy-logger/entity-internal.h | 17 | ||||
-rw-r--r-- | telepathy-logger/entity.c | 171 | ||||
-rw-r--r-- | telepathy-logger/log-store-sqlite.c | 9 | ||||
-rw-r--r-- | telepathy-logger/log-store-xml.c | 23 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/suppressions/tpl.supp | 20 | ||||
-rw-r--r-- | tests/test-entity.c | 66 |
8 files changed, 200 insertions, 203 deletions
diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c index f8a9a7386..f9ed2d1ea 100644 --- a/telepathy-logger/channel-text.c +++ b/telepathy-logger/channel-text.c @@ -1048,8 +1048,8 @@ on_sent_signal_cb (TpChannel *proxy, GError *error = NULL; TplChannelText *tpl_text = TPL_CHANNEL_TEXT (user_data); TpContact *me; - TplEntity *tpl_entity_sender; - TplEntity *tpl_entity_receiver = NULL; + TplEntity *sender; + TplEntity *receiver = NULL; TplEventText *text_log; TplEvent *log; TplLogManager *logmanager; @@ -1066,8 +1066,7 @@ on_sent_signal_cb (TpChannel *proxy, /* Initialize data for TplEntity */ me = _tpl_channel_text_get_my_contact (tpl_text); - tpl_entity_sender = _tpl_entity_from_tp_contact (me); - _tpl_entity_set_entity_type (tpl_entity_sender, TPL_ENTITY_SELF); + sender = _tpl_entity_new_from_tp_contact (me, TPL_ENTITY_SELF); if (!_tpl_channel_text_is_chatroom (tpl_text)) { @@ -1078,35 +1077,34 @@ on_sent_signal_cb (TpChannel *proxy, GUINT_TO_POINTER (handle)); g_assert (remote != NULL); - tpl_entity_receiver = _tpl_entity_from_tp_contact (remote); - _tpl_entity_set_entity_type (tpl_entity_receiver, TPL_ENTITY_CONTACT); + receiver = _tpl_entity_new_from_tp_contact (remote, TPL_ENTITY_CONTACT); DEBUG ("sent:\n\tlog_id=\"%s\"\n\tto=\"%s " "(%s)\"\n\tfrom=\"%s (%s)\"\n\tmsg=\"%s\"", log_id, - tpl_entity_get_identifier (tpl_entity_receiver), - tpl_entity_get_alias (tpl_entity_receiver), - tpl_entity_get_identifier (tpl_entity_sender), - tpl_entity_get_alias (tpl_entity_sender), + tpl_entity_get_identifier (receiver), + tpl_entity_get_alias (receiver), + tpl_entity_get_identifier (sender), + tpl_entity_get_alias (sender), arg_Text); } else { + receiver = _tpl_entity_new_from_room_id ( + _tpl_channel_text_get_chatroom_id (tpl_text)); + DEBUG ("sent:\n\tlog_id=\"%s\"\n\tto " "chatroom=\"%s\"\n\tfrom=\"%s (%s)\"\n\tmsg=\"%s\"", log_id, - _tpl_channel_text_get_chatroom_id (tpl_text), - tpl_entity_get_identifier (tpl_entity_sender), - tpl_entity_get_alias (tpl_entity_sender), + tpl_entity_get_identifier (receiver), + tpl_entity_get_identifier (sender), + tpl_entity_get_alias (sender), arg_Text); } /* Initialise TplEventText */ - if (!_tpl_channel_text_is_chatroom (tpl_text)) - chat_id = tpl_entity_get_identifier (tpl_entity_receiver); - else - chat_id = _tpl_channel_text_get_chatroom_id (tpl_text); + chat_id = tpl_entity_get_identifier (receiver); account = _tpl_channel_get_account (TPL_CHANNEL (tpl_text)); @@ -1118,10 +1116,8 @@ on_sent_signal_cb (TpChannel *proxy, _tpl_event_set_channel_path (TPL_EVENT (log), channel_path); _tpl_event_set_id (log, chat_id); _tpl_event_set_timestamp (log, (time_t) arg_Timestamp); - _tpl_event_set_sender (log, tpl_entity_sender); - /* NULL when it's a chatroom */ - if (tpl_entity_receiver != NULL) - _tpl_event_set_receiver (log, tpl_entity_receiver); + _tpl_event_set_sender (log, sender); + _tpl_event_set_receiver (log, receiver); _tpl_event_text_set_message (text_log, arg_Text); _tpl_event_text_set_signal_type (text_log, TPL_EVENT_TEXT_SIGNAL_SENT); _tpl_event_text_set_message_type (text_log, arg_Type); @@ -1140,9 +1136,8 @@ on_sent_signal_cb (TpChannel *proxy, g_error_free (error); } - if (tpl_entity_receiver != NULL) - g_object_unref (tpl_entity_receiver); - g_object_unref (tpl_entity_sender); + g_object_unref (receiver); + g_object_unref (sender); g_object_unref (logmanager); g_object_unref (log); @@ -1207,37 +1202,33 @@ keepon_on_receiving_signal (TplEventText *text_log, TplChannelText *tpl_text; GError *e = NULL; TplLogManager *logmanager; - TplEntity *tpl_entity_sender; - TplEntity *tpl_entity_receiver; - TpContact *local; + TplEntity *sender; + TplEntity *receiver; + TpContact *me; g_return_if_fail (TPL_IS_EVENT_TEXT (text_log)); tpl_text = _tpl_event_text_get_tpl_channel_text (text_log); - local = _tpl_channel_text_get_my_contact (tpl_text); - - tpl_entity_sender = _tpl_entity_from_tp_contact (remote); - _tpl_entity_set_entity_type (tpl_entity_sender, TPL_ENTITY_CONTACT); - _tpl_event_set_sender (log, tpl_entity_sender); + me = _tpl_channel_text_get_my_contact (tpl_text); + receiver = _tpl_entity_new_from_tp_contact (me, TPL_ENTITY_SELF); - tpl_entity_receiver = _tpl_entity_from_tp_contact (local); + sender = _tpl_entity_new_from_tp_contact (remote, TPL_ENTITY_CONTACT); + _tpl_event_set_sender (log, sender); DEBUG ("recvd:\n\tlog_id=\"%s\"\n\tto=\"%s " "(%s)\"\n\tfrom=\"%s (%s)\"\n\tmsg=\"%s\"", _tpl_event_get_log_id (log), - tpl_entity_get_identifier (tpl_entity_receiver), - tpl_entity_get_alias (tpl_entity_receiver), - tpl_entity_get_identifier (tpl_entity_sender), - tpl_entity_get_alias (tpl_entity_sender), + tpl_entity_get_identifier (receiver), + tpl_entity_get_alias (receiver), + tpl_entity_get_identifier (sender), + tpl_entity_get_alias (sender), tpl_event_text_get_message (text_log)); if (!_tpl_channel_text_is_chatroom (tpl_text)) - _tpl_event_set_id (log, tpl_entity_get_identifier ( - tpl_entity_sender)); + _tpl_event_set_id (log, tpl_entity_get_identifier (sender)); else - _tpl_event_set_id (log, _tpl_channel_text_get_chatroom_id ( - tpl_text)); + _tpl_event_set_id (log, _tpl_channel_text_get_chatroom_id (tpl_text)); _tpl_event_text_set_chatroom (text_log, _tpl_channel_text_is_chatroom (tpl_text)); @@ -1250,7 +1241,8 @@ keepon_on_receiving_signal (TplEventText *text_log, g_error_free (e); } - g_object_unref (tpl_entity_sender); + g_object_unref (sender); + g_object_unref (receiver); g_object_unref (log); g_object_unref (logmanager); } @@ -1271,9 +1263,8 @@ on_received_signal_cb (TpChannel *proxy, TplChannel *tpl_chan = TPL_CHANNEL (tpl_text); TpConnection *tp_conn; TpContact *me, *remote; - TplEntity *tpl_entity_receiver = NULL; + TplEntity *receiver = NULL; TplEventText *text_log = NULL; - TplEvent *log; TpAccount *account = _tpl_channel_get_account (TPL_CHANNEL (tpl_text)); TplLogStore *index = _tpl_log_store_sqlite_dup (); const gchar *channel_path = tp_proxy_get_object_path (TP_PROXY (tpl_text)); @@ -1316,9 +1307,8 @@ on_received_signal_cb (TpChannel *proxy, /* Initialize TplEventText (part 1) - chat_id still unknown */ text_log = _tpl_event_text_new (log_id, account); - log = TPL_EVENT (text_log); - _tpl_event_set_channel_path (log, channel_path); + _tpl_event_set_channel_path (TPL_EVENT (text_log), channel_path); _tpl_event_text_set_pending_msg_id (text_log, arg_ID); _tpl_event_text_set_tpl_channel_text (text_log, tpl_text); _tpl_event_text_set_message (text_log, arg_Text); @@ -1327,11 +1317,10 @@ on_received_signal_cb (TpChannel *proxy, TPL_EVENT_TEXT_SIGNAL_RECEIVED); me = _tpl_channel_text_get_my_contact (tpl_text); - tpl_entity_receiver = _tpl_entity_from_tp_contact (me); - _tpl_entity_set_entity_type (tpl_entity_receiver, TPL_ENTITY_SELF); - _tpl_event_set_receiver (log, tpl_entity_receiver); + receiver = _tpl_entity_new_from_tp_contact (me, TPL_ENTITY_SELF); + _tpl_event_set_receiver (TPL_EVENT (text_log), receiver); - _tpl_event_set_timestamp (log, (time_t) arg_Timestamp); + _tpl_event_set_timestamp (TPL_EVENT (text_log), (time_t) arg_Timestamp); tp_conn = tp_channel_borrow_connection (TP_CHANNEL (tpl_chan)); remote = g_hash_table_lookup (tpl_text->priv->contacts, @@ -1342,7 +1331,7 @@ on_received_signal_cb (TpChannel *proxy, /* Contact is not in the cache */ tp_connection_get_contacts_by_handle (tp_conn, 1, &sender, G_N_ELEMENTS (features), features, on_received_signal_with_contact_cb, - log, NULL, G_OBJECT (tpl_text)); + text_log, NULL, G_OBJECT (tpl_text)); } else { @@ -1350,8 +1339,8 @@ on_received_signal_cb (TpChannel *proxy, } out: - if (tpl_entity_receiver != NULL) - g_object_unref (tpl_entity_receiver); + if (receiver != NULL) + g_object_unref (receiver); g_object_unref (index); /* log is unrefed in keepon_on_receiving_signal() */ diff --git a/telepathy-logger/entity-internal.h b/telepathy-logger/entity-internal.h index 3b63b7735..ab29e4783 100644 --- a/telepathy-logger/entity-internal.h +++ b/telepathy-logger/entity-internal.h @@ -37,21 +37,8 @@ typedef struct GObjectClass parent_class; } TplEntityClass; -TplEntity *_tpl_entity_new (const gchar *identifier); -TplEntity *_tpl_entity_from_tp_contact (TpContact *contact); -TplEntity *_tpl_entity_from_room_id (const gchar *chatroom_id); - -void _tpl_entity_set_alias (TplEntity *self, - const gchar *data); - -void _tpl_entity_set_identifier (TplEntity *self, - const gchar *data); - -void _tpl_entity_set_entity_type (TplEntity *self, - TplEntityType data); - -void _tpl_entity_set_avatar_token (TplEntity *self, - const gchar *data); +TplEntity *_tpl_entity_new_from_tp_contact (TpContact *contact, TplEntityType type); +TplEntity *_tpl_entity_new_from_room_id (const gchar *room_id); G_END_DECLS #endif // __TPL_ENTITY_INTERNAL_H__ diff --git a/telepathy-logger/entity.c b/telepathy-logger/entity.c index f574db7a1..4b09088b4 100644 --- a/telepathy-logger/entity.c +++ b/telepathy-logger/entity.c @@ -31,15 +31,15 @@ /** * SECTION:entity * @title: TplEntity - * @short_description: Representation of a contact or chatroom + * @short_description: Representation of a contact or room * - * An object representing a contact or chatroom. + * An object representing a contact or room. */ /** * TplEntity: * - * An object representing a contact or chatroom. + * An object representing a contact or room. */ G_DEFINE_TYPE (TplEntity, tpl_entity, G_TYPE_OBJECT) @@ -55,6 +55,7 @@ struct _TplEntityPriv enum { PROP0, + PROP_TYPE, PROP_IDENTIFIER, PROP_ALIAS, PROP_AVATAR_TOKEN @@ -84,6 +85,9 @@ tpl_entity_get_property (GObject *object, switch (param_id) { + case PROP_TYPE: + g_value_set_int (value, priv->type); + break; case PROP_IDENTIFIER: g_value_set_string (value, priv->identifier); break; @@ -106,17 +110,24 @@ tpl_entity_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - TplEntity *self = TPL_ENTITY (object); + TplEntityPriv *priv = TPL_ENTITY (object)->priv; - switch (param_id) { + switch (param_id) + { + case PROP_TYPE: + priv->type = g_value_get_int (value); + break; case PROP_IDENTIFIER: - _tpl_entity_set_identifier (self, g_value_get_string (value)); + g_assert (priv->identifier == NULL); + priv->identifier = g_value_dup_string (value); break; case PROP_ALIAS: - _tpl_entity_set_alias (self, g_value_get_string (value)); + g_assert (priv->alias == NULL); + priv->alias = g_value_dup_string (value); break; case PROP_AVATAR_TOKEN: - _tpl_entity_set_avatar_token (self, g_value_get_string (value)); + g_assert (priv->avatar_token == NULL); + priv->avatar_token = g_value_dup_string (value); break; default: @@ -137,6 +148,20 @@ static void tpl_entity_class_init (TplEntityClass *klass) object_class->set_property = tpl_entity_set_property; /** + * TplEntity:type: + * + * The entity's type (see #TplEntityType). + */ + param_spec = g_param_spec_int ("type", + "Type", + "The entity's type", + TPL_ENTITY_UNKNOWN, + TPL_ENTITY_SELF, + TPL_ENTITY_UNKNOWN, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_TYPE, param_spec); + + /** * TplEntity:identifier: * * The entity's identifier @@ -145,7 +170,7 @@ static void tpl_entity_class_init (TplEntityClass *klass) "Identifier", "The entity's identifier", NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_IDENTIFIER, param_spec); /** @@ -157,7 +182,7 @@ static void tpl_entity_class_init (TplEntityClass *klass) "Alias", "The entity's alias", NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_ALIAS, param_spec); /** @@ -169,8 +194,8 @@ static void tpl_entity_class_init (TplEntityClass *klass) "AvatarToken", "The entity's avatar's token", NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ALIAS, param_spec); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_AVATAR_TOKEN, param_spec); g_type_class_add_private (object_class, sizeof (TplEntityPriv)); } @@ -186,67 +211,56 @@ tpl_entity_init (TplEntity *self) } -TplEntity * -_tpl_entity_new (const gchar *identifier) -{ - g_return_val_if_fail (!TPL_STR_EMPTY (identifier), NULL); - - return g_object_new (TPL_TYPE_ENTITY, - "identifier", identifier, NULL); -} - - -/* _tpl_entity_from_room_id: - * @chatroom_id: the chatroom id which will be the identifier for the entity +/* _tpl_entity_new_from_room_id: + * @room_id: the room id which will be the identifier for the entity * * Return a TplEntity instance with identifier, alias copied from - * @chatroom_id. It also sets %TPL_ENTITY_ROOM as type for + * @room_id. It also sets %TPL_ENTITY_ROOM as type for * the #TplEntity returned. */ TplEntity * -_tpl_entity_from_room_id (const gchar *chatroom_id) +_tpl_entity_new_from_room_id (const gchar *room_id) { TplEntity *ret; - g_return_val_if_fail (chatroom_id != NULL, NULL); + g_return_val_if_fail (room_id != NULL, NULL); - ret = _tpl_entity_new (chatroom_id); - _tpl_entity_set_alias (ret, chatroom_id); - _tpl_entity_set_entity_type (ret, TPL_ENTITY_ROOM); + ret = g_object_new (TPL_TYPE_ENTITY, + "type", TPL_ENTITY_ROOM, + "identifier", room_id, + "alias", room_id, + NULL); - DEBUG ("Chatroom id: %s", chatroom_id); + DEBUG ("Chatroom id: %s", room_id); return ret; } -/* _tpl_entity_from_tp_contact: +/* _tpl_entity_new_from_tp_contact: * @contact: the TpContact instance to create the TplEntity from + * @type: the #TplEntity type * * Return a TplEntity instance with identifier, alias and - * avatar's token copied. It also sets %TPL_ENTITY_CONTACT as contact type for - * the #TplEntity returned. The client needs to set it to %TPL_ENTITY_SELF - * in case the contact is the account's onwer. - * - * @see #tpl_entity_set_contact_type() and %TPL_ENTITY_SELF description. + * avatar's token copied. Type parameter is useful to differentiate between + * normal contact and self contact, thus only %TPL_ENTITY_CONTACT and + * %TPL_ENTITY_SELF are accepted. */ TplEntity * -_tpl_entity_from_tp_contact (TpContact *contact) +_tpl_entity_new_from_tp_contact (TpContact *contact, + TplEntityType type) { TplEntity *ret; g_return_val_if_fail (TP_IS_CONTACT (contact), NULL); + g_return_val_if_fail (type == TPL_ENTITY_CONTACT || type == TPL_ENTITY_SELF, + NULL); - ret = _tpl_entity_new (tp_contact_get_identifier (contact)); - - if (tp_contact_get_alias (contact) != NULL) - _tpl_entity_set_alias (ret, tp_contact_get_alias (contact)); - if (tp_contact_get_avatar_token (contact) != NULL) - _tpl_entity_set_avatar_token (ret, tp_contact_get_avatar_token (contact)); - - /* set contact type to TPL_ENTITY_CONTACT by default, the client need to set - * it to TPL_ENTITY_SELF in case the contact is actually the account's - * owner */ - _tpl_entity_set_entity_type (ret, TPL_ENTITY_CONTACT); + ret = g_object_new (TPL_TYPE_ENTITY, + "type", type, + "identifier", tp_contact_get_identifier (contact), + "alias", tp_contact_get_alias (contact), + "avatar-token", tp_contact_get_avatar_token (contact), + NULL); DEBUG ("ID: %s, TOK: %s", tpl_entity_get_identifier (ret), tpl_entity_get_avatar_token (ret)); @@ -312,62 +326,3 @@ tpl_entity_get_avatar_token (TplEntity *self) return self->priv->avatar_token; } - - -void -_tpl_entity_set_alias (TplEntity *self, - const gchar *data) -{ - g_return_if_fail (TPL_IS_ENTITY (self)); - g_return_if_fail (!TPL_STR_EMPTY (data)); - g_return_if_fail (self->priv->alias == NULL); - - self->priv->alias = g_strdup (data); -} - - -void -_tpl_entity_set_identifier (TplEntity *self, - const gchar *data) -{ - g_return_if_fail (TPL_IS_ENTITY (self)); - g_return_if_fail (!TPL_STR_EMPTY (data)); - g_return_if_fail (self->priv->identifier == NULL); - - self->priv->identifier = g_strdup (data); -} - - -/* _tpl_entity_set_entity_type: - * @self: a TplEntity instance - * @data: the contact type for @self - * - * Set a entity type for @self. - * - * Note: %TPL_ENTITY_CONTACT and %TPL_ENTITY_ROOM are automatically set after - * _tpl_entity_from_tp_contact() and #tpl_entity_from_chatroom_id(), - * respectively. Though, the client will need to set %TPL_ENTITY_SELF after - * those function calls when @self represents the owner of the account. - * - * @see #TplEntityType - */ -void -_tpl_entity_set_entity_type (TplEntity *self, - TplEntityType data) -{ - g_return_if_fail (TPL_IS_ENTITY (self)); - - self->priv->type = data; -} - - -void -_tpl_entity_set_avatar_token (TplEntity *self, - const gchar *data) -{ - g_return_if_fail (TPL_IS_ENTITY (self)); - g_return_if_fail (self->priv->avatar_token == NULL); - /* data can be NULL, if no avatar_token is set */ - - self->priv->avatar_token = g_strdup (data); -} diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c index f5a254b8f..0950de836 100644 --- a/telepathy-logger/log-store-sqlite.c +++ b/telepathy-logger/log-store-sqlite.c @@ -1167,10 +1167,11 @@ tpl_log_store_sqlite_get_entities (TplLogStore *self, DEBUG ("identifier = %s, chatroom = %i", identifier, chatroom); - entity = _tpl_entity_new (identifier); - _tpl_entity_set_entity_type (entity, type); - /* FIXME Faking alias with identifier */ - _tpl_entity_set_alias (entity, identifier); + entity = g_object_new (TPL_TYPE_ENTITY, + "identifier", identifier, + "type", type, + "alias", identifier, /* FIXME Faking alias with identifier */ + NULL); list = g_list_prepend (list, entity); } diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c index ca5259df8..4b818a004 100644 --- a/telepathy-logger/log-store-xml.c +++ b/telepathy-logger/log-store-xml.c @@ -862,9 +862,12 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, t = _tpl_time_parse (time_); - sender = _tpl_entity_new (sender_id); - _tpl_entity_set_alias (sender, sender_name); - _tpl_entity_set_avatar_token (sender, sender_avatar_token); + sender = g_object_new (TPL_TYPE_ENTITY, + "identifier", sender_id, + "type", is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT, + "alias", sender_name, + "avatar-token", sender_avatar_token, + NULL); if (self->priv->empathy_legacy) { @@ -1111,13 +1114,13 @@ log_store_xml_get_entities_for_dir (TplLogStoreXml *self, } if (is_chatroom) - entity = _tpl_entity_from_room_id (name); - else { - entity = _tpl_entity_new (name); - _tpl_entity_set_entity_type (entity, TPL_ENTITY_CONTACT); - /* FIXME Faking alias with identifier */ - _tpl_entity_set_alias (entity, name); - } + entity = _tpl_entity_new_from_room_id (name); + else + entity = g_object_new (TPL_TYPE_ENTITY, + "identifier", name, + "type", TPL_ENTITY_CONTACT, + "alias", name, /* FIXME Faking alias with identifier */ + NULL); entities = g_list_prepend (entities, entity); } diff --git a/tests/Makefile.am b/tests/Makefile.am index fc82f0165..6db1d887a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,6 +9,7 @@ LDADD = \ $(TPL_LIBS) noinst_PROGRAMS = \ + test-entity \ test-tpl-channel \ test-tpl-conf \ test-tpl-log-store-sqlite \ @@ -60,6 +61,7 @@ check-valgrind: $(TESTS) check_c_sources = \ $(dbus_test_sources) \ tpl-channel-test.c \ + test-entity.c \ test-tpl-channel.c \ test-tpl-conf.c \ test-tpl-observer.c \ diff --git a/tests/suppressions/tpl.supp b/tests/suppressions/tpl.supp index f72eae31e..c92f72ab3 100644 --- a/tests/suppressions/tpl.supp +++ b/tests/suppressions/tpl.supp @@ -146,6 +146,13 @@ fun:g_type_register_static } +{ + g_type_create_instance + Memcheck:Leak + ... + fun:g_type_create_instance +} + # ============================= dbus-glib ============================= { @@ -238,19 +245,6 @@ # ============================= unclassified ========================== { - creating param specs in tp_proxy_class_intern_init - Memcheck:Leak - fun:memalign - fun:posix_memalign - fun:slab_allocator_alloc_chunk - fun:g_slice_alloc - fun:g_slice_alloc0 - fun:g_type_create_instance - fun:g_param_spec_internal - fun:g_param_spec_string -} - -{ ld.so initialization on glibc 2.9 Memcheck:Cond fun:_dl_relocate_object diff --git a/tests/test-entity.c b/tests/test-entity.c new file mode 100644 index 000000000..93cb5c893 --- /dev/null +++ b/tests/test-entity.c @@ -0,0 +1,66 @@ +#include <glib.h> +#include <glib/gprintf.h> +#include <telepathy-logger/entity.h> +#include <telepathy-logger/entity-internal.h> + +static void +test_entity_instantiation (void) +{ + TplEntity *entity; + + entity = g_object_new (TPL_TYPE_ENTITY, + "identifier", "my-identifier", + "type", TPL_ENTITY_CONTACT, + "alias", "my-alias", + "avatar-token", "my-token", + NULL); + + g_assert_cmpstr (tpl_entity_get_identifier (entity), ==, "my-identifier"); + g_assert (tpl_entity_get_entity_type (entity) == TPL_ENTITY_CONTACT); + g_assert_cmpstr (tpl_entity_get_alias (entity), ==, "my-alias"); + g_assert_cmpstr (tpl_entity_get_avatar_token (entity), ==, "my-token"); + + g_object_unref (entity); +} + +static void +test_entity_instantiation_from_room_id (void) +{ + TplEntity *entity; + + entity = _tpl_entity_new_from_room_id ("my-room-id"); + + g_assert_cmpstr (tpl_entity_get_identifier (entity), ==, "my-room-id"); + g_assert (tpl_entity_get_entity_type (entity) == TPL_ENTITY_ROOM); + g_assert_cmpstr (tpl_entity_get_alias (entity), ==, "my-room-id"); + g_assert (tpl_entity_get_avatar_token (entity) == NULL); + + g_object_unref (entity); +} + +static void +test_entity_instantiation_from_tp_contact (void) +{ + /* TODO figure-out how to obtain a TpContact to test + * _tpl_entity_new_from_tp_contact() */ + g_printf ("- TODO - "); +} + +int main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_type_init (); + + g_test_add_func ("/entity/instantiation", + test_entity_instantiation); + + g_test_add_func ("/entity/instantiation-from-room-id", + test_entity_instantiation_from_room_id); + + g_test_add_func ("/entity/instantiation-from-tp-contact", + test_entity_instantiation_from_tp_contact); + + return g_test_run (); +} |