From cbcd280c1f6000b269359c9f7cee68873f95f042 Mon Sep 17 00:00:00 2001 From: Mark Kemel Date: Fri, 5 Jan 2024 10:24:02 +0200 Subject: [PATCH] Add array of structures aligning to .clang-format Signed-off-by: Mark Kemel --- .clang-format | 3 +- src/agent/main.c | 22 +++--- src/client/main.c | 8 ++- .../cfg_load_complete_configuration_test.c | 68 ++++++++----------- .../test/common/network/get_address_test.c | 14 ++-- src/libbluechi/test/log/bc_log_init_test.c | 66 +++++++++--------- src/manager/main.c | 12 ++-- src/proxy/main.c | 10 +-- 8 files changed, 102 insertions(+), 101 deletions(-) diff --git a/.clang-format b/.clang-format index 6847fec729..b159812183 100644 --- a/.clang-format +++ b/.clang-format @@ -26,6 +26,7 @@ --- AccessModifierOffset: -4 AlignAfterOpenBracket: AlwaysBreak +AlignArrayOfStructures: Left AlignEscapedNewlines: Left AlignOperands: false AllowShortFunctionsOnASingleLine: None @@ -124,4 +125,4 @@ SpaceAroundPointerQualifiers: Both SpaceBeforeParens: ControlStatementsExceptForEachMacros SpacesInAngles: true TabWidth: 8 -UseCRLF: false \ No newline at end of file +UseCRLF: false diff --git a/src/agent/main.c b/src/agent/main.c index e620ae3957..0b71adce02 100644 --- a/src/agent/main.c +++ b/src/agent/main.c @@ -10,16 +10,18 @@ #include "agent.h" -const struct option options[] = { { ARG_HOST, required_argument, 0, ARG_HOST_SHORT }, - { ARG_PORT, required_argument, 0, ARG_PORT_SHORT }, - { ARG_ADDRESS, required_argument, 0, ARG_ADDRESS_SHORT }, - { ARG_NAME, required_argument, 0, ARG_NAME_SHORT }, - { ARG_HEARTBEAT_INTERVAL, required_argument, 0, ARG_HEARTBEAT_INTERVAL_SHORT }, - { ARG_CONFIG, required_argument, 0, ARG_CONFIG_SHORT }, - { ARG_USER, no_argument, 0, ARG_USER_SHORT }, - { ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, - { ARG_VERSION, no_argument, 0, ARG_VERSION_SHORT }, - { NULL, 0, 0, '\0' } }; +const struct option options[] = { + {ARG_HOST, required_argument, 0, ARG_HOST_SHORT }, + { ARG_PORT, required_argument, 0, ARG_PORT_SHORT }, + { ARG_ADDRESS, required_argument, 0, ARG_ADDRESS_SHORT }, + { ARG_NAME, required_argument, 0, ARG_NAME_SHORT }, + { ARG_HEARTBEAT_INTERVAL, required_argument, 0, ARG_HEARTBEAT_INTERVAL_SHORT}, + { ARG_CONFIG, required_argument, 0, ARG_CONFIG_SHORT }, + { ARG_USER, no_argument, 0, ARG_USER_SHORT }, + { ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, + { ARG_VERSION, no_argument, 0, ARG_VERSION_SHORT }, + { NULL, 0, 0, '\0' } +}; #define OPTIONS_STR \ ARG_PORT_SHORT_S ARG_HOST_SHORT_S ARG_ADDRESS_SHORT_S ARG_HELP_SHORT_S ARG_CONFIG_SHORT_S \ diff --git a/src/client/main.c b/src/client/main.c index e9e476437a..2f9686c65c 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -8,9 +8,11 @@ #include "client.h" -const struct option options[] = { { ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, - { ARG_FILTER, required_argument, 0, ARG_FILTER_SHORT }, - { NULL, 0, 0, '\0' } }; +const struct option options[] = { + {ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, + { ARG_FILTER, required_argument, 0, ARG_FILTER_SHORT}, + { NULL, 0, 0, '\0' } +}; #define OPTIONS_STR ARG_HELP_SHORT_S ARG_FILTER_SHORT_S diff --git a/src/libbluechi/test/common/cfg/cfg_load_complete_configuration_test.c b/src/libbluechi/test/common/cfg/cfg_load_complete_configuration_test.c index 79137f13f3..e21be8f799 100644 --- a/src/libbluechi/test/common/cfg/cfg_load_complete_configuration_test.c +++ b/src/libbluechi/test/common/cfg/cfg_load_complete_configuration_test.c @@ -35,59 +35,51 @@ typedef struct cfg_test_param { } cfg_test_param; struct cfg_test_param test_data[] = { - /* basic single config file tests */ - { "no config files", - { NULL, NULL, { NULL, NULL } }, - 0, - { { NULL, NULL }, { NULL, NULL }, { NULL, NULL } } }, + /* basic single config file tests */ + {"no config files", + { NULL, NULL, { NULL, NULL } }, + 0, { { NULL, NULL }, { NULL, NULL }, { NULL, NULL } } }, { "only default config file", - { "NodeName = laptop\n", NULL, { NULL, NULL } }, - 0, - { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, + { "NodeName = laptop\n", NULL, { NULL, NULL } }, + 0, { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, { "only custom config file", - { NULL, "NodeName = laptop\n", { NULL, NULL } }, - 0, - { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, + { NULL, "NodeName = laptop\n", { NULL, NULL } }, + 0, { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, { "only file in confd", - { NULL, "NodeName = laptop\n", { "NodeName = laptop\n", NULL } }, - 0, - { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, + { NULL, "NodeName = laptop\n", { "NodeName = laptop\n", NULL } }, + 0, { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, - /* testing of loading order and overwrite */ + /* testing of loading order and overwrite */ { "with custom config file", - { "NodeName = laptop\n", "NodeName = pi\n", { NULL, NULL } }, - 0, - { { "NodeName", "pi" }, { NULL, NULL }, { NULL, NULL } } }, + { "NodeName = laptop\n", "NodeName = pi\n", { NULL, NULL } }, + 0, { { "NodeName", "pi" }, { NULL, NULL }, { NULL, NULL } } }, { "with config file in confd", - { "NodeName = laptop\n", "NodeName = pi\n", { "NodeName = vm\n", NULL } }, - 0, - { { "NodeName", "vm" }, { NULL, NULL }, { NULL, NULL } } }, + { "NodeName = laptop\n", "NodeName = pi\n", { "NodeName = vm\n", NULL } }, + 0, { { "NodeName", "vm" }, { NULL, NULL }, { NULL, NULL } } }, { "with multiple config files in confd", - { "NodeName = laptop\n", "NodeName = pi\n", { "NodeName = vm\n", "NodeName = container\n" } }, - 0, - { { "NodeName", "container" }, { NULL, NULL }, { NULL, NULL } } }, + { "NodeName = laptop\n", "NodeName = pi\n", { "NodeName = vm\n", "NodeName = container\n" } }, + 0, { { "NodeName", "container" }, { NULL, NULL }, { NULL, NULL } } }, - /* testing of loading order, overwrite and merges */ + /* testing of loading order, overwrite and merges */ { "with multiple, duplicate keys", - { "NodeName = laptop\nLogLevel=INFO\n", + { "NodeName = laptop\nLogLevel=INFO\n", "NodeName = pi\n", { "LogLevel=DEBUG\n", "LogTarget=stderr\n" } }, - 0, - { { "NodeName", "pi" }, { "LogLevel", "DEBUG" }, { "LogTarget", "stderr" } } }, + 0, { { "NodeName", "pi" }, { "LogLevel", "DEBUG" }, { "LogTarget", "stderr" } }}, - /* testing invalid entries */ + /* testing invalid entries */ { "with invalid value in default config file", - { "NodeName 0 laptop\n", "NodeName = pi\n", { "LogLevel=DEBUG\n", "LogTarget=stderr\n" } }, - -EINVAL, - { { NULL, NULL }, { NULL, NULL }, { NULL, NULL } } }, + { "NodeName 0 laptop\n", "NodeName = pi\n", { "LogLevel=DEBUG\n", "LogTarget=stderr\n" } }, + -EINVAL, + { { NULL, NULL }, { NULL, NULL }, { NULL, NULL } } }, { "with invalid value in custom config file", - { "NodeName = laptop\n", "NodeName 0 pi\n", { "LogLevel=DEBUG\n", "LogTarget=stderr\n" } }, - -EINVAL, - { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, + { "NodeName = laptop\n", "NodeName 0 pi\n", { "LogLevel=DEBUG\n", "LogTarget=stderr\n" } }, + -EINVAL, + { { "NodeName", "laptop" }, { NULL, NULL }, { NULL, NULL } } }, { "with invalid value in one of the confd files", - { "NodeName = laptop\n", "NodeName = pi\n", { "LogLevel=DEBUG\n", "LogTarget0stderr\n" } }, - -EINVAL, - { { "NodeName", "pi" }, { "LogLevel", "DEBUG" }, { NULL, NULL } } }, + { "NodeName = laptop\n", "NodeName = pi\n", { "LogLevel=DEBUG\n", "LogTarget0stderr\n" } }, + -EINVAL, + { { "NodeName", "pi" }, { "LogLevel", "DEBUG" }, { NULL, NULL } } }, }; void create_file(const char *file_path, const char *cfg_file_content) { diff --git a/src/libbluechi/test/common/network/get_address_test.c b/src/libbluechi/test/common/network/get_address_test.c index 7af96a1f0c..2bfa3332a9 100644 --- a/src/libbluechi/test/common/network/get_address_test.c +++ b/src/libbluechi/test/common/network/get_address_test.c @@ -17,13 +17,13 @@ typedef struct get_address_test_params { long unsigned int test_data_index = 0; struct get_address_test_params test_data[] = { - { NULL, true, NULL, -EINVAL }, - { ".", true, NULL, -1 }, - { "redhat", true, NULL, -1 }, - { "?10.10.10.3", true, NULL, -1 }, - { "192.168.1.", true, NULL, -1 }, - { "8.8.8.8", true, NULL, 0 }, - { "localhost.localdomain", true, "127.0.0.1", 0 }, + {NULL, true, NULL, -EINVAL}, + { ".", true, NULL, -1 }, + { "redhat", true, NULL, -1 }, + { "?10.10.10.3", true, NULL, -1 }, + { "192.168.1.", true, NULL, -1 }, + { "8.8.8.8", true, NULL, 0 }, + { "localhost.localdomain", true, "127.0.0.1", 0 }, }; int getaddrinfo_mock( diff --git a/src/libbluechi/test/log/bc_log_init_test.c b/src/libbluechi/test/log/bc_log_init_test.c index 13b7a093bd..f26502136f 100644 --- a/src/libbluechi/test/log/bc_log_init_test.c +++ b/src/libbluechi/test/log/bc_log_init_test.c @@ -19,39 +19,39 @@ typedef struct log_test_param { struct log_test_param test_data[] = { - // test valid log targets - { "journald", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "stderr", "INFO", "false", bc_log_to_stderr_with_location, LOG_LEVEL_INFO, false }, - { "stderr-full", "INFO", "false", bc_log_to_stderr_full_with_location, LOG_LEVEL_INFO, false }, - // test valid log levels - { "journald", "DEBUG", "false", bc_log_to_journald_with_location, LOG_LEVEL_DEBUG, false }, - { "journald", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "journald", "ERROR", "false", bc_log_to_journald_with_location, LOG_LEVEL_ERROR, false }, - { "journald", "WARN", "false", bc_log_to_journald_with_location, LOG_LEVEL_WARN, false }, - // test valid is quiet - { "journald", "INFO", "true", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, - - // test invalid log targets: should result in a default log function - { NULL, "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "stderr-ful", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - - // test invalid log levels: should result in a default log function - { "journald", NULL, "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "journald", "", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "journald", "info", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "journald", "just wrong", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - - // test is quiet: different string values interpreted as true - { "journald", "INFO", "true", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, - { "journald", "INFO", "t", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, - { "journald", "INFO", "yes", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, - { "journald", "INFO", "y", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, - { "journald", "INFO", "on", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, - // test is quiet: invalid values should result in false - { "journald", "INFO", "f", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "journald", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, - { "journald", "INFO", "invalid", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false }, + // test valid log targets + {"journald", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "stderr", "INFO", "false", bc_log_to_stderr_with_location, LOG_LEVEL_INFO, false}, + { "stderr-full", "INFO", "false", bc_log_to_stderr_full_with_location, LOG_LEVEL_INFO, false}, + // test valid log levels + { "journald", "DEBUG", "false", bc_log_to_journald_with_location, LOG_LEVEL_DEBUG, false}, + { "journald", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "journald", "ERROR", "false", bc_log_to_journald_with_location, LOG_LEVEL_ERROR, false}, + { "journald", "WARN", "false", bc_log_to_journald_with_location, LOG_LEVEL_WARN, false}, + // test valid is quiet + { "journald", "INFO", "true", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, + + // test invalid log targets: should result in a default log function + { NULL, "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "stderr-ful", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + + // test invalid log levels: should result in a default log function + { "journald", NULL, "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "journald", "", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "journald", "info", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "journald", "just wrong", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + + // test is quiet: different string values interpreted as true + { "journald", "INFO", "true", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, + { "journald", "INFO", "t", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, + { "journald", "INFO", "yes", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, + { "journald", "INFO", "y", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, + { "journald", "INFO", "on", bc_log_to_journald_with_location, LOG_LEVEL_INFO, true }, + // test is quiet: invalid values should result in false + { "journald", "INFO", "f", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "journald", "INFO", "false", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, + { "journald", "INFO", "invalid", bc_log_to_journald_with_location, LOG_LEVEL_INFO, false}, }; diff --git a/src/manager/main.c b/src/manager/main.c index 292dbb0e98..505ed34fd9 100644 --- a/src/manager/main.c +++ b/src/manager/main.c @@ -9,11 +9,13 @@ #include "manager.h" -const struct option options[] = { { ARG_PORT, required_argument, 0, ARG_PORT_SHORT }, - { ARG_CONFIG, required_argument, 0, ARG_CONFIG_SHORT }, - { ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, - { ARG_VERSION, no_argument, 0, ARG_VERSION_SHORT }, - { NULL, 0, 0, '\0' } }; +const struct option options[] = { + {ARG_PORT, required_argument, 0, ARG_PORT_SHORT }, + { ARG_CONFIG, required_argument, 0, ARG_CONFIG_SHORT }, + { ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, + { ARG_VERSION, no_argument, 0, ARG_VERSION_SHORT}, + { NULL, 0, 0, '\0' } +}; #define OPTIONS_STR ARG_PORT_SHORT_S ARG_HELP_SHORT_S ARG_CONFIG_SHORT_S ARG_VERSION_SHORT_S diff --git a/src/proxy/main.c b/src/proxy/main.c index aaabbf4dce..c5b4b38968 100644 --- a/src/proxy/main.c +++ b/src/proxy/main.c @@ -10,10 +10,12 @@ #include "libbluechi/common/opt.h" #include "libbluechi/log/log.h" -const struct option options[] = { { ARG_USER, no_argument, 0, ARG_USER_SHORT }, - { ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, - { ARG_VERSION, no_argument, 0, ARG_VERSION_SHORT }, - { NULL, 0, 0, '\0' } }; +const struct option options[] = { + {ARG_USER, no_argument, 0, ARG_USER_SHORT }, + { ARG_HELP, no_argument, 0, ARG_HELP_SHORT }, + { ARG_VERSION, no_argument, 0, ARG_VERSION_SHORT}, + { NULL, 0, 0, '\0' } +}; #define OPTIONS_STR ARG_HELP_SHORT_S ARG_USER_SHORT_S ARG_VERSION_SHORT_S