Mercurial > flash_v2
annotate packages/language/c/libc/current/tests/time/strftime.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 | 435cced73e2f |
| rev | line source |
|---|---|
| 2 | 1 //================================================================= |
| 2 // | |
| 3 // strftime.c | |
| 4 // | |
| 5 // Testcase for C library strftime() 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 strftime() 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 static void | |
| 78 test( CYG_ADDRWORD data ) | |
| 79 { | |
| 80 struct tm tm1; | |
| 81 char s[1000]; | |
| 82 size_t size; | |
| 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 size = strftime(s, 1000, "", &tm1); | |
| 95 CYG_TEST_PASS_FAIL((size==0) && (*s=='\0'), "strftime test #1"); | |
| 96 | |
| 97 size = strftime(s, 1000, "%a", &tm1); | |
| 98 CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Thu"), "strftime test #2"); | |
| 99 | |
| 100 size = strftime(s, 1000, "%A", &tm1); | |
| 101 CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "Thursday"), | |
| 102 "strftime test #3"); | |
| 103 | |
| 104 size = strftime(s, 1000, "%b", &tm1); | |
| 105 CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Feb"), | |
| 106 "strftime test #4"); | |
| 107 | |
| 108 size = strftime(s, 1000, "%B", &tm1); | |
| 109 CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "February"), | |
| 110 "strftime test #5"); | |
| 111 | |
| 112 size = strftime(s, 1000, "%d", &tm1); | |
| 113 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "21"), | |
| 114 "strftime test #6"); | |
| 115 | |
| 116 size = strftime(s, 1000, "%H", &tm1); | |
| 117 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "20"), | |
| 118 "strftime test #7"); | |
| 119 | |
| 120 size = strftime(s, 1000, "%I", &tm1); | |
| 121 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "09"), | |
| 122 "strftime test #8"); | |
| 123 | |
| 124 size = strftime(s, 1000, "%j", &tm1); | |
| 125 CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "051"), | |
| 126 "strftime test #9"); | |
| 127 | |
| 128 size = strftime(s, 1000, "%m", &tm1); | |
| 129 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "01"), | |
| 130 "strftime test #10"); | |
| 131 | |
| 132 size = strftime(s, 1000, "%M", &tm1); | |
| 133 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "23"), | |
| 134 "strftime test #11"); | |
| 135 | |
| 136 size = strftime(s, 1000, "%p", &tm1); | |
| 137 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "pm"), | |
| 138 "strftime test #12"); | |
| 139 | |
| 140 size = strftime(s, 1000, "%S", &tm1); | |
| 141 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "04"), | |
| 142 "strftime test #13"); | |
| 143 | |
| 144 size = strftime(s, 1000, "%U", &tm1); | |
| 145 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"), | |
| 146 "strftime test #14"); | |
| 147 | |
| 148 size = strftime(s, 1000, "%w", &tm1); | |
| 149 CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "4"), | |
| 150 "strftime test #15"); | |
| 151 | |
| 152 size = strftime(s, 1000, "%W", &tm1); | |
| 153 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"), | |
| 154 "strftime test #16"); | |
| 155 | |
| 156 size = strftime(s, 1000, "%y", &tm1); | |
| 157 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "74"), | |
| 158 "strftime test #17"); | |
| 159 | |
| 160 size = strftime(s, 1000, "%Y", &tm1); | |
| 161 CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"), | |
| 162 "strftime test #18"); | |
| 163 | |
| 164 size = strftime(s, 1000, "%%", &tm1); | |
| 165 CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "%"), | |
| 166 "strftime test #19"); | |
| 167 | |
| 168 size = strftime(s, 5, "%Y", &tm1); | |
| 169 CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"), | |
| 170 "strftime test #20"); | |
| 171 | |
| 172 size = strftime(s, 4, "%Y", &tm1); | |
| 173 CYG_TEST_PASS_FAIL((size==0), "strftime test #21"); | |
| 174 | |
| 175 | |
| 176 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | |
| 177 "strftime() function"); | |
| 178 } // test() | |
| 179 | |
| 180 | |
| 181 int | |
| 182 main(int argc, char *argv[]) | |
| 183 { | |
| 184 CYG_TEST_INIT(); | |
| 185 | |
| 186 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 187 "strftime() function"); | |
| 188 | |
| 189 START_TEST( test ); | |
| 190 | |
| 191 CYG_TEST_NA("Testing is not applicable to this configuration"); | |
| 192 | |
| 193 } // main() | |
| 194 | |
| 195 // EOF strftime.c |
