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