1 //=================================================================
5 // Testcase for C library strftime() function
7 //=================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //=================================================================
41 //#####DESCRIPTIONBEGIN####
43 // Author(s): jlarmour
46 // Description: Contains testcode for C library strftime() function
49 //####DESCRIPTIONEND####
53 #include <pkgconf/libc_time.h> // C library configuration
58 #include <cyg/infra/testcase.h>
62 # define START_TEST( test ) test(0)
66 static int my_strcmp(const char *s1, const char *s2)
68 for ( ; *s1 == *s2 ; s1++,s2++ )
78 test( CYG_ADDRWORD data )
94 size = strftime(s, 1000, "", &tm1);
95 CYG_TEST_PASS_FAIL((size==0) && (*s=='\0'), "strftime test #1");
97 size = strftime(s, 1000, "%a", &tm1);
98 CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Thu"), "strftime test #2");
100 size = strftime(s, 1000, "%A", &tm1);
101 CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "Thursday"),
104 size = strftime(s, 1000, "%b", &tm1);
105 CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Feb"),
108 size = strftime(s, 1000, "%B", &tm1);
109 CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "February"),
112 size = strftime(s, 1000, "%d", &tm1);
113 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "21"),
116 size = strftime(s, 1000, "%H", &tm1);
117 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "20"),
120 size = strftime(s, 1000, "%I", &tm1);
121 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "08"),
124 size = strftime(s, 1000, "%j", &tm1);
125 CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "051"),
128 size = strftime(s, 1000, "%m", &tm1);
129 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "02"),
130 "strftime test #10");
132 size = strftime(s, 1000, "%M", &tm1);
133 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "23"),
134 "strftime test #11");
136 size = strftime(s, 1000, "%p", &tm1);
137 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "pm"),
138 "strftime test #12");
140 size = strftime(s, 1000, "%S", &tm1);
141 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "04"),
142 "strftime test #13");
144 size = strftime(s, 1000, "%U", &tm1);
145 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"),
146 "strftime test #14");
148 size = strftime(s, 1000, "%w", &tm1);
149 CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "4"),
150 "strftime test #15");
152 size = strftime(s, 1000, "%W", &tm1);
153 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"),
154 "strftime test #16");
156 size = strftime(s, 1000, "%y", &tm1);
157 CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "74"),
158 "strftime test #17");
160 size = strftime(s, 1000, "%Y", &tm1);
161 CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"),
162 "strftime test #18");
164 size = strftime(s, 1000, "%%", &tm1);
165 CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "%"),
166 "strftime test #19");
168 size = strftime(s, 5, "%Y", &tm1);
169 CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"),
170 "strftime test #20");
172 size = strftime(s, 4, "%Y", &tm1);
173 CYG_TEST_PASS_FAIL((size==0), "strftime test #21");
176 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
177 "strftime() function");
182 main(int argc, char *argv[])
186 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
187 "strftime() function");
191 CYG_TEST_NA("Testing is not applicable to this configuration");