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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libc/] [time/] [current/] [tests/] [gmtime.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
2
//
3
//        gmtime.c
4
//
5
//        Testcase for C library gmtime() 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 gmtime() 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
66
cmp_structtm(struct tm *tm1, struct tm *tm2)
67
{
68
    if ((tm1->tm_sec   != tm2->tm_sec)   ||
69
        (tm1->tm_min   != tm2->tm_min)   ||
70
        (tm1->tm_hour  != tm2->tm_hour)  ||
71
        (tm1->tm_mday  != tm2->tm_mday)  ||
72
        (tm1->tm_mon   != tm2->tm_mon)   ||
73
        (tm1->tm_year  != tm2->tm_year)  ||
74
        (tm1->tm_wday  != tm2->tm_wday)  ||
75
        (tm1->tm_yday  != tm2->tm_yday)  ||
76
        (tm1->tm_isdst != tm2->tm_isdst))
77
        return 1;
78
    else
79
        return 0;
80
}
81
 
82
static void
83
test( CYG_ADDRWORD data )
84
{
85
    struct tm tm1, *tm2;
86
    time_t t;
87
 
88
    // make this predictable - independent of the user option
89
    cyg_libc_time_setzoneoffsets(0, 3600);
90
    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );
91
 
92
    tm1.tm_sec = 4;
93
    tm1.tm_min = 23;
94
    tm1.tm_hour = 20;
95
    tm1.tm_mday = 21;
96
    tm1.tm_mon = 1;
97
    tm1.tm_year = 74;
98
    tm1.tm_wday = 4;
99
    tm1.tm_yday = 51;
100
    tm1.tm_isdst = 0;
101
 
102
    t = (time_t)130710184;
103
 
104
    tm2 = gmtime(&t);
105
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, tm2), "gmtime test #1");
106
 
107
 
108
    tm1.tm_sec = 1;
109
    tm1.tm_min = 21;
110
    tm1.tm_hour = 4;
111
    tm1.tm_mday = 5;
112
    tm1.tm_mon = 0;
113
    tm1.tm_wday = 2;
114
    tm1.tm_yday = 4;
115
    tm1.tm_year = 99;
116
    tm1.tm_isdst = 0;
117
 
118
    t = (time_t)915510061;
119
 
120
    tm2 = gmtime(&t);
121
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, tm2), "gmtime test #2");
122
 
123
    tm1.tm_sec = 54;
124
    tm1.tm_min = 24;
125
    tm1.tm_hour = 1;
126
    tm1.tm_mday = 1;
127
    tm1.tm_mon = 0;
128
    tm1.tm_year = 100;
129
    tm1.tm_wday = 6;
130
    tm1.tm_yday = 0;
131
    tm1.tm_isdst = 0;
132
 
133
    t = (time_t)946689894;
134
 
135
    tm2 = gmtime(&t);
136
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, tm2), "gmtime Y2K test #3");
137
 
138
    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTON );
139
 
140
    tm1.tm_sec = 54;
141
    tm1.tm_min = 24;
142
    tm1.tm_hour = 23;
143
    tm1.tm_mday = 31;
144
    tm1.tm_mon = 4;
145
    tm1.tm_wday = 2;
146
    tm1.tm_yday = 150;
147
    tm1.tm_year = 66;
148
    tm1.tm_isdst = 0;
149
 
150
    t = (time_t)-113186106;
151
 
152
    tm2 = gmtime(&t);
153
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, tm2), "gmtime test #4");
154
 
155
    tm1.tm_sec = 59;
156
    tm1.tm_min = 59;
157
    tm1.tm_hour = 23;
158
    tm1.tm_mday = 31;
159
    tm1.tm_mon = 4;
160
    tm1.tm_wday = 3;
161
    tm1.tm_yday = 151;
162
    tm1.tm_year = 100;
163
    tm1.tm_isdst = 0;
164
 
165
    t = (time_t)959817599;
166
 
167
    tm2 = gmtime(&t);
168
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, tm2), "gmtime test #5");
169
 
170
    tm1.tm_sec = 0;
171
    tm1.tm_min = 0;
172
    tm1.tm_hour = 0;
173
    tm1.tm_mday = 1;
174
    tm1.tm_mon = 5;
175
    tm1.tm_wday = 4;
176
    tm1.tm_yday = 152;
177
    tm1.tm_year = 100;
178
    tm1.tm_isdst = 0;
179
 
180
    t = (time_t)959817600;
181
 
182
    tm2 = gmtime(&t);
183
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, tm2), "gmtime test #6");
184
 
185
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
186
                    "gmtime() function");
187
} // test()
188
 
189
 
190
int
191
main(int argc, char *argv[])
192
{
193
    CYG_TEST_INIT();
194
 
195
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
196
                  "gmtime() function");
197
 
198
    START_TEST( test );
199
 
200
    CYG_TEST_NA("Testing is not applicable to this configuration");
201
 
202
} // main()
203
 
204
// EOF gmtime.c

powered by: WebSVN 2.1.0

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