diff --git a/CMakeLists.txt b/CMakeLists.txt index bfdd61b..2f2bec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,9 @@ set(SOURCES src/string/memarray.c src/string/misc.c src/string/naive.c + # time + src/time/clock.c + src/time/functions.c # unistd src/unistd/files.c # fcntl @@ -70,7 +73,7 @@ target_compile_options(fxlibctest PRIVATE -Wall -Wextra -Os -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/src/=) target_link_options(fxlibctest PRIVATE -Wl,-Map=map -Wl,--print-memory-usage) target_include_directories(fxlibctest PRIVATE include/) -target_link_libraries(fxlibctest JustUI::JustUI Gint::Gint) +target_link_libraries(fxlibctest JustUI::JustUI Gint::Gint -lc Gint::Gint) if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) generate_g1a(TARGET fxlibctest OUTPUT "FxLibcT.g1a" diff --git a/include/ft/all-tests.h b/include/ft/all-tests.h index 2e8bf78..3eff9cf 100644 --- a/include/ft/all-tests.h +++ b/include/ft/all-tests.h @@ -49,6 +49,10 @@ extern ft_test ft_string_strlen; extern ft_test ft_string_naive; extern ft_test ft_string_strerror; +/* time */ +extern ft_test ft_time_clock; +extern ft_test ft_time_functions; + /* unistd */ extern ft_test ft_unistd_simple_write; extern ft_test ft_unistd_write_odd; diff --git a/src/main.c b/src/main.c index 10b2e79..3be8451 100644 --- a/src/main.c +++ b/src/main.c @@ -68,7 +68,11 @@ ft_list headers_libc[] = { &ft_string_strerror, NULL, }}, - { _("time.h", ""), NULL }, + { _("time.h", ""), (ft_test*[]){ + &ft_time_clock, + &ft_time_functions, + NULL, + }}, { _("uchar.h", ""), NULL }, { _("wchar.h", ""), NULL }, { _("wctype.h", ""), NULL }, diff --git a/src/time/clock.c b/src/time/clock.c new file mode 100644 index 0000000..f79a6fd --- /dev/null +++ b/src/time/clock.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +static void _ft_time_clock(ft_test *t) +{ + rtc_time_t rtc; + rtc_get_time(&rtc); + + static char const weekday_names[8][3] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???", + }; + int wday = (rtc.week_day >= 7) ? 7 : rtc.week_day; + ft_log(t, "RTC time: %04d-%02d-%02d (%.3s) %02d:%02d:%02d (%d t)\n", + rtc.year, rtc.month+1, rtc.month_day, weekday_names[wday], + rtc.hours, rtc.minutes, rtc.seconds, rtc.ticks); + + ft_log(t, "rtc_ticks() = %ld\n", rtc_ticks()); + + clock_t c = clock(); + ft_log(t, "clock() = %llu\n", c); + + time_t ti = time(NULL); + ft_log(t, "time() = %llu\n", ti); +} + +ft_test ft_time_clock = { + .name = "Obtaining time", + .function = _ft_time_clock, +}; diff --git a/src/time/functions.c b/src/time/functions.c new file mode 100644 index 0000000..4a4b79f --- /dev/null +++ b/src/time/functions.c @@ -0,0 +1,39 @@ +#include +#include +#include + +static void _ft_time_functions(ft_test *t) +{ + time_t t1 = 1638650741; + time_t t2 = 1573929834; + time_t t3 = 1237432983; + time_t t4 = 1839824619; + + /* gmtime() uses mktime() internally, this saves us the need to build + some struct tm's manually */ + struct tm tm1 = *gmtime(&t1); + struct tm tm2 = *gmtime(&t2); + struct tm tm3 = *gmtime(&t3); + struct tm tm4 = *gmtime(&t4); + + ft_log(t, "%llu:\n %s", t1, asctime(&tm1)); + ft_assert(t, !strcmp(asctime(&tm1), "Sat Dec 4 20:45:41 2021\n")); + ft_assert(t, mktime(&tm1) == t1); + + ft_log(t, "%llu:\n %s", t2, asctime(&tm2)); + ft_assert(t, !strcmp(asctime(&tm2), "Sat Nov 16 18:43:54 2019\n")); + ft_assert(t, mktime(&tm2) == t2); + + ft_log(t, "%llu:\n %s", t3, asctime(&tm3)); + ft_assert(t, !strcmp(asctime(&tm3), "Thu Mar 19 03:23:03 2009\n")); + ft_assert(t, mktime(&tm3) == t3); + + ft_log(t, "%llu:\n %s", t4, asctime(&tm4)); + ft_assert(t, !strcmp(asctime(&tm4), "Thu Apr 20 06:23:39 2028\n")); + ft_assert(t, mktime(&tm4) == t4); +} + +ft_test ft_time_functions = { + .name = "All time functions", + .function = _ft_time_functions, +}; diff --git a/src/widgets/fbar.c b/src/widgets/fbar.c index bb83da5..60b4cc4 100644 --- a/src/widgets/fbar.c +++ b/src/widgets/fbar.c @@ -107,6 +107,8 @@ static int block(int rx, int y, GUNUSED int h, int px, int val, int fg) #else static int block(int rx, int y, int h, int px, int val, int fg) { + if(!px) return 0; + drect(rx, y, rx+px-1, y+h-1, fg); dprint_opt(rx+px/2, y+2, C_BLACK, C_NONE, DTEXT_CENTER, DTEXT_TOP, "%d", val); diff --git a/src/widgets/flog.c b/src/widgets/flog.c index c8c3427..9566411 100644 --- a/src/widgets/flog.c +++ b/src/widgets/flog.c @@ -111,7 +111,7 @@ static void flog_poly_render(void *l0, int x, int y) { #ifdef FXCG50 if(current_line >= l->top && current_line < l->top + l->visible) - dprint_opt(x+22, current_y, C_BLACK, C_NONE, + dprint_opt(x+22, current_y, C_RGB(16,16,16), C_NONE, DTEXT_RIGHT, DTEXT_TOP, "%d", current_line+1); #endif @@ -131,10 +131,6 @@ static void flog_poly_render(void *l0, int x, int y) } if(current_line >= l->top && current_line < l->top + l->visible) { -#ifdef FXCG50 - int previous_y = current_y; - dline(x+26, previous_y, x+26, current_y-1, C_BLACK); -#endif current_y += l->font->line_height + l->line_spacing; } current_line++;