sscanf_tc.c 626 B

123456789101112131415161718192021222324252627282930
  1. #include <stdio.h>
  2. #include <string.h>
  3. static int sscanf_entry(void)
  4. {
  5. int day, year;
  6. char weekday[20], month[20], dtm[100];
  7. strcpy( dtm, "Friday January 1 2021" );
  8. sscanf( dtm, "%s %s %d %d", weekday, month, &day, &year );
  9. if(strcmp(month,"January") || strcmp(weekday,"Friday")
  10. || (year != 2021) ||(day != 1))
  11. {
  12. return -1;
  13. }
  14. return 0;
  15. }
  16. #include <utest.h>
  17. static void test_sscanf(void)
  18. {
  19. uassert_int_equal(sscanf_entry(), 0);
  20. }
  21. static void testcase(void)
  22. {
  23. UTEST_UNIT_RUN(test_sscanf);
  24. }
  25. UTEST_TC_EXPORT(testcase, "posix.stdio_h.sscanf.c", RT_NULL, RT_NULL, 10);