nmtst: add assertion functions for verify() connection

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-07-18 23:35:22 +02:00
parent 80e1b05c31
commit 043ab29ca9

View File

@@ -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