Skip to content

Commit

Permalink
Add array of structures aligning to .clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Kemel <mkemel@redhat.com>
  • Loading branch information
mkemel authored and engelmi committed Jan 5, 2024
1 parent 93bfea1 commit cbcd280
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
---
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Left
AlignEscapedNewlines: Left
AlignOperands: false
AllowShortFunctionsOnASingleLine: None
Expand Down Expand Up @@ -124,4 +125,4 @@ SpaceAroundPointerQualifiers: Both
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpacesInAngles: true
TabWidth: 8
UseCRLF: false
UseCRLF: false
22 changes: 12 additions & 10 deletions src/agent/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
8 changes: 5 additions & 3 deletions src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions src/libbluechi/test/common/network/get_address_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
66 changes: 33 additions & 33 deletions src/libbluechi/test/log/bc_log_init_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};


Expand Down
12 changes: 7 additions & 5 deletions src/manager/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions src/proxy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cbcd280

Please sign in to comment.