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