Mercurial > nand-ecoscentric
annotate packages/language/c/libc/current/tests/time/asctime.c @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 2 | 1 //================================================================= |
| 2 // | |
| 3 // asctime.c | |
| 4 // | |
| 5 // Testcase for C library asctime() 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 |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
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 |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
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 asctime() 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 my_strcmp(const char *s1, const char *s2) | |
| 67 { | |
| 68 for ( ; *s1 == *s2 ; s1++,s2++ ) | |
| 69 { | |
| 70 if ( *s1 == '\0' ) | |
| 71 break; | |
| 72 } // for | |
| 73 | |
| 74 return (*s1 - *s2); | |
| 75 } // my_strcmp() | |
| 76 | |
| 77 | |
| 78 static void | |
| 79 test( CYG_ADDRWORD data ) | |
| 80 { | |
| 81 struct tm tm1; | |
| 82 char *ret; | |
| 83 | |
| 84 tm1.tm_sec = 4; | |
| 85 tm1.tm_min = 23; | |
| 86 tm1.tm_hour = 20; | |
| 87 tm1.tm_mday = 21; | |
| 88 tm1.tm_mon = 1; | |
| 89 tm1.tm_year = 74; | |
| 90 tm1.tm_wday = 4; | |
| 91 tm1.tm_yday = 51; | |
| 92 tm1.tm_isdst = 0; | |
| 93 | |
| 94 ret = asctime(&tm1); | |
| 95 | |
| 96 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Thu Feb 21 20:23:04 1974\n"), | |
| 97 "asctime test #1"); | |
| 98 tm1.tm_sec = 3; | |
| 99 tm1.tm_min = 51; | |
| 100 tm1.tm_hour = 5; | |
| 101 tm1.tm_mday = 2; | |
| 102 tm1.tm_mon = 11; | |
| 103 tm1.tm_year = 68; | |
| 104 tm1.tm_wday = 1; | |
| 105 tm1.tm_yday = 336; | |
| 106 tm1.tm_isdst = 0; | |
| 107 | |
| 108 ret = asctime(&tm1); | |
| 109 | |
| 110 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Mon Dec 02 05:51:03 1968\n"), | |
| 111 "asctime test #2"); | |
| 112 | |
| 113 // make this predictable - independent of the user option | |
| 114 cyg_libc_time_setzoneoffsets(0, 3600); | |
| 115 | |
| 116 tm1.tm_sec = 3; | |
| 117 tm1.tm_min = 51; | |
| 118 tm1.tm_hour = 5; | |
| 119 tm1.tm_mday = 2; | |
| 120 tm1.tm_mon = 6; | |
| 121 tm1.tm_year = 68; | |
| 122 tm1.tm_wday = 2; | |
| 123 tm1.tm_yday = 183; | |
| 124 tm1.tm_isdst = 1; | |
| 125 | |
| 126 ret = asctime(&tm1); | |
| 127 | |
| 128 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Tue Jul 02 05:51:03 1968\n"), | |
| 129 "asctime test #3"); | |
| 130 | |
| 131 tm1.tm_sec = 0; | |
| 132 tm1.tm_min = 0; | |
| 133 tm1.tm_hour = 0; | |
| 134 tm1.tm_mday = 1; | |
| 135 tm1.tm_mon = 0; | |
| 136 tm1.tm_year = 0; | |
| 137 tm1.tm_wday = 1; | |
| 138 tm1.tm_yday = 0; | |
| 139 tm1.tm_isdst = 0; | |
| 140 | |
| 141 ret = asctime(&tm1); | |
| 142 | |
| 143 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Mon Jan 01 00:00:00 1900\n"), | |
| 144 "asctime test #4"); | |
| 145 | |
| 146 tm1.tm_sec = 0; | |
| 147 tm1.tm_min = 0; | |
| 148 tm1.tm_hour = 0; | |
| 149 tm1.tm_mday = 1; | |
| 150 tm1.tm_mon = 0; | |
| 151 tm1.tm_year = 100; | |
| 152 tm1.tm_wday = 6; | |
| 153 tm1.tm_yday = 0; | |
| 154 tm1.tm_isdst = 0; | |
| 155 | |
| 156 ret = asctime(&tm1); | |
| 157 | |
| 158 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Sat Jan 01 00:00:00 2000\n"), | |
| 159 "asctime Y2K test #5"); | |
| 160 | |
| 161 #ifdef CYGFUN_LIBC_TIME_POSIX | |
| 162 { | |
| 163 char ret2[100]; | |
| 164 | |
| 165 tm1.tm_sec = 3; | |
| 166 tm1.tm_min = 51; | |
| 167 tm1.tm_hour = 5; | |
| 168 tm1.tm_mday = 2; | |
| 169 tm1.tm_mon = 11; | |
| 170 tm1.tm_year = 68; | |
| 171 tm1.tm_wday = 1; | |
| 172 tm1.tm_yday = 336; | |
| 173 tm1.tm_isdst = 0; | |
| 174 | |
| 175 ret = asctime_r(&tm1, ret2); | |
| 176 | |
| 177 CYG_TEST_PASS_FAIL((ret==ret2) && | |
| 178 !my_strcmp(ret, "Mon Dec 02 05:51:03 1968\n"), | |
| 179 "asctime_r test #1"); | |
| 180 | |
| 181 } | |
| 182 #endif | |
| 183 | |
| 184 | |
| 185 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | |
| 186 "asctime() function"); | |
| 187 } // test() | |
| 188 | |
| 189 | |
| 190 int | |
| 191 main(int argc, char *argv[]) | |
| 192 { | |
| 193 CYG_TEST_INIT(); | |
| 194 | |
| 195 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 196 "asctime() function"); | |
| 197 | |
| 198 START_TEST( test ); | |
| 199 | |
| 200 CYG_TEST_NA("Testing is not applicable to this configuration"); | |
| 201 | |
| 202 } // main() | |
| 203 | |
| 204 // EOF asctime.c |
