summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-07-18 23:35:22 +0200
committerThomas Haller <thaller@redhat.com>2014-08-22 15:24:30 +0200
commit043ab29ca949bfaf9fcaa034f86bb67ead1a666c (patch)
treef07b821eb26cd56d0aa4b2a34e20b3cc16489c2a
parent80e1b05c316ffbde059d9478237f8683405e63a8 (diff)
downloadNetworkManager-043ab29ca949bfaf9fcaa034f86bb67ead1a666c.tar.gz
nmtst: add assertion functions for verify() connection
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--include/nm-test-utils.h132
1 files changed, 131 insertions, 1 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h
index aeba15269e..9c8009355d 100644
--- a/include/nm-test-utils.h
+++ b/include/nm-test-utils.h
@@ -36,6 +36,30 @@
#include "gsystem-local-alloc.h"
+/*******************************************************************************/
+
+/* 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);
+ }
+}
+
+/*******************************************************************************/
+
struct __nmtst_internal
{
GRand *rand0;
@@ -777,7 +801,7 @@ _nmtst_connection_duplicate_and_normalize (NMConnection *connection, ...)
g_assert (NM_IS_CONNECTION (connection));
- connection = nm_connection_duplicate (connection);
+ connection = nm_simple_connection_new_clone (connection);
va_start (args, connection);
was_modified = _nmtst_connection_normalize_v (connection, args);
@@ -826,6 +850,112 @@ nmtst_assert_connection_equals (NMConnection *a, gboolean normalize_a, NMConnect
g_assert (compare);
}
+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;
+
+ g_assert (NM_IS_CONNECTION (con));
+
+ clone = nm_simple_connection_new_clone (con);
+
+ success = nm_connection_verify (con, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ success = nm_connection_normalize (con, NULL, &was_modified, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert (!was_modified);
+
+ nmtst_assert_connection_equals (con, FALSE, clone, FALSE);
+}
+
+inline static void
+nmtst_assert_connection_verifies_and_normalizable (NMConnection *con)
+{
+ /* assert that the connection does verify, but normalization still modifies it */
+ GError *error = NULL;
+ gboolean success;
+ gboolean was_modified = FALSE;
+
+ g_assert (NM_IS_CONNECTION (con));
+
+ success = nm_connection_verify (con, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_clear_error (&error);
+
+ success = nm_connection_normalize (con, NULL, &was_modified, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert (was_modified);
+
+ /* again! */
+ nmtst_assert_connection_verifies_without_normalization (con);
+}
+
+inline static void
+nmtst_assert_connection_verifies_after_normalization (NMConnection *con,
+ GQuark expect_error_domain,
+ gint expect_error_code)
+{
+ /* assert that the connection does not verify, but normalization does fix it */
+ GError *error = NULL;
+ gboolean success;
+ gboolean was_modified = FALSE;
+
+ g_assert (NM_IS_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);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert (was_modified);
+
+ /* again! */
+ nmtst_assert_connection_verifies_without_normalization (con);
+}
+
+inline static void
+nmtst_assert_connection_unnormalizable (NMConnection *con,
+ GQuark expect_error_domain,
+ gint expect_error_code)
+{
+ /* assert that the connection does not verify, and it cannot be fixed by normalization */
+
+ GError *error = NULL;
+ gboolean success;
+ gboolean was_modified = FALSE;
+ gs_unref_object NMConnection *clone = NULL;
+
+ g_assert (NM_IS_CONNECTION (con));
+
+ clone = nm_simple_connection_new_clone (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);
+ nmtst_assert_error (error, expect_error_domain, expect_error_code, NULL);
+ g_assert (!success);
+ g_assert (!was_modified);
+ g_clear_error (&error);
+
+ nmtst_assert_connection_equals (con, FALSE, clone, FALSE);
+}
+
#endif