From a487b64fb3419b1545454ed9c0312bf974f4bdb8 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 19 May 2021 21:45:04 +0200 Subject: [PATCH] stdlib: add a test to check size of integer and floating-point types This dictates the behavior of strtoll, strtoull, strtold mainly. --- CMakeLists.txt | 1 + include/ft/all-tests.h | 1 + src/main.c | 1 + src/stdlib/sizes.c | 22 ++++++++++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 src/stdlib/sizes.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 03d49a5..f9723d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ set(SOURCES src/inttypes/sizes.c # stdlib src/stdlib/arith.c + src/stdlib/sizes.c # string src/string/memarray.c src/string/core.c diff --git a/include/ft/all-tests.h b/include/ft/all-tests.h index d43191e..4e62cc3 100644 --- a/include/ft/all-tests.h +++ b/include/ft/all-tests.h @@ -19,6 +19,7 @@ extern ft_test ft_inttypes_functions; /* stdlib */ extern ft_test ft_stdlib_arith; +extern ft_test ft_stdlib_sizes; /* string */ extern ft_test ft_string_memset; diff --git a/src/main.c b/src/main.c index 033757d..a3f8ac5 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,7 @@ ft_list headers_libc[] = { }}, */ { "", (ft_test*[]){ &ft_stdlib_arith, + &ft_stdlib_sizes, NULL, }}, { "", (ft_test*[]){ diff --git a/src/stdlib/sizes.c b/src/stdlib/sizes.c new file mode 100644 index 0000000..b7e9a19 --- /dev/null +++ b/src/stdlib/sizes.c @@ -0,0 +1,22 @@ +#include +#include +#include + +static void _stdlib_sizes(ft_test *t) +{ + /* TODO: Use %zu once available in *printf */ + ft_log(t, "Size of types for conversion:\n\n"); + + ft_log(t, " %d float\n", (int)sizeof(float)); + ft_log(t, " %d double\n", (int)sizeof(double)); + ft_log(t, " %d long double\n", (int)sizeof(long double)); + + ft_log(t, " %d int\n", (int)sizeof(int)); + ft_log(t, " %d long int\n", (int)sizeof(long int)); + ft_log(t, " %d long long int\n", (int)sizeof(long long int)); +} + +ft_test ft_stdlib_sizes = { + .name = "Size of numeric types", + .function = _stdlib_sizes, +};