Bemanitools v5.26 release
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
testexes += cconfig-test
|
||||
|
||||
srcdir_cconfig-test := src/test/cconfig
|
||||
|
||||
libs_cconfig-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_cconfig-test := \
|
||||
cconfig-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += cconfig-util-test
|
||||
|
||||
srcdir_cconfig-util-test := src/test/cconfig
|
||||
|
||||
libs_cconfig-util-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_cconfig-util-test := \
|
||||
cconfig-util-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += cconfig-cmd-test
|
||||
|
||||
srcdir_cconfig-cmd-test := src/test/cconfig
|
||||
|
||||
libs_cconfig-cmd-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_cconfig-cmd-test := \
|
||||
cconfig-cmd-test.c \
|
||||
|
||||
################################################################################
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "cconfig/cmd.h"
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_cmd()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int argc = 6;
|
||||
char* argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"};
|
||||
char str[32];
|
||||
int32_t val;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_true(cconfig_cmd_parse(config, "-P", argc, argv, true));
|
||||
|
||||
check_int_eq(config->nentries, 2);
|
||||
|
||||
check_bool_true(cconfig_util_get_str(config, "test", str, sizeof(str), "1"));
|
||||
check_str_eq(str, "aaa");
|
||||
|
||||
check_bool_true(cconfig_util_get_int(config, "test2", &val, 0));
|
||||
check_int_eq(val, 123);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_cmd_absent_entries()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int argc = 6;
|
||||
char* argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"};
|
||||
char str[32];
|
||||
int32_t val;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set2(config, "test", "aaa");
|
||||
|
||||
check_bool_true(cconfig_cmd_parse(config, "-P", argc, argv, false));
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
|
||||
check_bool_true(cconfig_util_get_str(config, "test", str, sizeof(str), "1"));
|
||||
check_str_eq(str, "aaa");
|
||||
|
||||
check_bool_false(cconfig_util_get_int(config, "test2", &val, 0));
|
||||
check_int_eq(val, 0);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("cconfig-cmd")
|
||||
TEST_MODULE_TEST(test_cmd)
|
||||
TEST_MODULE_TEST(test_cmd_absent_entries)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,156 @@
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
struct cconfig* config;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_empty()
|
||||
{
|
||||
struct cconfig* config;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_null(cconfig_get(config, "test"));
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_one_elem()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set(config, "test", "123", "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "123");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
entry = cconfig_get(config, "test");
|
||||
|
||||
check_str_eq(entry->key, "test");
|
||||
check_str_eq(entry->value, "123");
|
||||
check_str_eq(entry->desc, "desc");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_one_elem2()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set2(config, "test", "123");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "123");
|
||||
check_str_eq(config->entries[0].desc, "");
|
||||
|
||||
entry = cconfig_get(config, "test");
|
||||
|
||||
check_str_eq(entry->key, "test");
|
||||
check_str_eq(entry->value, "123");
|
||||
check_str_eq(entry->desc, "");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_same_elem()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set(config, "test", "123", "desc");
|
||||
cconfig_set(config, "test", "12345", "aaa");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "12345");
|
||||
check_str_eq(config->entries[0].desc, "aaa");
|
||||
|
||||
entry = cconfig_get(config, "test");
|
||||
|
||||
check_str_eq(entry->key, "test");
|
||||
check_str_eq(entry->value, "12345");
|
||||
check_str_eq(entry->desc, "aaa");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_many_elem()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
char key[16];
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sprintf(key, "%d", i);
|
||||
cconfig_set(config, key, "123", "desc");
|
||||
}
|
||||
|
||||
check_int_eq(config->nentries, 1000);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sprintf(key, "%d", i);
|
||||
check_str_eq(config->entries[i].key, key);
|
||||
check_str_eq(config->entries[i].value, "123");
|
||||
check_str_eq(config->entries[i].desc, "desc");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sprintf(key, "%d", i);
|
||||
entry = cconfig_get(config, key);
|
||||
|
||||
check_str_eq(entry->key, key);
|
||||
check_str_eq(entry->value, "123");
|
||||
check_str_eq(entry->desc, "desc");
|
||||
}
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("cconfig")
|
||||
TEST_MODULE_TEST(test_init)
|
||||
TEST_MODULE_TEST(test_get_empty)
|
||||
TEST_MODULE_TEST(test_set_get_one_elem)
|
||||
TEST_MODULE_TEST(test_set_get_one_elem2)
|
||||
TEST_MODULE_TEST(test_set_get_same_elem)
|
||||
TEST_MODULE_TEST(test_set_get_many_elem)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,220 @@
|
||||
#include "cconfig/cconfig-util.h"
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_set_get_int()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int32_t value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_int(config, "test", 12345, "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "12345");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_int(config, "test", &value, 0));
|
||||
check_int_eq(value, 12345);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_int_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int32_t value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_int(config, "test", &value, 123));
|
||||
check_int_eq(value, 123);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_float()
|
||||
{
|
||||
struct cconfig* config;
|
||||
float value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_float(config, "test", 100.5f, "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_float(config, "test", &value, 0));
|
||||
check_float_eq(value, 100.5f, 0.1f);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_float_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
float value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_float(config, "test", &value, 115.9f));
|
||||
check_float_eq(value, 115.9f, 0.1f);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_bool()
|
||||
{
|
||||
struct cconfig* config;
|
||||
bool value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_bool(config, "test", true, "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_bool(config, "test", &value, 0));
|
||||
check_bool_true(value);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_bool_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
bool value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_bool(config, "test", &value, true));
|
||||
check_bool_true(value);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_str()
|
||||
{
|
||||
struct cconfig* config;
|
||||
char value[1024];
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_str(config, "test", "hello world", "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_str(config, "test", value, sizeof(value),
|
||||
"world hello"));
|
||||
check_str_eq(value, "hello world");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_str_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
char value[1024];
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_str(config, "test", value, sizeof(value),
|
||||
"world hello"));
|
||||
check_str_eq(value, "world hello");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_data()
|
||||
{
|
||||
struct cconfig* config;
|
||||
uint8_t value[1024];
|
||||
uint8_t value2[1024];
|
||||
uint8_t value_default[] = {0x00};
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
for (int i = 0; i < sizeof(value); i++) {
|
||||
value[i] = (uint8_t) i;
|
||||
}
|
||||
|
||||
cconfig_util_set_data(config, "test", value, sizeof(value), "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_data(config, "test", value2, sizeof(value2),
|
||||
value_default));
|
||||
check_data_eq(value2, sizeof(value2), value, sizeof(value));
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_data_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
uint8_t value[1024];
|
||||
uint8_t value_default[] = {0x01};
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_data(config, "test", value, sizeof(value),
|
||||
value_default));
|
||||
check_data_eq(value, 1, value_default, sizeof(value_default));
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("cconfig-util")
|
||||
TEST_MODULE_TEST(test_set_get_int)
|
||||
TEST_MODULE_TEST(test_get_int_na)
|
||||
TEST_MODULE_TEST(test_set_get_float)
|
||||
TEST_MODULE_TEST(test_get_float_na)
|
||||
TEST_MODULE_TEST(test_set_get_bool)
|
||||
TEST_MODULE_TEST(test_get_bool_na)
|
||||
TEST_MODULE_TEST(test_set_get_str)
|
||||
TEST_MODULE_TEST(test_get_str_na)
|
||||
TEST_MODULE_TEST(test_set_get_data)
|
||||
TEST_MODULE_TEST(test_get_data_na)
|
||||
TEST_MODULE_END()
|
||||
Reference in New Issue
Block a user