1 /*- 2 * Copyright (c) 2024 Dag-Erling Smørgrav 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #include <time.h> 8 9 #include <atf-c.h> 10 11 ATF_TC_WITHOUT_HEAD(dayofweek); 12 ATF_TC_BODY(dayofweek, tc) 13 { 14 static const struct { 15 const char *str; 16 int wday; 17 } cases[] = { 18 { "1582-12-20", 1 }, 19 { "1700-03-01", 1 }, 20 { "1752-09-14", 4 }, 21 { "1800-12-31", 3 }, 22 { "1801-01-01", 4 }, 23 { "1900-12-31", 1 }, 24 { "1901-01-01", 2 }, 25 { "2000-12-31", 0 }, 26 { "2001-01-01", 1 }, 27 { "2100-12-31", 5 }, 28 { "2101-01-01", 6 }, 29 { "2200-12-31", 3 }, 30 { "2201-01-01", 4 }, 31 { }, 32 }; 33 struct tm tm; 34 35 for (unsigned int i = 0; cases[i].str != NULL; i++) { 36 if (strptime(cases[i].str, "%Y-%m-%d", &tm) == NULL) { 37 atf_tc_fail_nonfatal("failed to parse %s", 38 cases[i].str); 39 } else if (tm.tm_wday != cases[i].wday) { 40 atf_tc_fail_nonfatal("expected %d for %s, got %d", 41 cases[i].wday, cases[i].str, tm.tm_wday); 42 } 43 } 44 } 45 46 ATF_TP_ADD_TCS(tp) 47 { 48 ATF_TP_ADD_TC(tp, dayofweek); 49 return (atf_no_error()); 50 } 51