[network-manager-openvpn] shared: update shared files
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn] shared: update shared files
- Date: Mon, 15 Feb 2016 23:00:23 +0000 (UTC)
commit 21bf3ff0d8cb371ec0ef8e3d31935a6fc97989f9
Author: Thomas Haller <thaller redhat com>
Date: Mon Feb 15 23:44:03 2016 +0100
shared: update shared files
shared/nm-default.h | 1 +
shared/nm-glib.h | 14 ++++
shared/nm-macros-internal.h | 153 +++++++++++++++++++++++++++++++------------
shared/nm-test-utils.h | 148 ++++++++++++++++++++++++++++-------------
4 files changed, 226 insertions(+), 90 deletions(-)
---
diff --git a/shared/nm-default.h b/shared/nm-default.h
index e2677de..0567727 100644
--- a/shared/nm-default.h
+++ b/shared/nm-default.h
@@ -41,6 +41,7 @@
#include "nm-glib.h"
#include "nm-version.h"
#include "gsystem-local-alloc.h"
+#include "nm-macros-internal.h"
/*****************************************************************************/
diff --git a/shared/nm-glib.h b/shared/nm-glib.h
index c75e91b..201b6d3 100644
--- a/shared/nm-glib.h
+++ b/shared/nm-glib.h
@@ -116,6 +116,20 @@ __g_type_ensure (GType type)
#define g_test_initialized() (g_test_config_vars->test_initialized)
#endif
+/* g_assert_cmpmem() is only available since glib 2.46. */
+#if !GLIB_CHECK_VERSION (2, 45, 7)
+#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
+ gconstpointer __m1 = m1, __m2 = m2; \
+ int __l1 = l1, __l2 = l2; \
+ if (__l1 != __l2) \
+ g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
+ #l1 " (len(" #m1 ")) == " #l2 "
(len(" #m2 "))", __l1, "==", __l2, 'i'); \
+ else if (memcmp (__m1, __m2, __l1) != 0) \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
+ "assertion failed (" #m1 " == " #m2
")"); \
+ } G_STMT_END
+#endif
+
/* Rumtime check for glib version. First do a compile time check which
* (if satisfied) shortcuts the runtime check. */
#define nm_glib_check_version(major, minor, micro) \
diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h
index c178758..63f5138 100644
--- a/shared/nm-macros-internal.h
+++ b/shared/nm-macros-internal.h
@@ -107,7 +107,7 @@
/********************************************************/
/* macro to return strlen() of a compile time string. */
-#define STRLEN(str) ( sizeof ("" str) - 1 )
+#define NM_STRLEN(str) ( sizeof ("" str) - 1 )
#define NM_SET_OUT(out_val, value) \
G_STMT_START { \
@@ -120,63 +120,130 @@
/********************************************************/
-#define _NM_IN_SET_EVAL_1(op, x, y1) \
- ({ \
- typeof(x) _x = (x); \
- ( (_x == (y1)) \
- ); \
+#define _NM_IN_SET_EVAL_1(op, _x, y1) \
+ (_x == (y1))
+
+#define _NM_IN_SET_EVAL_2(op, _x, y1, y2) \
+ ( (_x == (y1)) \
+ op (_x == (y2)) \
+ )
+
+#define _NM_IN_SET_EVAL_3(op, _x, y1, y2, y3) \
+ ( (_x == (y1)) \
+ op (_x == (y2)) \
+ op (_x == (y3)) \
+ )
+
+#define _NM_IN_SET_EVAL_4(op, _x, y1, y2, y3, y4) \
+ ( (_x == (y1)) \
+ op (_x == (y2)) \
+ op (_x == (y3)) \
+ op (_x == (y4)) \
+ )
+
+#define _NM_IN_SET_EVAL_5(op, _x, y1, y2, y3, y4, y5) \
+ ( (_x == (y1)) \
+ op (_x == (y2)) \
+ op (_x == (y3)) \
+ op (_x == (y4)) \
+ op (_x == (y5)) \
+ )
+
+#define _NM_IN_SET_EVAL_6(op, _x, y1, y2, y3, y4, y5, y6) \
+ ( (_x == (y1)) \
+ op (_x == (y2)) \
+ op (_x == (y3)) \
+ op (_x == (y4)) \
+ op (_x == (y5)) \
+ op (_x == (y6)) \
+ )
+
+#define _NM_IN_SET_EVAL_N2(op, _x, n, ...) _NM_IN_SET_EVAL_##n(op, _x, __VA_ARGS__)
+#define _NM_IN_SET_EVAL_N(op, x, n, ...) \
+ ({ \
+ typeof(x) _x = (x); \
+ !!_NM_IN_SET_EVAL_N2(op, _x, n, __VA_ARGS__); \
})
-#define _NM_IN_SET_EVAL_2(op, x, y1, y2) \
- ({ \
- typeof(x) _x = (x); \
- ( (_x == (y1)) \
- op (_x == (y2)) \
- ); \
- })
+/* Beware that this does short-circuit evaluation (use "||" instead of "|")
+ * which has a possibly unexpected non-function-like behavior.
+ * Use NM_IN_SET_SE if you need all arguments to be evaluted. */
+#define NM_IN_SET(x, ...) _NM_IN_SET_EVAL_N(||, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
-#define _NM_IN_SET_EVAL_3(op, x, y1, y2, y3) \
- ({ \
- typeof(x) _x = (x); \
- ( (_x == (y1)) \
- op (_x == (y2)) \
- op (_x == (y3)) \
- ); \
- })
+/* "SE" stands for "side-effect". Contrary to NM_IN_SET(), this does not do
+ * short-circuit evaluation, which can make a difference if the arguments have
+ * side-effects. */
+#define NM_IN_SET_SE(x, ...) _NM_IN_SET_EVAL_N(|, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
-#define _NM_IN_SET_EVAL_4(op, x, y1, y2, y3, y4) \
- ({ \
- typeof(x) _x = (x); \
- ( (_x == (y1)) \
- op (_x == (y2)) \
- op (_x == (y3)) \
- op (_x == (y4)) \
- ); \
- })
+/********************************************************/
-#define _NM_IN_SET_EVAL_5(op, x, y1, y2, y3, y4, y5) \
+static inline gboolean
+_NM_IN_STRSET_streq (const char *x, const char *s)
+{
+ return s && strcmp (x, s) == 0;
+}
+
+#define _NM_IN_STRSET_EVAL_1(op, _x, y1) \
+ _NM_IN_STRSET_streq (_x, y1)
+
+#define _NM_IN_STRSET_EVAL_2(op, _x, y1, y2) \
+ ( _NM_IN_STRSET_streq (_x, y1) \
+ op _NM_IN_STRSET_streq (_x, y2) \
+ )
+
+#define _NM_IN_STRSET_EVAL_3(op, _x, y1, y2, y3) \
+ ( _NM_IN_STRSET_streq (_x, y1) \
+ op _NM_IN_STRSET_streq (_x, y2) \
+ op _NM_IN_STRSET_streq (_x, y3) \
+ )
+
+#define _NM_IN_STRSET_EVAL_4(op, _x, y1, y2, y3, y4) \
+ ( _NM_IN_STRSET_streq (_x, y1) \
+ op _NM_IN_STRSET_streq (_x, y2) \
+ op _NM_IN_STRSET_streq (_x, y3) \
+ op _NM_IN_STRSET_streq (_x, y4) \
+ )
+
+#define _NM_IN_STRSET_EVAL_5(op, _x, y1, y2, y3, y4, y5) \
+ ( _NM_IN_STRSET_streq (_x, y1) \
+ op _NM_IN_STRSET_streq (_x, y2) \
+ op _NM_IN_STRSET_streq (_x, y3) \
+ op _NM_IN_STRSET_streq (_x, y4) \
+ op _NM_IN_STRSET_streq (_x, y5) \
+ )
+
+#define _NM_IN_STRSET_EVAL_6(op, _x, y1, y2, y3, y4, y5, y6) \
+ ( _NM_IN_STRSET_streq (_x, y1) \
+ op _NM_IN_STRSET_streq (_x, y2) \
+ op _NM_IN_STRSET_streq (_x, y3) \
+ op _NM_IN_STRSET_streq (_x, y4) \
+ op _NM_IN_STRSET_streq (_x, y5) \
+ op _NM_IN_STRSET_streq (_x, y6) \
+ )
+
+#define _NM_IN_STRSET_EVAL_N2(op, _x, n, ...) _NM_IN_STRSET_EVAL_##n(op, _x, __VA_ARGS__)
+#define _NM_IN_STRSET_EVAL_N(op, x, n, ...) \
({ \
- typeof(x) _x = (x); \
- ( (_x == (y1)) \
- op (_x == (y2)) \
- op (_x == (y3)) \
- op (_x == (y4)) \
- op (_x == (y5)) \
- ); \
+ const char *_x = (x); \
+ ( ((_x == NULL) && _NM_IN_SET_EVAL_N2 (op, (const char *) NULL, n, __VA_ARGS__)) \
+ || ((_x != NULL) && _NM_IN_STRSET_EVAL_N2 (op, _x, n, __VA_ARGS__)) \
+ ); \
})
-#define _NM_IN_SET_EVAL_N2(op, x, n, ...) _NM_IN_SET_EVAL_##n(op, x, __VA_ARGS__)
-#define _NM_IN_SET_EVAL_N(op, x, n, ...) _NM_IN_SET_EVAL_N2(op, x, n, __VA_ARGS__)
-
/* Beware that this does short-circuit evaluation (use "||" instead of "|")
* which has a possibly unexpected non-function-like behavior.
- * Use NM_IN_SET_SE if you need all arguments to be evaluted. */
-#define NM_IN_SET(x, ...) _NM_IN_SET_EVAL_N(||, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
+ * Use NM_IN_STRSET_SE if you need all arguments to be evaluted. */
+#define NM_IN_STRSET(x, ...) _NM_IN_STRSET_EVAL_N(||, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
-/* "SE" stands for "side-effect". Contrary to NM_IN_SET(), this does not do
+/* "SE" stands for "side-effect". Contrary to NM_IN_STRSET(), this does not do
* short-circuit evaluation, which can make a difference if the arguments have
* side-effects. */
-#define NM_IN_SET_SE(x, ...) _NM_IN_SET_EVAL_N(|, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
+#define NM_IN_STRSET_SE(x, ...) _NM_IN_STRSET_EVAL_N(|, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
+
+/*****************************************************************************/
+
+#define nm_streq(s1, s2) (strcmp (s1, s2) == 0)
+#define nm_streq0(s1, s2) (g_strcmp0 (s1, s2) == 0)
/*****************************************************************************/
diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h
index b6bc332..85a2e2a 100644
--- a/shared/nm-test-utils.h
+++ b/shared/nm-test-utils.h
@@ -88,6 +88,8 @@
*
*******************************************************************************/
+#include "nm-default.h"
+
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
@@ -95,9 +97,7 @@
#include <string.h>
#include <errno.h>
-#include "nm-default.h"
#include "nm-utils.h"
-#include "nm-macros-internal.h"
#ifdef __NETWORKMANAGER_LOGGING_H__
/* We are running tests under src/. Let's include some files by default.
@@ -158,6 +158,12 @@ _nmtst_assert_success (gboolean success, GError *error, const char *file, int li
}
#define nmtst_assert_success(success, error) _nmtst_assert_success ((success), (error), __FILE__, __LINE__)
+#define nmtst_assert_no_success(success, error) \
+ G_STMT_START { \
+ g_assert (error); \
+ g_assert (!(success)); \
+ } G_STMT_END
+
/*******************************************************************************/
struct __nmtst_internal
@@ -1038,20 +1044,6 @@ _nmtst_assert_ip6_address (const char *file, int line, const struct in6_addr *ad
}
#define nmtst_assert_ip6_address(addr, str_expected) _nmtst_assert_ip6_address (__FILE__, __LINE__, addr,
str_expected)
-/* Deprecated: don't use this overly verbose macro. */
-#define FAIL(test_name, fmt, ...) \
- G_STMT_START { \
- g_error ("%s:%d: FAIL[%s]: " fmt, __FILE__, __LINE__, test_name, ## __VA_ARGS__); \
- } G_STMT_END
-
-/* Deprecated: don't use this overly verbose macro. */
-#define ASSERT(x, test_name, fmt, ...) \
- G_STMT_START { \
- if (!(x)) { \
- FAIL (test_name, fmt, ## __VA_ARGS__); \
- } \
- } G_STMT_END
-
#define nmtst_spawn_sync(working_directory, standard_out, standard_err, assert_exit_status, ...) \
__nmtst_spawn_sync (working_directory, standard_out, standard_err, assert_exit_status, ##__VA_ARGS__,
NULL)
inline static gint
@@ -1331,9 +1323,71 @@ nmtst_ip6_config_clone (NMIP6Config *config)
#endif
+#ifdef NM_SETTING_IP_CONFIG_H
+inline static void
+nmtst_setting_ip_config_add_address (NMSettingIPConfig *s_ip,
+ const char *address,
+ guint prefix)
+{
+ NMIPAddress *addr;
+ int family;
+
+ g_assert (s_ip);
+
+ if (nm_utils_ipaddr_valid (AF_INET, address))
+ family = AF_INET;
+ else if (nm_utils_ipaddr_valid (AF_INET6, address))
+ family = AF_INET6;
+ else
+ g_assert_not_reached ();
+
+ addr = nm_ip_address_new (family, address, prefix, NULL);
+ g_assert (addr);
+ g_assert (nm_setting_ip_config_add_address (s_ip, addr));
+ nm_ip_address_unref (addr);
+}
+
+inline static void
+nmtst_setting_ip_config_add_route (NMSettingIPConfig *s_ip,
+ const char *dest,
+ guint prefix,
+ const char *next_hop,
+ gint64 metric)
+{
+ NMIPRoute *route;
+ int family;
+
+ g_assert (s_ip);
+
+ if (nm_utils_ipaddr_valid (AF_INET, dest))
+ family = AF_INET;
+ else if (nm_utils_ipaddr_valid (AF_INET6, dest))
+ family = AF_INET6;
+ else
+ g_assert_not_reached ();
+
+ route = nm_ip_route_new (family, dest, prefix, next_hop, metric, NULL);
+ g_assert (route);
+ g_assert (nm_setting_ip_config_add_route (s_ip, route));
+ nm_ip_route_unref (route);
+}
+#endif /* NM_SETTING_IP_CONFIG_H */
+
#if (defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__)) ||
(defined(NM_CONNECTION_H))
inline static NMConnection *
+nmtst_clone_connection (NMConnection *connection)
+{
+ g_assert (NM_IS_CONNECTION (connection));
+
+#if defined(__NM_SIMPLE_CONNECTION_H__)
+ return nm_simple_connection_new_clone (connection);
+#else
+ return nm_connection_duplicate (connection);
+#endif
+}
+
+inline static NMConnection *
nmtst_create_minimal_connection (const char *id, const char *uuid, const char *type, NMSettingConnection
**out_s_con)
{
NMConnection *con;
@@ -1437,13 +1491,7 @@ _nmtst_connection_duplicate_and_normalize (NMConnection *connection, ...)
gboolean was_modified;
va_list args;
- g_assert (NM_IS_CONNECTION (connection));
-
-#if defined(__NM_SIMPLE_CONNECTION_H__)
- connection = nm_simple_connection_new_clone (connection);
-#else
- connection = nm_connection_duplicate (connection);
-#endif
+ connection = nmtst_clone_connection (connection);
va_start (args, connection);
was_modified = _nmtst_connection_normalize_v (connection, args);
@@ -1514,28 +1562,33 @@ nmtst_assert_connection_equals (NMConnection *a, gboolean normalize_a, NMConnect
}
inline static void
-nmtst_assert_connection_verifies_without_normalization (NMConnection *con)
+nmtst_assert_connection_verifies (NMConnection *con)
{
- /* assert that the connection verifies and does not need any normalization */
-
+ /* assert that the connection does verify, it might be normaliziable or not */
GError *error = NULL;
gboolean success;
- gboolean was_modified = FALSE;
- gs_unref_object NMConnection *clone = NULL;
g_assert (NM_IS_CONNECTION (con));
-#if defined(__NM_SIMPLE_CONNECTION_H__)
- clone = nm_simple_connection_new_clone (con);
-#else
- clone = nm_connection_duplicate (con);
-#endif
-
success = nm_connection_verify (con, &error);
g_assert_no_error (error);
g_assert (success);
+}
- success = nm_connection_normalize (con, NULL, &was_modified, &error);
+inline static void
+nmtst_assert_connection_verifies_without_normalization (NMConnection *con)
+{
+ /* assert that the connection verifies and does not need any normalization */
+ GError *error = NULL;
+ gboolean success;
+ gboolean was_modified = FALSE;
+ gs_unref_object NMConnection *clone = NULL;
+
+ clone = nmtst_clone_connection (con);
+
+ nmtst_assert_connection_verifies (con);
+
+ success = nm_connection_normalize (clone, NULL, &was_modified, &error);
g_assert_no_error (error);
g_assert (success);
nmtst_assert_connection_equals (con, FALSE, clone, FALSE);
@@ -1549,21 +1602,19 @@ nmtst_assert_connection_verifies_and_normalizable (NMConnection *con)
GError *error = NULL;
gboolean success;
gboolean was_modified = FALSE;
+ gs_unref_object NMConnection *clone = NULL;
- g_assert (NM_IS_CONNECTION (con));
+ clone = nmtst_clone_connection (con);
- success = nm_connection_verify (con, &error);
- g_assert_no_error (error);
- g_assert (success);
- g_clear_error (&error);
+ nmtst_assert_connection_verifies (con);
- success = nm_connection_normalize (con, NULL, &was_modified, &error);
+ success = nm_connection_normalize (clone, NULL, &was_modified, &error);
g_assert_no_error (error);
g_assert (success);
g_assert (was_modified);
/* again! */
- nmtst_assert_connection_verifies_without_normalization (con);
+ nmtst_assert_connection_verifies_without_normalization (clone);
}
inline static void
@@ -1575,21 +1626,22 @@ nmtst_assert_connection_verifies_after_normalization (NMConnection *con,
GError *error = NULL;
gboolean success;
gboolean was_modified = FALSE;
+ gs_unref_object NMConnection *clone = NULL;
- g_assert (NM_IS_CONNECTION (con));
+ clone = nmtst_clone_connection (con);
success = nm_connection_verify (con, &error);
nmtst_assert_error (error, expect_error_domain, expect_error_code, NULL);
g_assert (!success);
g_clear_error (&error);
- success = nm_connection_normalize (con, NULL, &was_modified, &error);
+ success = nm_connection_normalize (clone, NULL, &was_modified, &error);
g_assert_no_error (error);
g_assert (success);
g_assert (was_modified);
/* again! */
- nmtst_assert_connection_verifies_without_normalization (con);
+ nmtst_assert_connection_verifies_without_normalization (clone);
}
inline static void
@@ -1602,18 +1654,20 @@ nmtst_assert_connection_unnormalizable (NMConnection *con,
GError *error = NULL;
gboolean success;
gboolean was_modified = FALSE;
+ gs_unref_object NMConnection *clone = NULL;
- g_assert (NM_IS_CONNECTION (con));
+ clone = nmtst_clone_connection (con);
success = nm_connection_verify (con, &error);
nmtst_assert_error (error, expect_error_domain, expect_error_code, NULL);
g_assert (!success);
g_clear_error (&error);
- success = nm_connection_normalize (con, NULL, &was_modified, &error);
+ success = nm_connection_normalize (clone, NULL, &was_modified, &error);
nmtst_assert_error (error, expect_error_domain, expect_error_code, NULL);
g_assert (!success);
g_assert (!was_modified);
+ nmtst_assert_connection_equals (con, FALSE, clone, FALSE);
g_clear_error (&error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]