This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit cf52652ec705dbbc45a2d3e979a1032046bf339c Author: Marco Casaroli <[email protected]> AuthorDate: Sun Nov 8 11:55:30 2026 +0100 testing/libc/scanftest: Add cases for the L modifier. With a float specifier, L stores a long double. With an integer specifier, L is the same as ll, as in GNU libc. The test had no case for either. The long double cases are built only when the compiler has a long double (CONFIG_HAVE_LONG_DOUBLE). Each value is exact or needs one rounding only, so it is equal to the constant in every long double format. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- testing/libc/scanftest/scanftest_main.c | 121 ++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/testing/libc/scanftest/scanftest_main.c b/testing/libc/scanftest/scanftest_main.c index 6c262f9a3..1e2f8c287 100644 --- a/testing/libc/scanftest/scanftest_main.c +++ b/testing/libc/scanftest/scanftest_main.c @@ -138,6 +138,17 @@ struct type_data_s } type; }; +#ifdef CONFIG_HAVE_LONG_DOUBLE +struct ldouble_data_s +{ + FAR const char *input; + FAR const char *format; /* Takes a long double and an int */ + int rvalue; + long double ldvalue; + int nvalue; +}; +#endif + /**************************************************************************** * Private Data ****************************************************************************/ @@ -1059,7 +1070,72 @@ static const struct type_data_s type_data[] = }, LL_MOD_U }, /* 25 */ + + /* The L modifier with an integer specifier is the same as ll */ + + { + " 123456789123456789", "%Ld", + { + .s = (signed long long)123456789123456789LL + }, + LL_MOD_S + }, /* 26 */ + { + "-123456789123456789", "%Li", + { + .s = (signed long long)-123456789123456789LL + }, + LL_MOD_S + }, /* 27 */ + { + "+123456789123456789", "%Lu", + { + .u = (unsigned long long)123456789123456789LL + }, + LL_MOD_U + }, /* 28 */ + { + "-123456789123456789", "%Lu", + { + .u = (unsigned long long)-123456789123456789LL + }, + LL_MOD_U + }, /* 29 */ +}; + +#ifdef CONFIG_HAVE_LONG_DOUBLE +/* Test the L modifier with the float specifiers: the whole long double is + * stored. Each value is exact or needs one rounding only. + */ + +static const struct ldouble_data_s ldouble_data[] = +{ + { + "qwerty 1.25 7", "qwerty %Lf%i", 2, 1.25L, 7 + }, /* 1 */ + { + "-3.75e2 8", "%Le%i", 2, -375.0L, 8 + }, /* 2 */ + { + "+6.103515625e-05 9", "%Lg%i", 2, 6.103515625e-05L, 9 + }, /* 3 */ + { + "0.1", "%LE%i", 1, 0.1L, 0 + }, /* 4 */ + { + "9.87654321", "%LG%i", 1, 9.87654321L, 0 + }, /* 5 */ + { + "9007199254740993", "%Lf%i", 1, 9007199254740993.0L, 0 + }, /* 6 */ + { + "123.456789", "%5Lf%i", 2, 123.4L, 56789 + }, /* 7 */ + { + "1.5 2.5 3", "%*Lf%Lf%i", 2, 2.5L, 3 + }, /* 8 */ }; +#endif /**************************************************************************** * Public Functions @@ -1481,6 +1557,51 @@ int main(int argc, FAR char *argv[]) } } +#ifdef CONFIG_HAVE_LONG_DOUBLE + /* Test the L modifier with the float specifiers. */ + + printf("\nTesting scanf()'s L modifier with float specifiers...\n"); + for (t = 0; t < nitems(ldouble_data); ++t) + { + long double ld = 0; + + n1 = 0; + ok = true; + c = sscanf(ldouble_data[t].input, ldouble_data[t].format, &ld, &n1); + if (c != ldouble_data[t].rvalue) + { + printf("Test #%u returned %d instead of %d.\n", t + 1, c, + ldouble_data[t].rvalue); + ok = false; + } + + if (ld != ldouble_data[t].ldvalue) + { + printf("Test #%u assigned %Le instead of %Le.\n", t + 1, ld, + ldouble_data[t].ldvalue); + ok = false; + } + + if (n1 != ldouble_data[t].nvalue) + { + printf("Test #%u assigned %d instead of %d,\n" + "\tto the second argument.\n", t + 1, n1, + ldouble_data[t].nvalue); + ok = false; + } + + if (ok) + { + tests_ok += 1; + printf("Test #%u PASSED.\n", t + 1); + } + else + { + tests_err += 1; + } + } +#endif + printf("Scanf tests done... OK: %d, FAILED: %d\n", tests_ok, tests_err); return OK;
