mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-01 14:00:34 +02:00
wifi/tests: add test for ssids_options_to_ptrarray()
This commit is contained in:
parent
7d8da6c9c1
commit
023dc9646c
3 changed files with 67 additions and 0 deletions
|
|
@ -1079,6 +1079,8 @@ ssids_options_to_ptrarray (GVariant *value, GError **error)
|
|||
gsize len;
|
||||
int num_ssids, i;
|
||||
|
||||
nm_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("aay")));
|
||||
|
||||
num_ssids = g_variant_n_children (value);
|
||||
if (num_ssids > 32) {
|
||||
g_set_error_literal (error,
|
||||
|
|
@ -1110,6 +1112,12 @@ ssids_options_to_ptrarray (GVariant *value, GError **error)
|
|||
return ssids;
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
nmtst_ssids_options_to_ptrarray (GVariant *value, GError **error)
|
||||
{
|
||||
return ssids_options_to_ptrarray (value, error);
|
||||
}
|
||||
|
||||
static void
|
||||
dbus_request_scan_cb (NMDevice *device,
|
||||
GDBusMethodInvocation *context,
|
||||
|
|
|
|||
|
|
@ -40,4 +40,6 @@ void _nm_device_wifi_request_scan (NMDeviceWifi *self,
|
|||
GVariant *options,
|
||||
GDBusMethodInvocation *invocation);
|
||||
|
||||
GPtrArray *nmtst_ssids_options_to_ptrarray (GVariant *value, GError **error);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DEVICE_WIFI_H__ */
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "nm-default.h"
|
||||
|
||||
#include "devices/wifi/nm-wifi-utils.h"
|
||||
#include "devices/wifi/nm-device-wifi.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
#include "nm-test-utils-core.h"
|
||||
|
|
@ -1337,6 +1338,60 @@ test_strength_all (void)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
do_test_ssids_options_to_ptrarray (const char *const*ssids)
|
||||
{
|
||||
GVariantBuilder builder;
|
||||
gs_unref_variant GVariant *variant = NULL;
|
||||
gs_unref_ptrarray GPtrArray *ssids_arr = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
gsize len;
|
||||
gsize i;
|
||||
|
||||
g_assert (ssids);
|
||||
|
||||
len = NM_PTRARRAY_LEN (ssids);
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
|
||||
for (i = 0; i < len; i++) {
|
||||
const char *ssid = ssids[i];
|
||||
|
||||
g_variant_builder_add (&builder,
|
||||
"@ay",
|
||||
g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, ssid, strlen (ssid), 1));
|
||||
}
|
||||
variant = g_variant_builder_end (&builder);
|
||||
|
||||
if (nmtst_get_rand_bool ())
|
||||
g_variant_ref_sink (variant);
|
||||
|
||||
ssids_arr = nmtst_ssids_options_to_ptrarray (variant, &error);
|
||||
g_assert (!error);
|
||||
if (len == 0) {
|
||||
g_assert (!ssids_arr);
|
||||
return;
|
||||
}
|
||||
g_assert_cmpint (len, ==, ssids_arr->len);
|
||||
for (i = 0; i < len; i++) {
|
||||
const char *ssid = ssids[i];
|
||||
GBytes *bytes = ssids_arr->pdata[i];
|
||||
|
||||
g_assert (nm_utils_gbytes_equal_mem (bytes,
|
||||
ssid,
|
||||
strlen (ssid)));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_ssids_options_to_ptrarray (void)
|
||||
{
|
||||
do_test_ssids_options_to_ptrarray (NM_PTRARRAY_EMPTY (const char *));
|
||||
do_test_ssids_options_to_ptrarray (NM_MAKE_STRV ("ab"));
|
||||
do_test_ssids_options_to_ptrarray (NM_MAKE_STRV ("ab", "cd", "fsdfdsf"));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMTST_DEFINE ();
|
||||
|
||||
int
|
||||
|
|
@ -1501,5 +1556,7 @@ main (int argc, char **argv)
|
|||
g_test_add_func ("/wifi/strength/all",
|
||||
test_strength_all);
|
||||
|
||||
g_test_add_func ("/wifi/ssids_options_to_ptrarray", test_ssids_options_to_ptrarray);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue