comparison packages/language/c/libc/time/current/tests/ctime.c @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children e0c0827131d1
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 //=================================================================
2 //
3 // ctime.c
4 //
5 // Testcase for C library ctime() function
6 //
7 //=================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //=================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): jlarmour
35 // Contributors: jlarmour
36 // Date: 1999-03-05
37 // Description: Contains testcode for C library ctime() function
38 //
39 //
40 //####DESCRIPTIONEND####
41
42 // CONFIGURATION
43
44 #include <pkgconf/libc_time.h> // C library configuration
45
46 // INCLUDES
47
48 #include <time.h>
49 #include <cyg/infra/testcase.h>
50
51 // HOW TO START TESTS
52
53 # define START_TEST( test ) test(0)
54
55 // FUNCTIONS
56
57 static int my_strcmp(const char *s1, const char *s2)
58 {
59 for ( ; *s1 == *s2 ; s1++,s2++ )
60 {
61 if ( *s1 == '\0' )
62 break;
63 } // for
64
65 return (*s1 - *s2);
66 } // my_strcmp()
67
68
69 static void
70 test( CYG_ADDRWORD data )
71 {
72 time_t t;
73 char *ret;
74
75 // make this predictable - independent of the user option
76 cyg_libc_time_setzoneoffsets(0, 3600);
77 cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );
78
79 t = (time_t)130710184;
80
81 ret = ctime(&t);
82 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Thu Feb 21 20:23:04 1974\n"),
83 "ctime test #1");
84
85 t = (time_t)946689894;
86
87 ret = ctime(&t);
88 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Sat Jan 01 01:24:54 2000\n"),
89 "ctime Y2K test #2");
90
91 cyg_libc_time_setdst( CYG_LIBC_TIME_DSTON );
92
93 t = (time_t)-113186106;
94
95 ret = ctime(&t);
96 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Tue Jun 01 00:24:54 1966\n"),
97 "ctime test #3");
98
99 #ifdef CYGFUN_LIBC_TIME_POSIX
100 cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );
101
102 t = (time_t)915510061;
103
104 {
105 char ret2[26];
106
107 ret = ctime_r(&t, ret2);
108 CYG_TEST_PASS_FAIL(!my_strcmp(ret2, "Tue Jan 05 04:21:01 1999\n"),
109 "ctime_r test #1");
110 }
111 #endif
112
113 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
114 "ctime() function");
115 } // test()
116
117
118 int
119 main(int argc, char *argv[])
120 {
121 CYG_TEST_INIT();
122
123 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
124 "ctime() function");
125
126 START_TEST( test );
127
128 CYG_TEST_NA("Testing is not applicable to this configuration");
129
130 } // main()
131
132 // EOF ctime.c