From 79c17deb218f683ba127d358fcee904eb6a8d7fd Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 29 Dec 2022 06:32:35 +0100 Subject: [PATCH] Test: Logging - C99 --- test/test_log.c | 82 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/test/test_log.c b/test/test_log.c index a7bca23..3629b60 100644 --- a/test/test_log.c +++ b/test/test_log.c @@ -2,16 +2,84 @@ #include #include #include -#include "../src/valog.h" +#include "../src/log.h" +#include +// ORCA LOG C usage int main() { - // C usage - ORCA_LOG_ERR(); - ORCA_LOG_ERR("HELLO"); - char *str = strdup("fds"); - ORCA_LOG_ERR("string: %s", str); + // Test Levels + { + ORCA_LOG_ERR("SHOULD NOT SEE THIS"); - free(str); + orca_log_set_level(ORCA_LOG_LEVEL_ALL); + ORCA_LOG_ERR(); + ORCA_LOG_WARN(); + ORCA_LOG_INFO(); + + orca_log_set_level(ORCA_LOG_LEVEL_ERROR); + ORCA_LOG_ERR(); + ORCA_LOG_WARN("SHOULD NOT SEE THIS"); + ORCA_LOG_INFO("SHOULD NOT SEE THIS"); + } + + // BASIC USAGE MACRO + { + orca_log_set_level(ORCA_LOG_LEVEL_INFO); + // no message + ORCA_LOG_INFO(); + + // simple string literal + ORCA_LOG_INFO("HELLO"); + + // sprintf style formatting + char *str2 = strdup("best"); + ORCA_LOG_INFO("The %s number is %i", str2, 23); + free(str2); + + // does not compile, 1st must be literal fmt string + // ORCA_LOG_WARN(str1); + } + + // BASIC USAGE FUNC + { + orca_log_set_level(ORCA_LOG_LEVEL_INFO); + // literal + orca_log("Literal RAW"); + + // c-string + char *str2 = strdup("c-string RAW"); + orca_log(str2); + free(str2); + + orca_log_h1("HEADING 1"); + orca_log_h2("HEADING 2"); + orca_log_h3("HEADING 3"); + } + + // Colors functions only + { + orca_log_h1("Colors functions only"); + orca_log("DEFAULT COLOR"); + orca_log_set_color(ORCA_LOG_COLOR_GREEN); + orca_log("DEFAULT COLOR AFTER SET GREEN"); + orca_log_set_color(ORCA_LOG_COLOR_YELLOW); + strdup("YELLOW ONE OFF"); + orca_log(strdup("YELLOW ONE OFF")); + orca_log_set_color(ORCA_LOG_COLOR_RESET); + orca_log("COLOR RESET"); + } + + // Colors using Macros + { + orca_log_h1("Colors using Macros"); + orca_log("DEFAULT COLOR"); + orca_log_set_color(ORCA_LOG_COLOR_GREEN); + ORCA_LOG_ERR("DEFAULT COLOR AFTER SET GREEN"); + orca_log_set_color(ORCA_LOG_COLOR_YELLOW); + ORCA_LOG_ERR("YELLOW ONE OFF"); + orca_log_set_color(ORCA_LOG_COLOR_RESET); + ORCA_LOG_ERR("COLOR RESET"); + } }