Test notification referencing
This commit is contained in:
parent
fe7d82380e
commit
52c47524f2
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user