xref: /aosp_15_r20/external/ltp/lib/newlib_tests/tst_safe_sscanf.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2024 Linux Test Project
4  */
5 
6 /*
7  * Basic unit test for the tst_safe_sscanf() function.
8  */
9 
10 #include "tst_test.h"
11 
check_safe_sscanf(void)12 static void check_safe_sscanf(void)
13 {
14 	int day, month, year;
15 	int nvalues = SAFE_SSCANF("14-07-2023", "%d-%d-%d", &day, &month, &year);
16 
17 	if (nvalues == 3 && day == 14 && month == 7 && year == 2023)
18 		tst_res(TPASS, "%d values parsed : %d,%d,%d", nvalues, day, month, year);
19 	else
20 		tst_res(TFAIL, "expected 3 values 14,7,2023 got: %d values %d,%d,%d", nvalues, day, month, year);
21 }
22 
23 static struct tst_test test = {
24 	.test_all = check_safe_sscanf,
25 };
26