diff options
author | Thomas Haller <thaller@redhat.com> | 2016-03-13 10:16:11 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-03-13 12:32:36 +0100 |
commit | 32ae9418a747663d02f01838b64fb4990d2b7385 (patch) | |
tree | e203a64ad28ea235ec8393e8b52e54e09177d169 | |
parent | 25b5f766ed8d1213ad10238a2e8e9fed1a5cd10f (diff) | |
download | network-manager-applet-32ae9418a747663d02f01838b64fb4990d2b7385.tar.gz |
shared: update shared files from NetworkManager
To get nm_g_object_unref().
-rw-r--r-- | shared/nm-glib.h | 7 | ||||
-rw-r--r-- | shared/nm-macros-internal.h | 44 | ||||
-rw-r--r-- | shared/nm-test-utils.h | 81 |
3 files changed, 111 insertions, 21 deletions
diff --git a/shared/nm-glib.h b/shared/nm-glib.h index 201b6d33..c92d6f0f 100644 --- a/shared/nm-glib.h +++ b/shared/nm-glib.h @@ -367,4 +367,11 @@ _nm_g_hash_table_get_keys_as_array (GHashTable *hash_table, }) #endif +#ifndef g_info +/* g_info was only added with 2.39.2 */ +#define g_info(...) g_log (G_LOG_DOMAIN, \ + G_LOG_LEVEL_INFO, \ + __VA_ARGS__) +#endif + #endif /* __NM_GLIB_H__ */ diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h index 9971f15c..1f638bab 100644 --- a/shared/nm-macros-internal.h +++ b/shared/nm-macros-internal.h @@ -24,12 +24,14 @@ /********************************************************/ +#define nm_auto(fcn) __attribute ((cleanup(fcn))) + /** * nm_auto_free: * * Call free() on a variable location when it goes out of scope. */ -#define nm_auto_free __attribute__ ((cleanup(_nm_auto_free_impl))) +#define nm_auto_free nm_auto(_nm_auto_free_impl) GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free) /********************************************************/ @@ -114,6 +116,26 @@ GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free) /********************************************************/ +/** + * NM_G_ERROR_MSG: + * @error: (allow none): the #GError instance + * + * All functions must follow the convention that when they + * return a failure, they must also set the GError to a valid + * message. For external API however, we want to be extra + * careful before accessing the error instance. Use NM_G_ERROR_MSG() + * which is safe to use on NULL. + * + * Returns: the error message. + **/ +static inline const char * +NM_G_ERROR_MSG (GError *error) +{ + return error ? (error->message ? : "(null)") : "(no-error)"; \ +} + +/********************************************************/ + /* macro to return strlen() of a compile time string. */ #define NM_STRLEN(str) ( sizeof ("" str) - 1 ) @@ -291,6 +313,26 @@ _notify (obj_type *obj, _PropertyEnums prop) \ /*****************************************************************************/ +static inline gpointer +nm_g_object_ref (gpointer obj) +{ + /* g_object_ref() doesn't accept NULL. */ + if (obj) + g_object_ref (obj); + return obj; +} + +static inline void +nm_g_object_unref (gpointer obj) +{ + /* g_object_unref() doesn't accept NULL. Usully, we workaround that + * by using g_clear_object(), but sometimes that is not convinient + * (for example as as destroy function for a hash table that can contain + * NULL values). */ + if (obj) + g_object_unref (obj); +} + static inline gboolean nm_clear_g_source (guint *id) { diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 85a2e2a3..6e705dce 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -110,23 +110,24 @@ /* general purpose functions that have no dependency on other nmtst functions */ -inline static void -nmtst_assert_error (GError *error, - GQuark expect_error_domain, - gint expect_error_code, - const char *expect_error_pattern) -{ - if (expect_error_domain) - g_assert_error (error, expect_error_domain, expect_error_code); - else - g_assert (error); - g_assert (error->message); - if ( expect_error_pattern - && !g_pattern_match_simple (expect_error_pattern, error->message)) { - g_error ("error message does not have expected pattern '%s'. Instead it is '%s' (%s, %d)", - expect_error_pattern, error->message, g_quark_to_string (error->domain), error->code); - } -} +#define nmtst_assert_error(error, expect_error_domain, expect_error_code, expect_error_pattern) \ + G_STMT_START { \ + GError *_error = (error); \ + GQuark _expect_error_domain = (expect_error_domain); \ + const char *_expect_error_pattern = (expect_error_pattern); \ + \ + if (_expect_error_domain) \ + g_assert_error (_error, _expect_error_domain, (expect_error_code)); \ + else \ + g_assert (_error); \ + g_assert (_error->message); \ + if ( _expect_error_pattern \ + && !g_pattern_match_simple (_expect_error_pattern, _error->message)) { \ + g_error ("%s:%d: error message does not have expected pattern '%s'. Instead it is '%s' (%s, %d)", \ + __FILE__, __LINE__, \ + _expect_error_pattern, _error->message, g_quark_to_string (_error->domain), _error->code); \ + } \ + } G_STMT_END #define NMTST_WAIT(max_wait_ms, wait) \ ({ \ @@ -154,7 +155,7 @@ inline static void _nmtst_assert_success (gboolean success, GError *error, const char *file, int line) { if (!success || error) - g_error ("(%s:%d) FAILURE success=%d, error=%s", file, line, success, error && error->message ? error->message : "(no error)"); + g_error ("(%s:%d) FAILURE success=%d, error=%s", file, line, success, error ? error->message : "(no error)"); } #define nmtst_assert_success(success, error) _nmtst_assert_success ((success), (error), __FILE__, __LINE__) @@ -852,6 +853,18 @@ nmtst_main_loop_run (GMainLoop *loop, int timeout_ms) return loopx != NULL; } +inline static void +_nmtst_main_loop_quit_on_notify (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + GMainLoop *loop = user_data; + + g_assert (G_IS_OBJECT (object)); + g_assert (loop); + + g_main_loop_quit (loop); +} +#define nmtst_main_loop_quit_on_notify ((GCallback) _nmtst_main_loop_quit_on_notify) + /*****************************************************************************/ inline static const char * @@ -1147,7 +1160,7 @@ nmtst_platform_ip6_address (const char *address, const char *peer_address, guint inline static NMPlatformIP6Address * nmtst_platform_ip6_address_full (const char *address, const char *peer_address, guint plen, int ifindex, NMIPConfigSource source, guint32 timestamp, - guint32 lifetime, guint32 preferred, guint flags) + guint32 lifetime, guint32 preferred, guint32 flags) { NMPlatformIP6Address *addr = nmtst_platform_ip6_address (address, peer_address, plen); @@ -1156,7 +1169,7 @@ nmtst_platform_ip6_address_full (const char *address, const char *peer_address, addr->timestamp = timestamp; addr->lifetime = lifetime; addr->preferred = preferred; - addr->flags = flags; + addr->n_ifa_flags = flags; return addr; } @@ -1773,6 +1786,34 @@ nmtst_create_connection_from_keyfile (const char *keyfile_str, const char *keyfi #ifdef __NM_CONNECTION_H__ +#define nmtst_assert_variant_is_of_type(variant, type) \ + G_STMT_START { \ + GVariant *_variantx = (variant); \ + \ + g_assert (_variantx); \ + g_assert (g_variant_is_of_type (_variantx, (type))); \ + } G_STMT_END + +#define nmtst_assert_variant_uint32(variant, val) \ + G_STMT_START { \ + GVariant *_variant = (variant); \ + \ + nmtst_assert_variant_is_of_type (_variant, G_VARIANT_TYPE_UINT32); \ + g_assert_cmpint (g_variant_get_uint32 (_variant), ==, (val)); \ + } G_STMT_END + +#define nmtst_assert_variant_string(variant, str) \ + G_STMT_START { \ + gsize _l; \ + GVariant *_variant = (variant); \ + const char *_str = (str); \ + \ + nmtst_assert_variant_is_of_type (_variant, G_VARIANT_TYPE_STRING); \ + g_assert (_str); \ + g_assert_cmpstr (g_variant_get_string (_variant, &_l), ==, _str); \ + g_assert_cmpint (_l, ==, strlen (_str)); \ + } G_STMT_END + typedef enum { NMTST_VARIANT_EDITOR_CONNECTION, NMTST_VARIANT_EDITOR_SETTING, |