1 |
786 |
skrzyp |
//=================================================================
|
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 Free Software Foundation, 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
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//=================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): jlarmour
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 1999-03-05
|
45 |
|
|
// Description: Contains testcode for C library strftime() function
|
46 |
|
|
//
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
|
50 |
|
|
// CONFIGURATION
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/libc_time.h> // C library configuration
|
53 |
|
|
|
54 |
|
|
// INCLUDES
|
55 |
|
|
|
56 |
|
|
#include <time.h>
|
57 |
|
|
#include <cyg/infra/testcase.h>
|
58 |
|
|
|
59 |
|
|
// HOW TO START TESTS
|
60 |
|
|
|
61 |
|
|
# define START_TEST( test ) test(0)
|
62 |
|
|
|
63 |
|
|
// FUNCTIONS
|
64 |
|
|
|
65 |
|
|
static int my_strcmp(const char *s1, const char *s2)
|
66 |
|
|
{
|
67 |
|
|
for ( ; *s1 == *s2 ; s1++,s2++ )
|
68 |
|
|
{
|
69 |
|
|
if ( *s1 == '\0' )
|
70 |
|
|
break;
|
71 |
|
|
} // for
|
72 |
|
|
|
73 |
|
|
return (*s1 - *s2);
|
74 |
|
|
} // my_strcmp()
|
75 |
|
|
|
76 |
|
|
static void
|
77 |
|
|
test( CYG_ADDRWORD data )
|
78 |
|
|
{
|
79 |
|
|
struct tm tm1;
|
80 |
|
|
char s[1000];
|
81 |
|
|
size_t size;
|
82 |
|
|
|
83 |
|
|
tm1.tm_sec = 4;
|
84 |
|
|
tm1.tm_min = 23;
|
85 |
|
|
tm1.tm_hour = 20;
|
86 |
|
|
tm1.tm_mday = 21;
|
87 |
|
|
tm1.tm_mon = 1;
|
88 |
|
|
tm1.tm_year = 74;
|
89 |
|
|
tm1.tm_wday = 4;
|
90 |
|
|
tm1.tm_yday = 51;
|
91 |
|
|
tm1.tm_isdst = 0;
|
92 |
|
|
|
93 |
|
|
size = strftime(s, 1000, "", &tm1);
|
94 |
|
|
CYG_TEST_PASS_FAIL((size==0) && (*s=='\0'), "strftime test #1");
|
95 |
|
|
|
96 |
|
|
size = strftime(s, 1000, "%a", &tm1);
|
97 |
|
|
CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Thu"), "strftime test #2");
|
98 |
|
|
|
99 |
|
|
size = strftime(s, 1000, "%A", &tm1);
|
100 |
|
|
CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "Thursday"),
|
101 |
|
|
"strftime test #3");
|
102 |
|
|
|
103 |
|
|
size = strftime(s, 1000, "%b", &tm1);
|
104 |
|
|
CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Feb"),
|
105 |
|
|
"strftime test #4");
|
106 |
|
|
|
107 |
|
|
size = strftime(s, 1000, "%B", &tm1);
|
108 |
|
|
CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "February"),
|
109 |
|
|
"strftime test #5");
|
110 |
|
|
|
111 |
|
|
size = strftime(s, 1000, "%d", &tm1);
|
112 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "21"),
|
113 |
|
|
"strftime test #6");
|
114 |
|
|
|
115 |
|
|
size = strftime(s, 1000, "%H", &tm1);
|
116 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "20"),
|
117 |
|
|
"strftime test #7");
|
118 |
|
|
|
119 |
|
|
size = strftime(s, 1000, "%I", &tm1);
|
120 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "08"),
|
121 |
|
|
"strftime test #8");
|
122 |
|
|
|
123 |
|
|
size = strftime(s, 1000, "%j", &tm1);
|
124 |
|
|
CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "051"),
|
125 |
|
|
"strftime test #9");
|
126 |
|
|
|
127 |
|
|
size = strftime(s, 1000, "%m", &tm1);
|
128 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "02"),
|
129 |
|
|
"strftime test #10");
|
130 |
|
|
|
131 |
|
|
size = strftime(s, 1000, "%M", &tm1);
|
132 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "23"),
|
133 |
|
|
"strftime test #11");
|
134 |
|
|
|
135 |
|
|
size = strftime(s, 1000, "%p", &tm1);
|
136 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "pm"),
|
137 |
|
|
"strftime test #12");
|
138 |
|
|
|
139 |
|
|
size = strftime(s, 1000, "%S", &tm1);
|
140 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "04"),
|
141 |
|
|
"strftime test #13");
|
142 |
|
|
|
143 |
|
|
size = strftime(s, 1000, "%U", &tm1);
|
144 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"),
|
145 |
|
|
"strftime test #14");
|
146 |
|
|
|
147 |
|
|
size = strftime(s, 1000, "%w", &tm1);
|
148 |
|
|
CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "4"),
|
149 |
|
|
"strftime test #15");
|
150 |
|
|
|
151 |
|
|
size = strftime(s, 1000, "%W", &tm1);
|
152 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"),
|
153 |
|
|
"strftime test #16");
|
154 |
|
|
|
155 |
|
|
size = strftime(s, 1000, "%y", &tm1);
|
156 |
|
|
CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "74"),
|
157 |
|
|
"strftime test #17");
|
158 |
|
|
|
159 |
|
|
size = strftime(s, 1000, "%Y", &tm1);
|
160 |
|
|
CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"),
|
161 |
|
|
"strftime test #18");
|
162 |
|
|
|
163 |
|
|
size = strftime(s, 1000, "%%", &tm1);
|
164 |
|
|
CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "%"),
|
165 |
|
|
"strftime test #19");
|
166 |
|
|
|
167 |
|
|
size = strftime(s, 5, "%Y", &tm1);
|
168 |
|
|
CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"),
|
169 |
|
|
"strftime test #20");
|
170 |
|
|
|
171 |
|
|
size = strftime(s, 4, "%Y", &tm1);
|
172 |
|
|
CYG_TEST_PASS_FAIL((size==0), "strftime test #21");
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
|
176 |
|
|
"strftime() function");
|
177 |
|
|
} // test()
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
int
|
181 |
|
|
main(int argc, char *argv[])
|
182 |
|
|
{
|
183 |
|
|
CYG_TEST_INIT();
|
184 |
|
|
|
185 |
|
|
CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
|
186 |
|
|
"strftime() function");
|
187 |
|
|
|
188 |
|
|
START_TEST( test );
|
189 |
|
|
|
190 |
|
|
CYG_TEST_NA("Testing is not applicable to this configuration");
|
191 |
|
|
|
192 |
|
|
} // main()
|
193 |
|
|
|
194 |
|
|
// EOF strftime.c
|