libnm/tests: add NMTSTC_SERVICE_INFO_SETUP() macro
authorThomas Haller <thaller@redhat.com>
Mon, 21 Dec 2015 09:55:38 +0000 (10:55 +0100)
committerThomas Haller <thaller@redhat.com>
Sat, 26 Dec 2015 15:43:49 +0000 (16:43 +0100)
shared/nm-test-libnm-utils.h

index 667ba90..290feea 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "nm-test-utils.h"
 
+/*****************************************************************************/
+
 typedef struct {
        GDBusConnection *bus;
        GDBusProxy *proxy;
@@ -32,6 +34,21 @@ typedef struct {
 NMTstcServiceInfo *nmtstc_service_init (void);
 void nmtstc_service_cleanup (NMTstcServiceInfo *info);
 
+static inline void _nmtstc_auto_service_cleanup (NMTstcServiceInfo **info)
+{
+       if (info && *info) {
+               nmtstc_service_cleanup (*info);
+               *info = NULL;
+       }
+}
+
+#define NMTSTC_SERVICE_INFO_SETUP(sinfo) \
+       NM_PRAGMA_WARNING_DISABLE ("-Wunused-variable") \
+       __attribute__ ((cleanup(_nmtstc_auto_service_cleanup))) NMTstcServiceInfo *sinfo = nmtstc_service_init (); \
+       NM_PRAGMA_WARNING_REENABLE
+
+/*****************************************************************************/
+
 #if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB)
 
 NMDevice *nmtstc_service_add_device (NMTstcServiceInfo *info,