2022-06-02 21:41:06 +03:00
|
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
|
|
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
|
|
2022-06-09 11:39:19 +03:00
|
|
|
#include <stdarg.h>
|
2022-06-02 21:41:06 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
#include "../include/test.h"
|
|
|
|
|
#include "../include/time.h"
|
|
|
|
|
#include "../include/random.h"
|
|
|
|
|
|
|
|
|
|
static TIMER GLOBAL_TIMER;
|
|
|
|
|
static const char* TEST_NAME = 0;
|
|
|
|
|
|
|
|
|
|
static void test_uload() __attribute__((destructor));
|
|
|
|
|
|
|
|
|
|
static void test_uload() {
|
|
|
|
|
if (TEST_NAME) {
|
|
|
|
|
timer_stop(&GLOBAL_TIMER);
|
|
|
|
|
puts("");
|
2022-06-09 11:39:19 +03:00
|
|
|
put_separator(0);
|
2022-06-02 21:41:06 +03:00
|
|
|
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));
|
2022-06-09 11:39:19 +03:00
|
|
|
put_separator(0);
|
2022-06-02 21:41:06 +03:00
|
|
|
timer_free(&GLOBAL_TIMER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 11:39:19 +03:00
|
|
|
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(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 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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 21:41:06 +03:00
|
|
|
|
2022-06-09 11:39:19 +03:00
|
|
|
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) {
|
2022-06-06 22:07:35 +03:00
|
|
|
if (prefix) {
|
2022-06-09 11:39:19 +03:00
|
|
|
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);
|
|
|
|
|
}
|
2022-06-06 22:07:35 +03:00
|
|
|
}
|
|
|
|
|
|
2022-06-09 11:39:19 +03:00
|
|
|
void print_container_value(const ssize_t* index, const void* value, const vtype type, _Bool print_type, unsigned int hpos) {
|
2022-06-06 22:07:35 +03:00
|
|
|
if (index) {
|
2022-06-09 11:39:19 +03:00
|
|
|
printf("\e[%dG\e[32;1m%5ld: \e[m", hpos+1, *index);
|
|
|
|
|
} else {
|
|
|
|
|
printf("\e[%dG ", hpos+1);
|
|
|
|
|
}
|
2022-06-06 22:07:35 +03:00
|
|
|
|
|
|
|
|
printf("\e[31m%24s\e[m", libcdsb_vtype_stringify(value, type));
|
|
|
|
|
|
|
|
|
|
if (print_type) {
|
|
|
|
|
printf(" \e[36m(\e[m\e[32;1m%s\e[m\e[36m)\e[m", libcdsb_vtype_name(type));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puts("");
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 11:39:19 +03:00
|
|
|
void print_container_info(const char* name, const char* el_name, const vtype* type, ssize_t size, ssize_t nmemb, unsigned int hpos) {
|
2022-06-06 22:07:35 +03:00
|
|
|
if (!el_name) el_name = "elements";
|
|
|
|
|
|
|
|
|
|
if (type) {
|
2022-06-09 11:39:19 +03:00
|
|
|
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));
|
2022-06-06 22:07:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (size >= 0 || nmemb >= 0) {
|
2022-06-09 11:39:19 +03:00
|
|
|
printf("\e[%dG\e[36m%s consists of \e[m", hpos+1, name);
|
2022-06-06 22:07:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (size >= 0) {
|
|
|
|
|
printf("\e[32m%ld\e[m \e[36m%s", size, el_name);
|
|
|
|
|
|
|
|
|
|
if (nmemb >= 0) {
|
|
|
|
|
printf(" (\e[m\e[32m%ld bytes\e[m\e[36m)\e[m\n", nmemb);
|
|
|
|
|
} else puts("\e[m");
|
|
|
|
|
|
|
|
|
|
} else if (nmemb >= 0) {
|
|
|
|
|
printf("\e[32m%ld bytes\e[m\n", nmemb);
|
|
|
|
|
}
|
|
|
|
|
}
|