Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/project.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: MIT
set(SAMCONF_VERSION 0.75.8)
set(SAMCONF_VERSION 0.75.11)

# Attention: Aside from the version, as many things as possible in this file
# should be put into functions, as this solves potential issues with commands
Expand Down
9 changes: 9 additions & 0 deletions src/samconf/private/samconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,9 @@ samconfConfigStatusE_t samconfConfigSetInt(samconfConfig_t *config, int64_t intV
samconfConfigStatusE_t status = SAMCONF_CONFIG_ERROR;

if (config != NULL) {
if (config->type == SAMCONF_CONFIG_VALUE_STRING) {
free(config->value.string);
}
config->value.integer = intValue;
config->type = SAMCONF_CONFIG_VALUE_INT;
status = SAMCONF_CONFIG_OK;
Expand All @@ -1017,6 +1020,9 @@ samconfConfigStatusE_t samconfConfigSetBool(samconfConfig_t *config, bool value)
samconfConfigStatusE_t status = SAMCONF_CONFIG_ERROR;

if (config != NULL) {
if (config->type == SAMCONF_CONFIG_VALUE_STRING) {
free(config->value.string);
}
config->value.boolean = value;
config->type = SAMCONF_CONFIG_VALUE_BOOLEAN;
status = SAMCONF_CONFIG_OK;
Expand All @@ -1029,6 +1035,9 @@ samconfConfigStatusE_t samconfConfigSetReal(samconfConfig_t *config, double valu
samconfConfigStatusE_t status = SAMCONF_CONFIG_ERROR;

if (config != NULL) {
if (config->type == SAMCONF_CONFIG_VALUE_STRING) {
free(config->value.string);
}
config->value.real = value;
config->type = SAMCONF_CONFIG_VALUE_REAL;
status = SAMCONF_CONFIG_OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void samconfTestSamconfConfigMergeConfigOverwriteSuccess(UNUSED void **state) {
SHOULD("%s", "overwrite value of one config to the other");

testConfigToMerge = calloc(1, sizeof(samconfConfig_t));
result = samconfUtilCreateMockConfigFromStr(_TEST_CONFIG_FETCHAPI, false, testConfigToMerge);
result = samconfUtilCreateMockConfigFromStr(_TEST_CONFIG_FETCHAPI_B, false, testConfigToMerge);
assert_int_equal(result, SAMCONF_CONFIG_OK);

testDefConfig = calloc(1, sizeof(samconfConfig_t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,25 @@
}\
}\
}"

#define _TEST_CONFIG_FETCHAPI_B \
"{\
\"root\": {\
\"elos\": {\
\"EventLogging\": {\
\"Plugins\": {\
\"fetchapi\": {\
\"File\": \"backend_fetchapi.so\",\
\"Run\": \"always\",\
\"Filter\": [\
\"1 1 EQ\"\
],\
\"Config\": {\
\"BufferSize\": \"100\"\
}\
}\
}\
}\
}\
}\
}"
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
// SPDX-License-Identifier: MIT
#include <stdint.h>
#include <string.h>

#include "samconfConfigSetBool_utest.h"

int samconfTestSamconfConfigSetBoolSuccessSetup(UNUSED void **state) {
int samconfTestSamconfConfigSetBoolSuccessSetup(void **state) {
samconfConfig_t *root = NULL;
samconfConfigNew(&root);
root->key = strdup("node");
root->type = SAMCONF_CONFIG_VALUE_STRING;
root->value.string = strdup("test");
*state = root;
return 0;
}

int samconfTestSamconfConfigSetBoolSuccessTeardown(UNUSED void **state) {
int samconfTestSamconfConfigSetBoolSuccessTeardown(void **state) {
samconfConfig_t *root = *state;
samconfConfigDelete(root);
return 0;
}

void samconfTestSamconfConfigSetBoolSuccess(UNUSED void **state) {
void samconfTestSamconfConfigSetBoolSuccess(void **state) {
samconfConfig_t *root = *state;
bool testValue[] = {true, false};

samconfConfigStatusE_t status = SAMCONF_CONFIG_ERROR;

samconfConfig_t root = {
.parent = NULL,
.key = "node",
.type = SAMCONF_CONFIG_VALUE_STRING,
.value.string = "test",
.children = NULL,
.childCount = 0,
};

TEST("samconfConfigSetBool");
SHOULD("%s", "return SAMCONF_CONFIG_OK since given boolean value is set");

for (size_t i = 0; i < ARRAY_SIZE(testValue); i++) {
status = samconfConfigSetBool(&root, testValue[i]);
status = samconfConfigSetBool(root, testValue[i]);
assert_int_equal(status, SAMCONF_CONFIG_OK);
assert_int_equal(root.type, SAMCONF_CONFIG_VALUE_BOOLEAN);
assert_int_equal(root.value.boolean, testValue[i]);
assert_int_equal(root->type, SAMCONF_CONFIG_VALUE_BOOLEAN);
assert_int_equal(root->value.boolean, testValue[i]);
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
// SPDX-License-Identifier: MIT
#include <stdint.h>
#include <string.h>

#include "samconf/samconf.h"
#include "samconf/samconf_types.h"
#include "samconfConfigSetInt_utest.h"

int samconfTestSamconfConfigSetIntSuccessSetup(UNUSED void **state) {
int samconfTestSamconfConfigSetIntSuccessSetup(void **state) {
samconfConfig_t *root = NULL;
samconfConfigNew(&root);
root->key = strdup("node");
root->type = SAMCONF_CONFIG_VALUE_STRING;
root->value.string = strdup("test");
*state = root;
return 0;
}

int samconfTestSamconfConfigSetIntSuccessTeardown(UNUSED void **state) {
int samconfTestSamconfConfigSetIntSuccessTeardown(void **state) {
samconfConfig_t *root = *state;
samconfConfigDelete(root);
return 0;
}

void samconfTestSamconfConfigSetIntSuccess(UNUSED void **state) {
void samconfTestSamconfConfigSetIntSuccess(void **state) {
samconfConfig_t *root = *state;
int64_t testValue[] = {0x7F102B892386AF1F, INT64_MAX, 0, INT64_MIN};

samconfConfigStatusE_t status = SAMCONF_CONFIG_ERROR;

samconfConfig_t root = {
.parent = NULL,
.key = "node",
.type = SAMCONF_CONFIG_VALUE_STRING,
.value.string = "test",
.children = NULL,
.childCount = 0,
};

TEST("samconfConfigSetInt");
SHOULD("%s", "return SAMCONF_CONFIG_OK since given integer value is set");

for (size_t i = 0; i < ARRAY_SIZE(testValue); i++) {
status = samconfConfigSetInt(&root, testValue[i]);
status = samconfConfigSetInt(root, testValue[i]);
assert_int_equal(status, SAMCONF_CONFIG_OK);
assert_int_equal(root.type, SAMCONF_CONFIG_VALUE_INT);
assert_int_equal(root.value.integer, testValue[i]);
assert_int_equal(root->type, SAMCONF_CONFIG_VALUE_INT);
assert_int_equal(root->value.integer, testValue[i]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,39 @@
#include <float.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>

#include "samconfConfigSetReal_utest.h"

int samconfTestSamconfConfigSetRealSuccessSetup(UNUSED void **state) {
int samconfTestSamconfConfigSetRealSuccessSetup(void **state) {
samconfConfig_t *root = NULL;
samconfConfigNew(&root);
root->key = strdup("node");
root->type = SAMCONF_CONFIG_VALUE_STRING;
root->value.string = strdup("test");
*state = root;
return 0;
}

int samconfTestSamconfConfigSetRealSuccessTeardown(UNUSED void **state) {
int samconfTestSamconfConfigSetRealSuccessTeardown(void **state) {
samconfConfig_t *root = *state;
samconfConfigDelete(root);
return 0;
}

void samconfTestSamconfConfigSetRealSuccess(UNUSED void **state) {
void samconfTestSamconfConfigSetRealSuccess(void **state) {
samconfConfig_t *root = *state;
double testValue[] = {6.2898, DBL_MAX, DBL_MIN, 0.0, 3.143};

samconfConfigStatusE_t status = SAMCONF_CONFIG_ERROR;

samconfConfig_t root = {
.parent = NULL,
.key = "node",
.type = SAMCONF_CONFIG_VALUE_STRING,
.value.string = "test",
.children = NULL,
.childCount = 0,
};

TEST("samconfConfigSetReal");
SHOULD("%s", "return SAMCONF_CONFIG_OK since given real value is set");

for (size_t i = 0; i < ARRAY_SIZE(testValue); i++) {
status = samconfConfigSetReal(&root, testValue[i]);
status = samconfConfigSetReal(root, testValue[i]);
assert_int_equal(status, SAMCONF_CONFIG_OK);
assert_int_equal(root.type, SAMCONF_CONFIG_VALUE_REAL);
assert_float_equal(root.value.real, testValue[i], 0.0);
assert_int_equal(root->type, SAMCONF_CONFIG_VALUE_REAL);
assert_float_equal(root->value.real, testValue[i], 0.0);
}
}