OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [time/] [v2_0/] [tests/] [asctime.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=================================================================
2
//
3
//        asctime.c
4
//
5
//        Testcase for C library asctime() 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 asctime() 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
 
67
static int my_strcmp(const char *s1, const char *s2)
68
{
69
    for ( ; *s1 == *s2 ; s1++,s2++ )
70
    {
71
        if ( *s1 == '\0' )
72
            break;
73
    } // for
74
 
75
    return (*s1 - *s2);
76
} // my_strcmp()
77
 
78
 
79
static void
80
test( CYG_ADDRWORD data )
81
{
82
    struct tm tm1;
83
    char *ret;
84
 
85
    tm1.tm_sec = 4;
86
    tm1.tm_min = 23;
87
    tm1.tm_hour = 20;
88
    tm1.tm_mday = 21;
89
    tm1.tm_mon = 1;
90
    tm1.tm_year = 74;
91
    tm1.tm_wday = 4;
92
    tm1.tm_yday = 51;
93
    tm1.tm_isdst = 0;
94
 
95
    ret = asctime(&tm1);
96
 
97
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Thu Feb 21 20:23:04 1974\n"),
98
                       "asctime test #1");
99
    tm1.tm_sec = 3;
100
    tm1.tm_min = 51;
101
    tm1.tm_hour = 5;
102
    tm1.tm_mday = 2;
103
    tm1.tm_mon = 11;
104
    tm1.tm_year = 68;
105
    tm1.tm_wday = 1;
106
    tm1.tm_yday = 336;
107
    tm1.tm_isdst = 0;
108
 
109
    ret = asctime(&tm1);
110
 
111
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Mon Dec 02 05:51:03 1968\n"),
112
                       "asctime test #2");
113
 
114
    // make this predictable - independent of the user option
115
    cyg_libc_time_setzoneoffsets(0, 3600);
116
 
117
    tm1.tm_sec = 3;
118
    tm1.tm_min = 51;
119
    tm1.tm_hour = 5;
120
    tm1.tm_mday = 2;
121
    tm1.tm_mon = 6;
122
    tm1.tm_year = 68;
123
    tm1.tm_wday = 2;
124
    tm1.tm_yday = 183;
125
    tm1.tm_isdst = 1;
126
 
127
    ret = asctime(&tm1);
128
 
129
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Tue Jul 02 05:51:03 1968\n"),
130
                       "asctime test #3");
131
 
132
    tm1.tm_sec = 0;
133
    tm1.tm_min = 0;
134
    tm1.tm_hour = 0;
135
    tm1.tm_mday = 1;
136
    tm1.tm_mon = 0;
137
    tm1.tm_year = 0;
138
    tm1.tm_wday = 1;
139
    tm1.tm_yday = 0;
140
    tm1.tm_isdst = 0;
141
 
142
    ret = asctime(&tm1);
143
 
144
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Mon Jan 01 00:00:00 1900\n"),
145
                       "asctime test #4");
146
 
147
    tm1.tm_sec = 0;
148
    tm1.tm_min = 0;
149
    tm1.tm_hour = 0;
150
    tm1.tm_mday = 1;
151
    tm1.tm_mon = 0;
152
    tm1.tm_year = 100;
153
    tm1.tm_wday = 6;
154
    tm1.tm_yday = 0;
155
    tm1.tm_isdst = 0;
156
 
157
    ret = asctime(&tm1);
158
 
159
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Sat Jan 01 00:00:00 2000\n"),
160
                       "asctime Y2K test #5");
161
 
162
#ifdef CYGFUN_LIBC_TIME_POSIX
163
    {
164
        char ret2[100];
165
 
166
        tm1.tm_sec = 3;
167
        tm1.tm_min = 51;
168
        tm1.tm_hour = 5;
169
        tm1.tm_mday = 2;
170
        tm1.tm_mon = 11;
171
        tm1.tm_year = 68;
172
        tm1.tm_wday = 1;
173
        tm1.tm_yday = 336;
174
        tm1.tm_isdst = 0;
175
 
176
        ret = asctime_r(&tm1, ret2);
177
 
178
        CYG_TEST_PASS_FAIL((ret==ret2) &&
179
                           !my_strcmp(ret, "Mon Dec 02 05:51:03 1968\n"),
180
                           "asctime_r test #1");
181
 
182
    }
183
#endif
184
 
185
 
186
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
187
                    "asctime() function");
188
} // test()
189
 
190
 
191
int
192
main(int argc, char *argv[])
193
{
194
    CYG_TEST_INIT();
195
 
196
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
197
                  "asctime() function");
198
 
199
    START_TEST( test );
200
 
201
    CYG_TEST_NA("Testing is not applicable to this configuration");
202
 
203
} // main()
204
 
205
// EOF asctime.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.