]>
git.saurik.com Git - apple/libc.git/blob - tests/strptime.c
b34fa1a863097310fce5bb51fe5bd1a0875eec39
3 #include <darwintest.h>
4 #include <darwintest_utils.h>
6 T_DECL(strptime_PR_27004626
, "strptime() should fail when a %t doesn't match anything")
9 T_ASSERT_NULL(strptime("there'snotemplateforthis", "%t", &tm
), NULL
);
12 T_DECL(strptime_PR_29381762
, "strptime() sets the tm_wday field incorrectly")
15 struct tm t
= *localtime(&epoch
);
17 T_LOG("2015-01-01 12:00:00 -> Thursday");
18 (void)strptime("2015-01-01 12:00:00", "%F %T", &t
);
19 T_EXPECT_EQ(t
.tm_wday
, 4, NULL
);
21 T_LOG("2015-04-19 12:00:00 -> Sunday");
22 (void)strptime("2015-04-19 12:00:00", "%F %T", &t
);
23 T_EXPECT_EQ(t
.tm_wday
, 0, NULL
);
25 T_LOG("2009-03-03 12:00:00 -> Tuesday");
26 (void)strptime("2009-03-03 12:00:00", "%F %T", &t
);
27 T_EXPECT_EQ(t
.tm_wday
, 2, NULL
);
29 T_LOG("1990-02-15 12:00:00 -> Thursday");
30 (void)strptime("1990-02-15 12:00:00", "%F %T", &t
);
31 T_EXPECT_EQ(t
.tm_wday
, 4, NULL
);
33 T_LOG("1993-03-02 12:00:00 -> Sunday");
34 (void)strptime("1993-03-02 12:00:00", "%F %T", &t
);
35 T_EXPECT_EQ(t
.tm_wday
, 2, NULL
);
39 T_DECL(strptime_PR_42669744_1
, "strptime() with %%C, %%y and %%Y")
46 result
= strptime("201", "%C%y", &tm
);
47 T_QUIET
; T_EXPECT_NOTNULL(result
, "201, %%C%%y");
48 T_EXPECT_EQ(tm
.tm_year
, 2001 - 1900, NULL
);
50 T_LOG("2010, %%C%%y");
51 result
= strptime("2010", "%C%y", &tm
);
52 T_QUIET
; T_EXPECT_NOTNULL(result
, "2010, %%C%%y");
53 T_EXPECT_EQ(tm
.tm_year
, 2010 - 1900, NULL
);
55 T_LOG("20010, %%C%%y");
56 result
= strptime("20010", "%C%y", &tm
);
57 T_QUIET
; T_EXPECT_NOTNULL(result
, "20010, %%C%%y");
58 T_EXPECT_EQ(tm
.tm_year
, 2001 - 1900, NULL
);
60 T_LOG("+2010, %%C%%y");
61 result
= strptime("+2010", "%C%y", &tm
);
62 T_QUIET
; T_EXPECT_NOTNULL(result
, "2010, %%C%%y");
63 T_EXPECT_EQ(tm
.tm_year
, 201 - 1900, NULL
);
65 T_LOG("-20100, %%C%%y");
66 result
= strptime("-20100", "%C%y", &tm
);
67 T_QUIET
; T_EXPECT_NOTNULL(result
, "-20100, %%C%%y");
68 T_EXPECT_EQ(tm
.tm_year
, -200 + 1 - 1900, NULL
);
70 T_LOG("-2-1, %%C%%y");
71 result
= strptime("-2-1", "%C%y", &tm
);
72 T_QUIET
; T_EXPECT_NOTNULL(result
, "-2-1, %%C%%y");
73 T_EXPECT_EQ(tm
.tm_year
, -200 - 1 - 1900, NULL
);
75 T_LOG("-2+1, %%C%%y");
76 result
= strptime("-2+1", "%C%y", &tm
);
77 T_QUIET
; T_EXPECT_NOTNULL(result
, "-2+1, %%C%%y");
78 T_EXPECT_EQ(tm
.tm_year
, -200 + 1 - 1900, NULL
);
82 result
= strptime("201", "%Y", &tm
);
83 T_QUIET
; T_EXPECT_NOTNULL(result
, "201, %%Y");
84 T_EXPECT_EQ(tm
.tm_year
, 201 - 1900, NULL
);
87 result
= strptime("2001", "%Y", &tm
);
88 T_QUIET
; T_EXPECT_NOTNULL(result
, "2001, %%Y");
89 T_EXPECT_EQ(tm
.tm_year
, 2001 - 1900, NULL
);
92 result
= strptime("20010", "%Y", &tm
);
93 T_QUIET
; T_EXPECT_NOTNULL(result
, "20010, %%Y");
94 T_EXPECT_EQ(tm
.tm_year
, 2001 - 1900, NULL
);
97 result
= strptime("+2010", "%Y", &tm
);
98 T_QUIET
; T_EXPECT_NOTNULL(result
, "+2010, %%Y");
99 T_EXPECT_EQ(tm
.tm_year
, 201 - 1900, NULL
);
102 result
= strptime("-2010", "%Y", &tm
);
103 T_QUIET
; T_EXPECT_NOTNULL(result
, "-2010, %%Y");
104 T_EXPECT_EQ(tm
.tm_year
, -201 - 1900, NULL
);