1 |
27 |
unneback |
//=================================================================
|
2 |
|
|
//
|
3 |
|
|
// strftime.c
|
4 |
|
|
//
|
5 |
|
|
// Testcase for C library strftime() function
|
6 |
|
|
//
|
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.
|
12 |
|
|
//
|
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.
|
16 |
|
|
//
|
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
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
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.
|
25 |
|
|
//
|
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.
|
32 |
|
|
//
|
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.
|
35 |
|
|
//
|
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####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): jlarmour
|
44 |
|
|
// Contributors:
|
45 |
|
|
// Date: 1999-03-05
|
46 |
|
|
// Description: Contains testcode for C library strftime() function
|
47 |
|
|
//
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
|
51 |
|
|
// CONFIGURATION
|
52 |
|
|
|
53 |
|
|
#include <pkgconf/libc_time.h> // C library configuration
|
54 |
|
|
|
55 |
|
|
// INCLUDES
|
56 |
|
|
|
57 |
|
|
#include <time.h>
|
58 |
|
|
#include <cyg/infra/testcase.h>
|
59 |
|
|
|
60 |
|
|
// HOW TO START TESTS
|
61 |
|
|
|
62 |
|
|
# define START_TEST( test ) test(0)
|
63 |
|
|
|
64 |
|
|
// FUNCTIONS
|
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, "02"),
|
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
|