Update tests base
This commit is contained in:
+23
-1
@@ -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;
|
||||
}
|
||||
|
||||
+48
-29
@@ -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("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user