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/] [mktime.c] - Blame information for rev 810

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
2
//
3
//        mktime.c
4
//
5
//        Testcase for C library mktime() 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:  jlarmour
44
// Date:          1999-03-05
45
// Description:   Contains testcode for C library mktime() 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
 
91
    tm1.tm_sec = 4;
92
    tm1.tm_min = 23;
93
    tm1.tm_hour = 20;
94
    tm1.tm_mday = 21;
95
    tm1.tm_mon = 1;
96
    tm1.tm_year = 74;
97
    tm1.tm_isdst = 0;
98
 
99
    tm2 = tm1;
100
    tm2.tm_wday = 4;
101
    tm2.tm_yday = 51;
102
 
103
    t = mktime(&tm1);
104
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #1");
105
    CYG_TEST_PASS_FAIL(t == 130710184, "mktime return test #1");
106
 
107
    tm1.tm_sec = 61;
108
    tm1.tm_min = 20;
109
    tm1.tm_hour = 4;
110
    tm1.tm_mday = 5;
111
    tm1.tm_mon = 0;
112
    tm1.tm_year = 99;
113
    tm1.tm_isdst = 0;
114
 
115
    tm2 = tm1;
116
    tm2.tm_sec=1;
117
    tm2.tm_min = 21;
118
    tm2.tm_wday = 2;
119
    tm2.tm_yday = 4;
120
 
121
    t = mktime(&tm1);
122
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #2");
123
    CYG_TEST_PASS_FAIL(t == 915510061, "mktime return test #2");
124
 
125
    tm1.tm_sec = 54;
126
    tm1.tm_min = 24;
127
    tm1.tm_hour = 1;
128
    tm1.tm_mday = 1;
129
    tm1.tm_mon = 0;
130
    tm1.tm_year = 100;
131
    tm1.tm_isdst = 0;
132
 
133
    tm2 = tm1;
134
    tm2.tm_wday = 6;
135
    tm2.tm_yday = 0;
136
 
137
    t = mktime(&tm1);
138
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime Y2K test #3");
139
    CYG_TEST_PASS_FAIL(t == 946689894, "mktime Y2K return test #3");
140
 
141
    tm1.tm_sec = 54;
142
    tm1.tm_min = 24;
143
    tm1.tm_hour = 23;
144
    tm1.tm_mday = 31;
145
    tm1.tm_mon = 4;
146
    tm1.tm_year = 66;
147
    tm1.tm_isdst = 1;
148
 
149
    tm2 = tm1;
150
    tm2.tm_wday = 2;
151
    tm2.tm_yday = 150;
152
 
153
    t = mktime(&tm1);
154
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #4");
155
    CYG_TEST_PASS_FAIL(t == -113186106, "mktime return test #4");
156
 
157
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
158
                    "mktime() function");
159
} // test()
160
 
161
 
162
int
163
main(int argc, char *argv[])
164
{
165
    CYG_TEST_INIT();
166
 
167
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
168
                  "mktime() function");
169
 
170
    START_TEST( test );
171
 
172
    CYG_TEST_NA("Testing is not applicable to this configuration");
173
 
174
} // main()
175
 
176
// EOF mktime.c

powered by: WebSVN 2.1.0

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