tst-strptime3.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. static int
  6. do_test (void)
  7. {
  8. int result = 0;
  9. struct tm tm;
  10. memset (&tm, 0xaa, sizeof (tm));
  11. /* Test we don't crash on uninitialized struct tm.
  12. Some fields might contain bogus values until everything
  13. needed is initialized, but we shouldn't crash. */
  14. if (strptime ("2007", "%Y", &tm) == NULL
  15. || strptime ("12", "%d", &tm) == NULL
  16. || strptime ("Feb", "%b", &tm) == NULL
  17. || strptime ("13", "%M", &tm) == NULL
  18. || strptime ("21", "%S", &tm) == NULL
  19. || strptime ("16", "%H", &tm) == NULL)
  20. {
  21. puts ("strptimes failed");
  22. result = 1;
  23. }
  24. if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
  25. || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107
  26. || tm.tm_wday != 1 || tm.tm_yday != 42)
  27. {
  28. puts ("unexpected tm content");
  29. result = 1;
  30. }
  31. if (strptime ("8", "%d", &tm) == NULL)
  32. {
  33. puts ("strptime failed");
  34. result = 1;
  35. }
  36. if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
  37. || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107
  38. || tm.tm_wday != 4 || tm.tm_yday != 38)
  39. {
  40. puts ("unexpected tm content");
  41. result = 1;
  42. }
  43. return result;
  44. }
  45. #define TEST_FUNCTION do_test ()
  46. #include "../test-skeleton.c"