|
2
|
1 //================================================================= |
|
|
2 // |
|
|
3 // mktime.c |
|
|
4 // |
|
|
5 // Testcase for C library mktime() function |
|
|
6 // |
|
|
7 //================================================================= |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): jlarmour |
|
|
33 // Contributors: jlarmour |
|
|
34 // Date: 1999-03-05 |
|
|
35 // Description: Contains testcode for C library mktime() function |
|
|
36 // |
|
|
37 // |
|
|
38 //####DESCRIPTIONEND#### |
|
|
39 |
|
|
40 // CONFIGURATION |
|
|
41 |
|
|
42 #include <pkgconf/libc.h> // C library configuration |
|
|
43 |
|
|
44 // INCLUDES |
|
|
45 |
|
|
46 #include <time.h> |
|
|
47 #include <cyg/infra/testcase.h> |
|
|
48 #include <sys/cstartup.h> // C library initialisation |
|
|
49 |
|
|
50 // HOW TO START TESTS |
|
|
51 |
|
|
52 # define START_TEST( test ) test(0) |
|
|
53 |
|
|
54 // FUNCTIONS |
|
|
55 |
|
|
56 |
|
|
57 externC void |
|
|
58 cyg_package_start( void ) |
|
|
59 { |
|
|
60 cyg_iso_c_start(); |
|
|
61 } // cyg_package_start() |
|
|
62 |
|
|
63 |
|
|
64 static int |
|
|
65 cmp_structtm(struct tm *tm1, struct tm *tm2) |
|
|
66 { |
|
|
67 if ((tm1->tm_sec != tm2->tm_sec) || |
|
|
68 (tm1->tm_min != tm2->tm_min) || |
|
|
69 (tm1->tm_hour != tm2->tm_hour) || |
|
|
70 (tm1->tm_mday != tm2->tm_mday) || |
|
|
71 (tm1->tm_mon != tm2->tm_mon) || |
|
|
72 (tm1->tm_year != tm2->tm_year) || |
|
|
73 (tm1->tm_wday != tm2->tm_wday) || |
|
|
74 (tm1->tm_yday != tm2->tm_yday) || |
|
|
75 (tm1->tm_isdst != tm2->tm_isdst)) |
|
|
76 return 1; |
|
|
77 else |
|
|
78 return 0; |
|
|
79 } |
|
|
80 |
|
|
81 static void |
|
|
82 test( CYG_ADDRWORD data ) |
|
|
83 { |
|
|
84 struct tm tm1, tm2; |
|
|
85 time_t t; |
|
|
86 |
|
|
87 // make this predictable - independent of the user option |
|
|
88 cyg_libc_time_setzoneoffsets(0, 3600); |
|
|
89 |
|
|
90 tm1.tm_sec = 4; |
|
|
91 tm1.tm_min = 23; |
|
|
92 tm1.tm_hour = 20; |
|
|
93 tm1.tm_mday = 21; |
|
|
94 tm1.tm_mon = 1; |
|
|
95 tm1.tm_year = 74; |
|
|
96 tm1.tm_isdst = 0; |
|
|
97 |
|
|
98 tm2 = tm1; |
|
|
99 tm2.tm_wday = 4; |
|
|
100 tm2.tm_yday = 51; |
|
|
101 |
|
|
102 t = mktime(&tm1); |
|
|
103 CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #1"); |
|
|
104 CYG_TEST_PASS_FAIL(t == 130710184, "mktime return test #1"); |
|
|
105 |
|
|
106 tm1.tm_sec = 61; |
|
|
107 tm1.tm_min = 20; |
|
|
108 tm1.tm_hour = 4; |
|
|
109 tm1.tm_mday = 5; |
|
|
110 tm1.tm_mon = 0; |
|
|
111 tm1.tm_year = 99; |
|
|
112 tm1.tm_isdst = 0; |
|
|
113 |
|
|
114 tm2 = tm1; |
|
|
115 tm2.tm_sec=1; |
|
|
116 tm2.tm_min = 21; |
|
|
117 tm2.tm_wday = 2; |
|
|
118 tm2.tm_yday = 4; |
|
|
119 |
|
|
120 t = mktime(&tm1); |
|
|
121 CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #2"); |
|
|
122 CYG_TEST_PASS_FAIL(t == 915510061, "mktime return test #2"); |
|
|
123 |
|
|
124 tm1.tm_sec = 54; |
|
|
125 tm1.tm_min = 24; |
|
|
126 tm1.tm_hour = 1; |
|
|
127 tm1.tm_mday = 1; |
|
|
128 tm1.tm_mon = 0; |
|
|
129 tm1.tm_year = 100; |
|
|
130 tm1.tm_isdst = 0; |
|
|
131 |
|
|
132 tm2 = tm1; |
|
|
133 tm2.tm_wday = 6; |
|
|
134 tm2.tm_yday = 0; |
|
|
135 |
|
|
136 t = mktime(&tm1); |
|
|
137 CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime Y2K test #3"); |
|
|
138 CYG_TEST_PASS_FAIL(t == 946689894, "mktime Y2K return test #3"); |
|
|
139 |
|
|
140 tm1.tm_sec = 54; |
|
|
141 tm1.tm_min = 24; |
|
|
142 tm1.tm_hour = 23; |
|
|
143 tm1.tm_mday = 31; |
|
|
144 tm1.tm_mon = 4; |
|
|
145 tm1.tm_year = 66; |
|
|
146 tm1.tm_isdst = 1; |
|
|
147 |
|
|
148 tm2 = tm1; |
|
|
149 tm2.tm_wday = 2; |
|
|
150 tm2.tm_yday = 150; |
|
|
151 |
|
|
152 t = mktime(&tm1); |
|
|
153 CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #4"); |
|
|
154 CYG_TEST_PASS_FAIL(t == -113186106, "mktime return test #4"); |
|
|
155 |
|
|
156 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " |
|
|
157 "mktime() function"); |
|
|
158 } // test() |
|
|
159 |
|
|
160 |
|
|
161 int |
|
|
162 main(int argc, char *argv[]) |
|
|
163 { |
|
|
164 CYG_TEST_INIT(); |
|
|
165 |
|
|
166 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " |
|
|
167 "mktime() function"); |
|
|
168 |
|
|
169 START_TEST( test ); |
|
|
170 |
|
|
171 CYG_TEST_NA("Testing is not applicable to this configuration"); |
|
|
172 |
|
|
173 } // main() |
|
|
174 |
|
|
175 // EOF mktime.c |