Update tests base

This commit is contained in:
Gregory Lirent 2022-06-09 11:39:19 +03:00
parent 3d8ecee1e5
commit c6cc575759
5 changed files with 101 additions and 34 deletions

View File

@ -35,6 +35,12 @@ OBJECTS_LIST := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix .
OBJECTS_MAP := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_MAP))
OBJECTS_SET := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_SET))
OBJECTS_STRING := $(OBJECTS_STRING) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/string/src/,string-))
OBJECTS_ARRAY := $(OBJECTS_ARRAY) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/array/src/,array-))
OBJECTS_LIST := $(OBJECTS_LIST) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/list/src/,list-))
OBJECTS_MAP := $(OBJECTS_MAP) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/map/src/,map-))
OBJECTS_SET := $(OBJECTS_SET) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/set/src/,set-))
########################################################################################################################
tests: modules
@ -50,6 +56,17 @@ tests: $(addprefix $(BUILD_PATH)/set-,$(notdir $(basename $(wildcard ./src/set/*
$(BUILD_PATH)/obj/%.o: ./src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/array-%.o: ./src/array/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/string-%.o: ./src/string/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/list-%.o: ./src/list/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/map-%.o: ./src/map/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/set-%.o: ./src/set/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/array-%: ./src/array/%.c $(OBJECTS_ARRAY) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/string-%: ./src/string/%.c $(OBJECTS_STRING) | $(BUILD_PATH)/

View File

@ -2,10 +2,16 @@
/* Copyright © 2022 Gregory Lirent */
#include "../../include/vtype.h"
#include "../../src/__internal/vnode.h"
#ifndef LIBCDSB_TESTS_RANDOM_H
#define LIBCDSB_TESTS_RANDOM_H
typedef struct {
var_t value[1];
vtype type;
} value_t;
extern int random_init(int argc, char** argv);
extern vtype_bool random_boolean();
@ -25,4 +31,7 @@ extern vtype_int64 random_int64();
extern char random_ascii_char();
extern unsigned int random_unicode_symbol();
extern value_t random_value();
#endif /* LIBCDSB_TESTS_RANDOM_H */

View File

@ -7,10 +7,10 @@
#ifndef LIBCDSB_TESTS_TEST_H
#define LIBCDSB_TESTS_TEST_H
extern void put_separator();
extern void print_container_values_prefix(const char* name, const char* prefix);
extern void print_container_value(const ssize_t* index, const void* value, const vtype type, _Bool print_type);
extern void print_container_info(const char* name, const char* el_name, const vtype* type, ssize_t size, ssize_t nmemb);
extern void put_separator(unsigned int hpos);
extern void print_container_values_prefix(const char* name, const char* prefix, unsigned int hpos);
extern void print_container_value(const ssize_t* index, const void* value, const vtype type, _Bool print_type, unsigned int hpos);
extern void print_container_info(const char* name, const char* el_name, const vtype* type, ssize_t size, ssize_t nmemb, unsigned int hpos);
extern void test_init(int argc, char** argv);

View File

@ -11,7 +11,7 @@
static void init(unsigned int seed) {
if (!seed) seed = time(0);
printf("\e[36mRandom module initialized with seed: \e[m\e[32m%u\n\e[m", seed);
put_separator();
put_separator(0);
srand(seed);
}
@ -109,3 +109,25 @@ unsigned int random_unicode_symbol() {
case 19: return (random_uint16()%0x03d8) + 0x01f300;
}
}
value_t random_value() {
value_t v;
switch (random_uint8()%13) {
default:
case 0: v.value[0].b = random_boolean(); v.type = VTYPE_BOOLEAN; break;
case 1: v.value[0].u8 = random_uint8 (); v.type = VTYPE_UINT8; break;
case 2: v.value[0].u16 = random_uint16 (); v.type = VTYPE_UINT16; break;
case 3: v.value[0].u32 = random_uint32 (); v.type = VTYPE_UINT32; break;
case 4: v.value[0].u64 = random_uint64 (); v.type = VTYPE_UINT64; break;
case 5: v.value[0].u8 = random_int8 (); v.type = VTYPE_INT8; break;
case 6: v.value[0].u16 = random_int16 (); v.type = VTYPE_INT16; break;
case 7: v.value[0].u32 = random_int32 (); v.type = VTYPE_INT32; break;
case 8: v.value[0].u64 = random_int64 (); v.type = VTYPE_INT64; break;
case 9: v.value[0].f = random_float (); v.type = VTYPE_FLOAT; break;
case 10: v.value[0].d = random_double (); v.type = VTYPE_DOUBLE; break;
case 11: v.value[0].ld = random_ldouble(); v.type = VTYPE_LDOUBLE; break;
case 12: v.value[0].ptr = (void*)(uintptr_t)random_uint64(); v.type = VTYPE_POINTER; break;
}
return v;
}

View File

@ -1,6 +1,7 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdarg.h>
#include <string.h>
#include "../include/test.h"
#include "../include/time.h"
@ -15,25 +16,59 @@ static void test_uload() {
if (TEST_NAME) {
timer_stop(&GLOBAL_TIMER);
puts("");
put_separator();
put_separator(0);
printf("\e[36mTest \"\e[m\e[32;1m%s\e[m\e[36m\" is end.\nExecusion time: \e[m\e[32m%.6Lf sec\e[m\n", TEST_NAME, timer_value(&GLOBAL_TIMER));
put_separator();
put_separator(0);
timer_free(&GLOBAL_TIMER);
}
}
void put_separator() { puts("\e[37;2m=== === === === === === === ===\e[m"); }
void test_init(int argc, char** argv) {
timer_init(&GLOBAL_TIMER);
timer_start(&GLOBAL_TIMER);
void print_container_values_prefix(const char* name, const char* prefix) {
if (prefix) {
printf("\e[36m%s %s values:\e[m\n", name, prefix);
} else printf("\e[36m%s values:\e[m\n", name);
TEST_NAME = strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0];
put_separator(0);
printf("\e[H\e[J\e[36mTest \"\e[m\e[32;1m%s\e[m\e[36m\" is loaded\e[m\n", TEST_NAME);
put_separator(0);
random_init(argc, argv);
puts("");
}
void print_container_value(const ssize_t* index, const void* value, const vtype type, _Bool print_type) {
void hp_printf(unsigned int hpos, const char* format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
printf("\e[%dG", hpos+1);
vprintf(format, args);
va_end(args);
}
void put_separator(unsigned int hpos) {
printf("\e[%dG\e[37;2m=== === === === === === === ===\e[m\n", hpos+1);
}
void print_container_values_prefix(const char* name, const char* prefix, unsigned int hpos) {
if (prefix) {
printf("\e[%dG\e[36m%s %s values:\e[m\n", hpos+1, name, prefix);
} else {
printf("\e[%dG\e[36m%s values:\e[m\n", hpos+1, name);
}
}
void print_container_value(const ssize_t* index, const void* value, const vtype type, _Bool print_type, unsigned int hpos) {
if (index) {
printf("\e[32;1m%5ld: \e[m", *index);
} else fputs(" ", stdout);
printf("\e[%dG\e[32;1m%5ld: \e[m", hpos+1, *index);
} else {
printf("\e[%dG ", hpos+1);
}
printf("\e[31m%24s\e[m", libcdsb_vtype_stringify(value, type));
@ -44,15 +79,15 @@ void print_container_value(const ssize_t* index, const void* value, const vtype
puts("");
}
void print_container_info(const char* name, const char* el_name, const vtype* type, ssize_t size, ssize_t nmemb) {
void print_container_info(const char* name, const char* el_name, const vtype* type, ssize_t size, ssize_t nmemb, unsigned int hpos) {
if (!el_name) el_name = "elements";
if (type) {
printf("\e[36m%s initialized with type `\e[m\e[32;1m%s\e[m\e[36m`\n", name, libcdsb_vtype_name(*type));
printf("\e[%dG\e[36m%s initialized with type `\e[m\e[32;1m%s\e[m\e[36m`\n", hpos+1, name, libcdsb_vtype_name(*type));
}
if (size >= 0 || nmemb >= 0) {
printf("\e[36m%s consists of \e[m", name);
printf("\e[%dG\e[36m%s consists of \e[m", hpos+1, name);
}
if (size >= 0) {
@ -66,19 +101,3 @@ void print_container_info(const char* name, const char* el_name, const vtype* ty
printf("\e[32m%ld bytes\e[m\n", nmemb);
}
}
void test_init(int argc, char** argv) {
timer_init(&GLOBAL_TIMER);
timer_start(&GLOBAL_TIMER);
TEST_NAME = strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0];
put_separator();
printf("\e[H\e[J\e[36mTest \"\e[m\e[32;1m%s\e[m\e[36m\" is loaded\e[m\n", TEST_NAME);
put_separator();
random_init(argc, argv);
puts("");
}