1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

tests: use criterions C++ allocators

This commit is contained in:
Steffen Vogel 2018-10-21 19:54:23 +01:00
parent 39320dbf56
commit d6aa1aea35
2 changed files with 26 additions and 58 deletions

View file

@ -35,7 +35,6 @@
#include <villas/pool.h>
#include <villas/io.h>
#include <villas/log.hpp>
#include <villas/formats/raw.h>
using namespace villas;
@ -44,7 +43,7 @@ extern void init_memory();
#define NUM_VALUES 10
struct param {
char *fmt;
std::basic_string<char, std::char_traits<char>, criterion::allocator<char>> fmt;
int cnt;
int bits;
};
@ -206,16 +205,7 @@ void cr_assert_eq_sample_raw(struct sample *a, struct sample *b, int flags, int
ParameterizedTestParameters(io, lowlevel)
{
for (int i = 0; i < ARRAY_LEN(params); i++) {
struct param *p = &params[i];
char *fmt = cr_malloc(strlen(p->fmt) + 1);
strcpy(fmt, p->fmt);
p->fmt = fmt;
}
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
return criterion_test_params(params);
}
ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory)
@ -251,8 +241,8 @@ ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory)
fill_sample_data(&signals, smps, p->cnt);
f = format_type_lookup(p->fmt);
cr_assert_not_null(f, "Format '%s' does not exist", p->fmt);
f = format_type_lookup(p->fmt.c_str());
cr_assert_not_null(f, "Format '%s' does not exist", p->fmt.c_str());
ret = io_init(&io, f, &signals, SAMPLE_HAS_ALL);
cr_assert_eq(ret, 0);
@ -284,17 +274,7 @@ ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory)
ParameterizedTestParameters(io, highlevel)
{
for (int i = 0; i < ARRAY_LEN(params); i++) {
struct param *p = &params[i];
char *fmt = cr_malloc(strlen(p->fmt) + 1);
strcpy(fmt, p->fmt);
p->fmt = fmt;
}
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
return criterion_test_params(params);
}
ParameterizedTest(struct param *p, io, highlevel, .init = init_memory)
@ -342,8 +322,8 @@ ParameterizedTest(struct param *p, io, highlevel, .init = init_memory)
ret = asprintf(&fn, "%s/file", dir);
cr_assert_gt(ret, 0);
f = format_type_lookup(p->fmt);
cr_assert_not_null(f, "Format '%s' does not exist", p->fmt);
f = format_type_lookup(p->fmt.c_str());
cr_assert_not_null(f, "Format '%s' does not exist", p->fmt.c_str());
ret = io_init(&io, f, &signals, SAMPLE_HAS_ALL);
cr_assert_eq(ret, 0);

View file

@ -27,9 +27,11 @@
#include <villas/utils.h>
#include <villas/config_helper.h>
using str = std::basic_string<char, std::char_traits<char>, criterion::allocator<char>>;
struct param {
const char *argv[32];
const char *json;
std::vector<str, criterion::allocator<str>> argv;
str json;
};
ParameterizedTestParameters(json, json_load_cli)
@ -37,56 +39,42 @@ ParameterizedTestParameters(json, json_load_cli)
static struct param params[] = {
// Combined long option
{
.argv = { "dummy", "--option=value", nullptr },
.argv = { "dummy", "--option=value" },
.json = "{ \"option\" : \"value\" }"
},
// Separated long option
{
.argv = { "dummy", "--option", "value", nullptr },
.argv = { "dummy", "--option", "value" },
.json = "{ \"option\" : \"value\" }"
},
// All kinds of data types
{
.argv = { "dummy", "--integer", "1", "--real", "1.1", "--bool", "true", "--null", "null", "--string", "hello world", nullptr },
.argv = { "dummy", "--integer", "1", "--real", "1.1", "--bool", "true", "--null", "null", "--string", "hello world" },
.json = "{ \"integer\" : 1, \"real\" : 1.1, \"bool\" : true, \"null\" : null, \"string\" : \"hello world\" }"
},
// Array generation
{
.argv = { "dummy", "--bool", "true", "--bool", "false", nullptr },
.argv = { "dummy", "--bool", "true", "--bool", "false" },
.json = "{ \"bool\" : [ true, false ] }"
},
// Dots in the option name generate sub objects
{
.argv = { "dummy", "--sub.option", "value", nullptr },
.argv = { "dummy", "--sub.option", "value" },
.json = "{ \"sub\" : { \"option\" : \"value\" } }"
},
// Nesting is possible
{
.argv = { "dummy", "--sub.sub.option", "value", nullptr },
.argv = { "dummy", "--sub.sub.option", "value" },
.json = "{ \"sub\" : { \"sub\" : { \"option\" : \"value\" } } }"
},
// Multiple subgroups are merged
{
.argv = { "dummy", "--sub.sub.option", "value1", "--sub.option", "value2", nullptr },
.argv = { "dummy", "--sub.sub.option", "value1", "--sub.option", "value2" },
.json = "{ \"sub\" : { \"option\" : \"value2\", \"sub\" : { \"option\" : \"value1\" } } }"
}
};
for (int i = 0; i < ARRAY_LEN(params); i++) {
struct param *p = &params[i];
char *json = cr_malloc(strlen(p->json) + 1);
strcpy(json, p->json);
p->json = json;
for (char **a = p->argv; *a; a++) {
char *argv = cr_malloc(strlen(*a) + 1);
strcpy(argv , *a);
*a = argv;
}
}
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
return criterion_test_params(params);
}
ParameterizedTest(struct param *p, json, json_load_cli)
@ -94,15 +82,15 @@ ParameterizedTest(struct param *p, json, json_load_cli)
json_error_t err;
json_t *json, *cli;
/* Calculate argc */
int argc = 0;
while (p->argv[argc])
argc++;
json = json_loads(p->json, 0, &err);
json = json_loads(p->json.c_str(), 0, &err);
cr_assert_not_null(json);
cli = json_load_cli(argc, p->argv);
auto argv = new const char*[p->argv.size() + 1];
for (int i = 0; i < p->argv.size(); i++)
argv[i] = p->argv[i].c_str();
argv[p->argv.size()] = nullptr;
cli = json_load_cli(p->argv.size(), argv);
cr_assert_not_null(cli);
//json_dumpf(json, stdout, JSON_INDENT(2)); putc('\n', stdout);