diff options
| author | Michael Biebl <biebl@debian.org> | 2021-02-11 18:11:46 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2021-02-11 18:11:46 +0100 |
| commit | 80ec1decc49c72efec2a8b87c06245c92c0ab807 (patch) | |
| tree | e3b229aa94e8dcf0590f2317664176e7b8f7607b /libnm-core/tests | |
| parent | 65f86e8f56267192d42f2b629fc6b0c99fb9cd0c (diff) | |
New upstream version 1.29.90 upstream/1.29.90
Diffstat (limited to 'libnm-core/tests')
| -rw-r--r-- | libnm-core/tests/meson.build | 40 | ||||
| -rw-r--r-- | libnm-core/tests/test-compare.c | 4 | ||||
| -rw-r--r-- | libnm-core/tests/test-crypto.c | 4 | ||||
| -rw-r--r-- | libnm-core/tests/test-general-enums.h | 2 | ||||
| -rw-r--r-- | libnm-core/tests/test-general.c | 142 | ||||
| -rw-r--r-- | libnm-core/tests/test-keyfile.c | 8 | ||||
| -rw-r--r-- | libnm-core/tests/test-secrets.c | 4 | ||||
| -rw-r--r-- | libnm-core/tests/test-setting.c | 7 | ||||
| -rw-r--r-- | libnm-core/tests/test-settings-defaults.c | 4 |
9 files changed, 160 insertions, 55 deletions
diff --git a/libnm-core/tests/meson.build b/libnm-core/tests/meson.build index 4ce42526..df5209b4 100644 --- a/libnm-core/tests/meson.build +++ b/libnm-core/tests/meson.build @@ -1,36 +1,12 @@ -# SPDX-License-Identifier: LGPL-2.1+ - -# test-cert.p12 created with: -# -# openssl pkcs12 -export \ -# -in test_key_and_cert.pem \ -# -inkey test_key_and_cert.pem \ -# -certfile test_ca_cert.pem \ -# -name "test-pkcs12" \ -# -out test-cert.p12 - -enum_types = 'nm-core-tests-enum-types' +# SPDX-License-Identifier: LGPL-2.1-or-later enum_sources = gnome.mkenums_simple( - enum_types, + 'nm-core-tests-enum-types', sources: 'test-general-enums.h', identifier_prefix: nm_id_prefix, - body_prefix: '#include "nm-default.h"', + body_prefix: '#include "libnm-core/nm-default-libnm-core.h"', ) -deps = [ - libnm_keyfile_dep, - libnm_core_dep, - libnm_core_nm_default_dep, -] - -c_flags = [ - '-DNETWORKMANAGER_COMPILATION_TEST', - '-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM_CORE', -] - -test_cert_dir = join_paths(meson.current_source_dir(), 'certs') - test_units = [ 'test-compare', 'test-crypto', @@ -45,8 +21,14 @@ foreach test_unit: test_units exe = executable( 'libnm-core-' + test_unit, [test_unit + '.c'] + enum_sources, - dependencies: deps, - c_args: c_flags, + dependencies: [ + libnm_core_dep, + libnm_core_nm_default_dep, + libnm_base_dep, + ], + c_args: [ + '-DG_LOG_DOMAIN="test"', + ], link_with: libnm_systemd_logging_stub, ) diff --git a/libnm-core/tests/test-compare.c b/libnm-core/tests/test-compare.c index e8c3ec33..27049e87 100644 --- a/libnm-core/tests/test-compare.c +++ b/libnm-core/tests/test-compare.c @@ -1,10 +1,10 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2007 - 2014 Red Hat, Inc. * Copyright (C) 2007 - 2008 Novell, Inc. */ -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include <arpa/inet.h> #include <netinet/in.h> diff --git a/libnm-core/tests/test-crypto.c b/libnm-core/tests/test-crypto.c index a8af7f84..4e288b7b 100644 --- a/libnm-core/tests/test-crypto.c +++ b/libnm-core/tests/test-crypto.c @@ -1,10 +1,10 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Dan Williams <dcbw@redhat.com> * Copyright (C) 2007 - 2011 Red Hat, Inc. */ -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include <unistd.h> #include <stdlib.h> diff --git a/libnm-core/tests/test-general-enums.h b/libnm-core/tests/test-general-enums.h index 29b8823c..b3163e23 100644 --- a/libnm-core/tests/test-general-enums.h +++ b/libnm-core/tests/test-general-enums.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2015 Red Hat, Inc. */ diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 65717144..885319fc 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -1,20 +1,23 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2008 - 2018 Red Hat, Inc. */ #define NM_GLIB_COMPAT_H_TEST -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <linux/if_ether.h> +#include <linux/if_infiniband.h> #include "nm-std-aux/c-list-util.h" #include "nm-glib-aux/nm-enum-utils.h" #include "nm-glib-aux/nm-str-buf.h" #include "nm-glib-aux/nm-json-aux.h" +#include "nm-base/nm-base.h" #include "systemd/nm-sd-utils-shared.h" #include "nm-utils.h" @@ -54,9 +57,10 @@ #include "nm-setting-wireless-security.h" #include "nm-setting-wpan.h" #include "nm-simple-connection.h" -#include "nm-keyfile/nm-keyfile-internal.h" +#include "nm-keyfile-internal.h" #include "nm-glib-aux/nm-dedup-multi.h" -#include "nm-libnm-core-intern/nm-ethtool-utils.h" +#include "nm-base/nm-ethtool-base.h" +#include "nm-base/nm-ethtool-utils-base.h" #include "test-general-enums.h" @@ -72,6 +76,12 @@ G_STATIC_ASSERT(sizeof(bool) <= sizeof(int)); /*****************************************************************************/ +/* NM_UTILS_HWADDR_LEN_MAX is public API of libnm(-core) and _NM_UTILS_HWADDR_LEN_MAX + * is internal API. They are the same, but the latter can be used without including libnm-core. */ +G_STATIC_ASSERT(NM_UTILS_HWADDR_LEN_MAX == _NM_UTILS_HWADDR_LEN_MAX); + +/*****************************************************************************/ + static void test_nm_ascii_spaces(void) { @@ -95,6 +105,57 @@ test_nm_ascii_spaces(void) /*****************************************************************************/ +static void +test_wired_wake_on_lan_enum(void) +{ + nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; + + G_STATIC_ASSERT_EXPR(sizeof(NMSettingWiredWakeOnLan) == sizeof(_NMSettingWiredWakeOnLan)); + G_STATIC_ASSERT_EXPR(sizeof(NMSettingWiredWakeOnLan) < sizeof(gint64)); + + G_STATIC_ASSERT_EXPR(sizeof(NMSettingWiredWakeOnLan) < sizeof(gint64)); + g_assert((((gint64)((NMSettingWiredWakeOnLan) -1)) < 0) + == (((gint64)((_NMSettingWiredWakeOnLan) -1)) < 0)); + +#define _E(n) \ + G_STMT_START \ + { \ + G_STATIC_ASSERT_EXPR(n == (gint64) _##n); \ + G_STATIC_ASSERT_EXPR(_##n == (gint64) n); \ + g_assert(_##n == _NM_SETTING_WIRED_WAKE_ON_LAN_CAST(n)); \ + if (!g_hash_table_add(vals, GUINT_TO_POINTER(n))) \ + g_assert_not_reached(); \ + } \ + G_STMT_END + _E(NM_SETTING_WIRED_WAKE_ON_LAN_NONE); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_PHY); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_ARP); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_ALL); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE); + _E(NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS); +#undef _E + + flags_class = G_FLAGS_CLASS(g_type_class_ref(NM_TYPE_SETTING_WIRED_WAKE_ON_LAN)); + for (i = 0; i < flags_class->n_values; i++) { + const GFlagsValue *value = &flags_class->values[i]; + + if (!g_hash_table_contains(vals, GUINT_TO_POINTER(value->value))) { + g_error("The enum value %s from NMSettingWiredWakeOnLan is not checked for " + "_NMSettingWiredWakeOnLan", + value->value_name); + } + } +} + +/*****************************************************************************/ + typedef struct _nm_packed { int v0; char v1; @@ -330,7 +391,7 @@ _do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, } g_assert(words_g[words_len] == NULL); g_assert_cmpint(NM_PTRARRAY_LEN(words_g), ==, words_len); - g_assert(_nm_utils_strv_cmp_n(exp_words, words_len, NM_CAST_STRV_CC(words_g), -1) == 0); + g_assert(nm_utils_strv_cmp_n(exp_words, words_len, words_g, -1) == 0); } } @@ -354,7 +415,7 @@ _do_test_nm_utils_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, g_assert_cmpstr(exp_words[i], ==, words[i]); g_assert(words[words_len] == NULL); - g_assert(_nm_utils_strv_cmp_n(exp_words, words_len, words, -1) == 0); + g_assert(nm_utils_strv_cmp_n(exp_words, words_len, words, -1) == 0); s1 = words[0]; g_assert(s1 >= (char *) &words[words_len + 1]); @@ -515,7 +576,7 @@ _do_test_nm_utils_strsplit_set_simple(NMUtilsStrsplitSetFlags flags, g_assert_cmpint(words_len, >, 0); n_tokens = NM_PTRARRAY_LEN(tokens); - if (_nm_utils_strv_cmp_n(exp_words, words_len, tokens, -1) != 0) { + if (nm_utils_strv_cmp_n(exp_words, words_len, tokens, -1) != 0) { gsize i; g_print(">>> split \"%s\" (flags %x) got %zu tokens (%zu expected)\n", @@ -1225,7 +1286,7 @@ _dedup_obj_destroy(NMDedupMultiObj *obj) { DedupObj *o = (DedupObj *) obj; - nm_assert(o->parent._ref_count == 0); + g_assert(o->parent._ref_count == 0); o->parent._ref_count = 1; o = _dedup_obj_assert(obj); g_slice_free(DedupObj, o); @@ -5425,7 +5486,7 @@ _test_connection_normalize_type_normalizable_type(const char *type, if (add_setting_fcn) s_base = add_setting_fcn(con); else { - s_base = NM_SETTING(g_object_new(base_type, NULL)); + s_base = g_object_new(base_type, NULL); nm_connection_add_setting(con, s_base); } @@ -8803,6 +8864,20 @@ test_nm_utils_enum(void) NULL, color_value_infos); + _test_nm_utils_enum_from_str_do_full(NM_TYPE_SETTING_CONNECTION_LLMNR, + "-1", + TRUE, + -1, + NULL, + NULL); + + _test_nm_utils_enum_from_str_do_full(NM_TYPE_SETTING_CONNECTION_LLMNR, + "-0x1", + TRUE, + -1, + NULL, + NULL); + _test_nm_utils_enum_get_values_do(bool_enum, 0, G_MAXINT, "no,yes,maybe,unknown,67,64"); _test_nm_utils_enum_get_values_do(bool_enum, NM_TEST_GENERAL_BOOL_ENUM_YES, @@ -9538,6 +9613,11 @@ test_ethtool_offload(void) g_assert(d); g_assert_cmpint(d->id, ==, NM_ETHTOOL_ID_FEATURE_RXHASH); g_assert_cmpstr(d->optname, ==, NM_ETHTOOL_OPTNAME_FEATURE_RXHASH); + + /* these features are NETIF_F_NEVER_CHANGE: */ + g_assert(!nm_ethtool_data_get_by_optname("feature-netns-local")); + g_assert(!nm_ethtool_data_get_by_optname("feature-tx-lockless")); + g_assert(!nm_ethtool_data_get_by_optname("feature-vlan-challenged")); } /*****************************************************************************/ @@ -10058,7 +10138,7 @@ _strsplit_quoted_assert_strv(const char * topic, g_assert(strv1); g_assert(strv2); - if (_nm_utils_strv_equal((char **) strv1, (char **) strv2)) + if (nm_utils_strv_equal(strv1, strv2)) return; for (i = 0; strv1[i]; i++) { @@ -10198,6 +10278,45 @@ test_nm_utils_wifi_ghz_freqs(void) /*****************************************************************************/ +static void +test_vpn_connection_state_reason(void) +{ +#define ASSERT(v1, v2) \ + G_STMT_START \ + { \ + G_STATIC_ASSERT((gint64)(v1) == v2); \ + G_STATIC_ASSERT((gint64)(v2) == v1); \ + \ + nm_assert(((NMActiveConnectionStateReason)(int) (v1)) == v2); \ + nm_assert(((NMVpnConnectionStateReason)(int) (v2)) == v1); \ + } \ + G_STMT_END + + ASSERT(NM_VPN_CONNECTION_STATE_REASON_UNKNOWN, NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_NONE, NM_ACTIVE_CONNECTION_STATE_REASON_NONE); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED, + NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, + NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, + NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED); + ASSERT(NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED, + NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED); +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -10206,6 +10325,7 @@ main(int argc, char **argv) nmtst_init(&argc, &argv, TRUE); g_test_add_func("/core/general/test_nm_ascii_spaces", test_nm_ascii_spaces); + g_test_add_func("/core/general/test_wired_wake_on_lan_enum", test_wired_wake_on_lan_enum); g_test_add_func("/core/general/test_nm_hash", test_nm_hash); g_test_add_func("/core/general/test_nm_g_slice_free_fcn", test_nm_g_slice_free_fcn); g_test_add_func("/core/general/test_c_list_sort", test_c_list_sort); @@ -10527,6 +10647,8 @@ main(int argc, char **argv) g_test_add_func("/core/general/test_nm_utils_wifi_ghz_freqs", test_nm_utils_wifi_ghz_freqs); g_test_add_func("/core/general/test_strsplit_quoted", test_strsplit_quoted); + g_test_add_func("/core/general/test_vpn_connection_state_reason", + test_vpn_connection_state_reason); return g_test_run(); } diff --git a/libnm-core/tests/test-keyfile.c b/libnm-core/tests/test-keyfile.c index 2b3750a9..b3af6c4e 100644 --- a/libnm-core/tests/test-keyfile.c +++ b/libnm-core/tests/test-keyfile.c @@ -1,13 +1,13 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2015 Red Hat, Inc. */ -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include "nm-glib-aux/nm-json-aux.h" -#include "nm-keyfile/nm-keyfile-utils.h" -#include "nm-keyfile/nm-keyfile-internal.h" +#include "nm-keyfile-utils.h" +#include "nm-keyfile-internal.h" #include "nm-simple-connection.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" diff --git a/libnm-core/tests/test-secrets.c b/libnm-core/tests/test-secrets.c index eb08104a..42f1fd0a 100644 --- a/libnm-core/tests/test-secrets.c +++ b/libnm-core/tests/test-secrets.c @@ -1,9 +1,9 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2008 - 2011 Red Hat, Inc. */ -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include "nm-setting-8021x.h" #include "nm-setting-cdma.h" diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index 8978f73e..01cdb41c 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -1,14 +1,15 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2008 - 2017 Red Hat, Inc. */ -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include <linux/pkt_sched.h> #include <net/if.h> #include "nm-glib-aux/nm-json-aux.h" +#include "nm-base/nm-ethtool-utils-base.h" #include "nm-core-internal.h" #include "nm-utils.h" #include "nm-utils-private.h" @@ -25,7 +26,7 @@ #include "nm-simple-connection.h" #include "nm-setting-connection.h" #include "nm-errors.h" -#include "nm-keyfile/nm-keyfile-internal.h" +#include "nm-keyfile-internal.h" #include "nm-utils/nm-test-utils.h" diff --git a/libnm-core/tests/test-settings-defaults.c b/libnm-core/tests/test-settings-defaults.c index 9e4b09a1..1e6acd3c 100644 --- a/libnm-core/tests/test-settings-defaults.c +++ b/libnm-core/tests/test-settings-defaults.c @@ -1,9 +1,9 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2008 - 2011 Red Hat, Inc. */ -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include "nm-utils.h" #include "nm-setting-8021x.h" |