Test notification referencing

This commit is contained in:
Benedikt Heine 2018-10-06 08:36:05 +02:00
parent fe7d82380e
commit 52c47524f2
3 changed files with 31 additions and 0 deletions

View File

@ -215,6 +215,13 @@ static void notification_private_free(NotificationPrivate *p)
g_free(p); g_free(p);
} }
/* see notification.h */
gint notification_refcount_get(struct notification *n)
{
assert(n->priv->refcount > 0);
return g_atomic_int_get(&n->priv->refcount);
}
/* see notification.h */ /* see notification.h */
void notification_ref(struct notification *n) void notification_ref(struct notification *n)
{ {

View File

@ -101,6 +101,11 @@ struct notification {
*/ */
struct notification *notification_create(void); struct notification *notification_create(void);
/**
* Retrieve the current reference count of the notification
*/
gint notification_refcount_get(struct notification *n);
/** /**
* Increase the reference counter of the notification. * Increase the reference counter of the notification.
*/ */

View File

@ -98,6 +98,24 @@ TEST test_notification_replace_single_field(void)
PASS(); PASS();
} }
TEST test_notification_referencing(void)
{
struct notification *n = notification_create();
ASSERT(notification_refcount_get(n) == 1);
notification_ref(n);
ASSERT(notification_refcount_get(n) == 2);
notification_unref(n);
ASSERT(notification_refcount_get(n) == 1);
// Now we have to rely on valgrind to test, that
// it gets actually freed
notification_unref(n);
PASS();
}
SUITE(suite_notification) SUITE(suite_notification)
{ {
cmdline_load(0, NULL); cmdline_load(0, NULL);
@ -125,6 +143,7 @@ SUITE(suite_notification)
notification_unref(b); notification_unref(b);
RUN_TEST(test_notification_replace_single_field); RUN_TEST(test_notification_replace_single_field);
RUN_TEST(test_notification_referencing);
g_clear_pointer(&settings.icon_path, g_free); g_clear_pointer(&settings.icon_path, g_free);
} }