diff options
Diffstat (limited to 'libnm-core/tests/test-setting.c')
-rw-r--r-- | libnm-core/tests/test-setting.c | 92 |
1 files changed, 75 insertions, 17 deletions
diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index 359c20c43c..1b53baeda3 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -8,6 +8,7 @@ #include <linux/pkt_sched.h> #include <net/if.h> +#include "nm-glib-aux/nm-json-aux.h" #include "nm-core-internal.h" #include "nm-utils.h" #include "nm-utils-private.h" @@ -32,15 +33,6 @@ /*****************************************************************************/ -/* assert that the define is just a plain integer (boolean). */ - -G_STATIC_ASSERT ( (WITH_JSON_VALIDATION) == 1 - || (WITH_JSON_VALIDATION) == 0); - -_nm_unused static const int _with_json_validation = WITH_JSON_VALIDATION; - -/*****************************************************************************/ - /* converts @dict to a connection. In this case, @dict must be good, without warnings, so that * NM_SETTING_PARSE_FLAGS_STRICT and NM_SETTING_PARSE_FLAGS_BEST_EFFORT yield the exact same results. */ static NMConnection * @@ -979,6 +971,24 @@ test_dcb_bandwidth_sums (void) /*****************************************************************************/ static void +test_nm_json (void) +{ + g_assert (NM_IN_SET (WITH_JANSSON, 0, 1)); + +#if WITH_JANSSON + g_assert (nm_json_vt ()); +#else + g_assert (!nm_json_vt ()); +#endif + +#if WITH_JANSSON != defined (JANSSON_SONAME) +#error "WITH_JANSON and JANSSON_SONAME are defined inconsistently." +#endif +} + +/*****************************************************************************/ + +static void _test_team_config_sync (const char *team_config, int notify_peer_count, int notify_peers_interval, @@ -1000,7 +1010,7 @@ _test_team_config_sync (const char *team_config, guint i, j; gboolean found; - if (!WITH_JSON_VALIDATION) { + if (!nm_json_vt ()) { g_test_skip ("team test requires JSON validation"); return; } @@ -1265,7 +1275,7 @@ _test_team_port_config_sync (const char *team_port_config, guint i, j; gboolean found; - if (!WITH_JSON_VALIDATION) { + if (!nm_json_vt ()) { g_test_skip ("team test requires JSON validation"); return; } @@ -1397,7 +1407,7 @@ _check_team_setting (NMSetting *setting) : nm_setting_team_get_config (NM_SETTING_TEAM (setting)), NULL); - if (WITH_JSON_VALIDATION) + if (nm_json_vt ()) nmtst_assert_setting_is_equal (setting, setting2, NM_SETTING_COMPARE_FLAG_EXACT); g_clear_object (&setting2); @@ -2389,7 +2399,7 @@ test_tc_config_action (void) } static void -test_tc_config_tfilter (void) +test_tc_config_tfilter_matchall_sdata (void) { NMTCAction *action1; NMTCTfilter *tfilter1, *tfilter2; @@ -2444,6 +2454,50 @@ test_tc_config_tfilter (void) } static void +test_tc_config_tfilter_matchall_mirred (void) +{ + NMTCAction *action; + NMTCTfilter *tfilter1; + GError *error = NULL; + gs_strfreev char **attr_names = NULL; + gs_free char *str; + GVariant *variant; + + tfilter1 = nm_utils_tc_tfilter_from_str ("parent ffff: matchall action mirred ingress mirror dev eth0", &error); + nmtst_assert_success (tfilter1, error); + g_assert_cmpint (nm_tc_tfilter_get_parent (tfilter1), ==, TC_H_MAKE (0xffff << 16, 0)); + g_assert_cmpstr (nm_tc_tfilter_get_kind (tfilter1), ==, "matchall"); + + action = nm_tc_tfilter_get_action (tfilter1); + nm_assert (action); + g_assert_cmpstr (nm_tc_action_get_kind (action), ==, "mirred"); + attr_names = nm_tc_action_get_attribute_names (action); + g_assert (attr_names); + g_assert_cmpint (g_strv_length (attr_names), ==, 3); + + variant = nm_tc_action_get_attribute (action, "ingress"); + g_assert (variant); + g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN)); + g_assert (g_variant_get_boolean (variant)); + + variant = nm_tc_action_get_attribute (action, "mirror"); + g_assert (variant); + g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN)); + g_assert (g_variant_get_boolean (variant)); + + variant = nm_tc_action_get_attribute (action, "dev"); + g_assert (variant); + g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING)); + g_assert_cmpstr (g_variant_get_string (variant, NULL), ==, "eth0"); + + str = nm_utils_tc_tfilter_to_str (tfilter1, &error); + nmtst_assert_success (str, error); + g_assert_cmpstr (str, ==, "parent ffff: matchall action mirred dev eth0 ingress mirror"); + + nm_tc_tfilter_unref (tfilter1); +} + +static void test_tc_config_setting_valid (void) { gs_unref_object NMSettingTCConfig *s_tc = NULL; @@ -3977,10 +4031,10 @@ test_setting_metadata (void) || (pt == &nm_sett_info_propert_type_plain_u && pt_2 == &nm_sett_info_propert_type_deprecated_ignore_u) || (pt_2 == &nm_sett_info_propert_type_plain_u && pt == &nm_sett_info_propert_type_deprecated_ignore_u)) { /* These are known to be duplicated. This is the case for - * "gsm.network-type" and plain properies like "802-11-wireless-security.fils" ("i" D-Bus type) - * "gsm.allowed-bands" and plain properies like "802-11-olpc-mesh.channel" ("u" D-Bus type) + * "gsm.network-type" and plain properties like "802-11-wireless-security.fils" ("i" D-Bus type) + * "gsm.allowed-bands" and plain properties like "802-11-olpc-mesh.channel" ("u" D-Bus type) * While the content/behaviour of the property types are identical, their purpose - * is different. So allowe them. + * is different. So allow them. */ continue; } @@ -4040,7 +4094,10 @@ main (int argc, char **argv) g_test_add_func ("/libnm/settings/tc_config/qdisc", test_tc_config_qdisc); g_test_add_func ("/libnm/settings/tc_config/action", test_tc_config_action); - g_test_add_func ("/libnm/settings/tc_config/tfilter", test_tc_config_tfilter); + g_test_add_func ("/libnm/settings/tc_config/tfilter/matchall_sdata", + test_tc_config_tfilter_matchall_sdata); + g_test_add_func ("/libnm/settings/tc_config/tfilter/matchall_mirred", + test_tc_config_tfilter_matchall_mirred); g_test_add_func ("/libnm/settings/tc_config/setting/valid", test_tc_config_setting_valid); g_test_add_func ("/libnm/settings/tc_config/setting/duplicates", test_tc_config_setting_duplicates); g_test_add_func ("/libnm/settings/tc_config/dbus", test_tc_config_dbus); @@ -4048,6 +4105,7 @@ main (int argc, char **argv) g_test_add_func ("/libnm/settings/bridge/vlans", test_bridge_vlans); g_test_add_func ("/libnm/settings/bridge/verify", test_bridge_verify); + g_test_add_func ("/libnm/test_nm_json", test_nm_json); g_test_add_func ("/libnm/settings/team/sync_runner_from_config_roundrobin", test_runner_roundrobin_sync_from_config); g_test_add_func ("/libnm/settings/team/sync_runner_from_config_broadcast", |