mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/result_output: Add initial structure check
This commit is contained in:
parent
d17829311c
commit
2c2be2636d
3
sys/test_utils/result_output/check/Makefile
Normal file
3
sys/test_utils/result_output/check/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
MODULE = test_utils_result_output_check
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
13
sys/test_utils/result_output/check/doc.txt
Normal file
13
sys/test_utils/result_output/check/doc.txt
Normal file
@ -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 <kevin.weiss@haw-hamburg.de>
|
||||
* @}
|
||||
*/
|
126
sys/test_utils/result_output/check/result_output_check.c
Normal file
126
sys/test_utils/result_output/check/result_output_check.c
Normal file
@ -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 <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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--;
|
||||
}
|
45
sys/test_utils/result_output/check/result_output_types.h
Normal file
45
sys/test_utils/result_output/check/result_output_types.h
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user