mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-21 14:18:12 +02:00
We use clang-format for automatic formatting of our source files. Since clang-format is actively maintained software, the actual formatting depends on the used version of clang-format. That is unfortunate and painful, but really unavoidable unless clang-format would be strictly bug-compatible. So the version that we must use is from the current Fedora release, which is also tested by our gitlab-ci. Previously, we were using Fedora 34 with clang-tools-extra-12.0.1-1.fc34.x86_64. As Fedora 35 comes along, we need to update our formatting as Fedora 35 comes with version "13.0.0~rc1-1.fc35". An alternative would be to freeze on version 12, but that has different problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it would be cumbersome for our developers which are on Fedora 35 to use a clang that they cannot easily install). The (differently painful) solution is to reformat from time to time, as we switch to a new Fedora (and thus clang) version. Usually we would expect that such a reformatting brings minor changes. But this time, the changes are huge. That is mentioned in the release notes [1] as Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353) [1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
126 lines
3.7 KiB
C
126 lines
3.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
|
*/
|
|
|
|
#include "src/core/nm-default-daemon.h"
|
|
|
|
#include "nm-simple-connection.h"
|
|
#include "nm-setting-connection.h"
|
|
#include "devices/nm-device-ethernet-utils.h"
|
|
|
|
#include "nm-test-utils-core.h"
|
|
|
|
static NMConnection *
|
|
_new_connection(const char *id)
|
|
{
|
|
NMConnection *a;
|
|
NMSetting *setting;
|
|
|
|
a = nm_simple_connection_new();
|
|
setting = nm_setting_connection_new();
|
|
g_object_set(setting, NM_SETTING_CONNECTION_ID, id, NULL);
|
|
nm_connection_add_setting(a, setting);
|
|
return a;
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static char *
|
|
_get_default_wired_name(GSList *list)
|
|
{
|
|
gs_unref_hashtable GHashTable *existing_ids = NULL;
|
|
|
|
if (list) {
|
|
existing_ids = g_hash_table_new(nm_str_hash, g_str_equal);
|
|
for (; list; list = list->next)
|
|
g_hash_table_add(existing_ids, (char *) nm_connection_get_id(list->data));
|
|
}
|
|
return nm_device_ethernet_utils_get_default_wired_name(existing_ids);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
test_defname_no_connections(void)
|
|
{
|
|
gs_free char *name = NULL;
|
|
|
|
name = _get_default_wired_name(NULL);
|
|
g_assert_cmpstr(name, ==, "Wired connection 1");
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
test_defname_no_conflict(void)
|
|
{
|
|
GSList *list = NULL;
|
|
gs_free char *name = NULL;
|
|
|
|
list = g_slist_append(list, _new_connection("asdfasdfasdfadf"));
|
|
list = g_slist_append(list, _new_connection("work wifi"));
|
|
list = g_slist_append(list, _new_connection("random gsm connection"));
|
|
|
|
name = _get_default_wired_name(list);
|
|
g_assert_cmpstr(name, ==, "Wired connection 1");
|
|
|
|
g_slist_free_full(list, g_object_unref);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
test_defname_conflict(void)
|
|
{
|
|
GSList *list = NULL;
|
|
gs_free char *name = NULL;
|
|
|
|
list = g_slist_append(list, _new_connection("asdfasdfasdfadf"));
|
|
list = g_slist_append(list, _new_connection("Wired connection 1"));
|
|
list = g_slist_append(list, _new_connection("random gsm connection"));
|
|
|
|
name = _get_default_wired_name(list);
|
|
g_assert_cmpstr(name, ==, "Wired connection 2");
|
|
|
|
g_slist_free_full(list, g_object_unref);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
test_defname_multiple_conflicts(void)
|
|
{
|
|
GSList *list = NULL;
|
|
gs_free char *name = NULL;
|
|
|
|
list = g_slist_append(list, _new_connection("random gsm connection"));
|
|
list = g_slist_append(list, _new_connection("home wifi"));
|
|
list = g_slist_append(list, _new_connection("Wired connection 1"));
|
|
list = g_slist_append(list, _new_connection("Wired connection 2"));
|
|
list = g_slist_append(list, _new_connection("Wired connection 3"));
|
|
list = g_slist_append(list, _new_connection("work wifi"));
|
|
list = g_slist_append(list, _new_connection("a vpn"));
|
|
|
|
name = _get_default_wired_name(list);
|
|
g_assert_cmpstr(name, ==, "Wired connection 4");
|
|
|
|
g_slist_free_full(list, g_object_unref);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
NMTST_DEFINE();
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
nmtst_init_assert_logging(&argc, &argv, "INFO", "DEFAULT");
|
|
|
|
g_test_add_func("/defname/no_connections", test_defname_no_connections);
|
|
g_test_add_func("/defname/no_conflict", test_defname_no_conflict);
|
|
g_test_add_func("/defname/conflict", test_defname_conflict);
|
|
g_test_add_func("/defname/multiple_conflicts", test_defname_multiple_conflicts);
|
|
|
|
return g_test_run();
|
|
}
|