From 2c2be2636da79003461ebd0ac460817256e7e82b Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Fri, 12 Mar 2021 16:17:12 +0100 Subject: [PATCH] sys/result_output: Add initial structure check --- sys/test_utils/result_output/check/Makefile | 3 + sys/test_utils/result_output/check/doc.txt | 13 ++ .../result_output/check/result_output_check.c | 126 ++++++++++++++++++ .../result_output/check/result_output_types.h | 45 +++++++ 4 files changed, 187 insertions(+) create mode 100644 sys/test_utils/result_output/check/Makefile create mode 100644 sys/test_utils/result_output/check/doc.txt create mode 100644 sys/test_utils/result_output/check/result_output_check.c create mode 100644 sys/test_utils/result_output/check/result_output_types.h diff --git a/sys/test_utils/result_output/check/Makefile b/sys/test_utils/result_output/check/Makefile new file mode 100644 index 0000000000..1224fbb767 --- /dev/null +++ b/sys/test_utils/result_output/check/Makefile @@ -0,0 +1,3 @@ +MODULE = test_utils_result_output_check + +include $(RIOTBASE)/Makefile.base diff --git a/sys/test_utils/result_output/check/doc.txt b/sys/test_utils/result_output/check/doc.txt new file mode 100644 index 0000000000..5666c10362 --- /dev/null +++ b/sys/test_utils/result_output/check/doc.txt @@ -0,0 +1,13 @@ +/** + * @defgroup test_utils_result_output_check Test result output structure + * @brief Enable this module to check the result structure + * @ingroup test_utils_result_output + * @{ + * + * @file + * @brief Result output assert check implementation + * + * + * @author Kevin Weiss + * @} + */ diff --git a/sys/test_utils/result_output/check/result_output_check.c b/sys/test_utils/result_output/check/result_output_check.c new file mode 100644 index 0000000000..b095929d8f --- /dev/null +++ b/sys/test_utils/result_output/check/result_output_check.c @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2021 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#include +#include +#include + +#include "test_utils/result_output.h" + +void turo_init(turo_t *ctx) +{ + ctx->idx = 0; +} + +void turo_container_open(turo_t *ctx) +{ + assert(ctx->idx == 0); + assert(ctx->idx < CONFIG_TURO_MAX_NESTING_LEVELS); + ctx->states[ctx->idx++] = TURO_STATE_CONTAINER; + ctx->states[ctx->idx] = TURO_STATE_READY; +} + +static void _val_check(turo_t *ctx) +{ + assert(ctx->idx > 0); + assert(ctx->states[ctx->idx] != TURO_STATE_DICT_OPENED); + ctx->states[ctx->idx] = TURO_STATE_READY; +} + +void turo_s32(turo_t *ctx, int32_t val) +{ + (void)val; + _val_check(ctx); +} + +void turo_u32(turo_t *ctx, uint32_t val) +{ + (void)val; + _val_check(ctx); +} + +void turo_s64(turo_t *ctx, int64_t val) +{ + (void)val; + _val_check(ctx); +} + +void turo_u64(turo_t *ctx, uint64_t val) +{ + (void)val; + _val_check(ctx); +} + +void turo_float(turo_t *ctx, float val) +{ + (void)val; + _val_check(ctx); +} + +void turo_string(turo_t *ctx, const char *str) +{ + (void)str; + _val_check(ctx); +} + +void turo_bool(turo_t *ctx, bool val) +{ + (void)val; + _val_check(ctx); +} + +void turo_dict_open(turo_t *ctx) +{ + assert(ctx->idx > 0); + assert(ctx->idx < CONFIG_TURO_MAX_NESTING_LEVELS); + ctx->states[ctx->idx++] = TURO_STATE_DICT_OPENED; + ctx->states[ctx->idx] = TURO_STATE_DICT_OPENED; +} + +void turo_dict_key(turo_t *ctx, const char *key) +{ + (void)key; + assert(ctx->idx > 0); + assert(ctx->states[ctx->idx - 1] == TURO_STATE_DICT_OPENED); + assert(ctx->states[ctx->idx] == TURO_STATE_READY || + ctx->states[ctx->idx] == TURO_STATE_DICT_OPENED); + ctx->states[ctx->idx] = TURO_STATE_READY; +} + +void turo_dict_close(turo_t *ctx) +{ + assert(ctx->idx > 0); + assert(ctx->states[ctx->idx] == TURO_STATE_READY); + assert(ctx->states[--ctx->idx] == TURO_STATE_DICT_OPENED); + ctx->states[ctx->idx] = TURO_STATE_READY; +} + +void turo_array_open(turo_t *ctx) +{ + assert(ctx->idx > 0); + assert(ctx->idx < CONFIG_TURO_MAX_NESTING_LEVELS); + ctx->states[ctx->idx++] = TURO_STATE_ARRAY_OPENED; + ctx->states[ctx->idx] = TURO_STATE_READY; +} + +void turo_array_close(turo_t *ctx) +{ + assert(ctx->idx > 0); + assert(ctx->states[ctx->idx] == TURO_STATE_READY); + assert(ctx->states[--ctx->idx] == TURO_STATE_ARRAY_OPENED); + ctx->states[ctx->idx] = TURO_STATE_READY; +} + +void turo_container_close(turo_t *ctx, int exit_status) +{ + (void)exit_status; + assert(ctx->idx == 1); + assert(ctx->states[ctx->idx] == TURO_STATE_READY); + assert(ctx->states[0] == TURO_STATE_CONTAINER); + ctx->idx--; +} diff --git a/sys/test_utils/result_output/check/result_output_types.h b/sys/test_utils/result_output/check/result_output_types.h new file mode 100644 index 0000000000..601a1b52e2 --- /dev/null +++ b/sys/test_utils/result_output/check/result_output_types.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#ifndef RESULT_OUTPUT_TYPES_H +#define RESULT_OUTPUT_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef CONFIG_TURO_MAX_NESTING_LEVELS +#define CONFIG_TURO_MAX_NESTING_LEVELS 32 /**< max level of state nesting */ +#endif + +/** + * @brief States of the TURO container + * @{ + */ +typedef enum { + TURO_STATE_UNKNOWN, /**< unknown state */ + TURO_STATE_READY, /**< state ready */ + TURO_STATE_CONTAINER, /**< container open or closing */ + TURO_STATE_DICT_OPENED, /**< dictionary opened */ + TURO_STATE_ARRAY_OPENED /**< array opening */ +} turo_state_t; +/** @} */ + +/** + * @brief turo type + * @internal + */ +struct turo { + size_t idx; /**< index for states */ + turo_state_t states[CONFIG_TURO_MAX_NESTING_LEVELS]; /**< state buffer */ +}; + +#ifdef __cplusplus +} +#endif +#endif /* RESULT_OUTPUT_TYPES_H */