Mercurial > flash_v2
comparison packages/language/c/libc/current/tests/time/ctime.c @ 2:443894e2e912 ecos-v1_2_1-release
Block commit of eCos version 1.2.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 12:24:34 +0000 |
| parents | |
| children | d3fbcdfa1b2f |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 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 Cygnus eCos Public License | |
| 12 // Version 1.0 (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://sourceware.cygnus.com/ecos | |
| 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 Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //================================================================= | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): jlarmour | |
| 33 // Contributors: jlarmour | |
| 34 // Date: 1999-03-05 | |
| 35 // Description: Contains testcode for C library ctime() function | |
| 36 // | |
| 37 // | |
| 38 //####DESCRIPTIONEND#### | |
| 39 | |
| 40 // CONFIGURATION | |
| 41 | |
| 42 #include <pkgconf/libc.h> // C library configuration | |
| 43 | |
| 44 // INCLUDES | |
| 45 | |
| 46 #include <time.h> | |
| 47 #include <cyg/infra/testcase.h> | |
| 48 #include <sys/cstartup.h> // C library initialisation | |
| 49 | |
| 50 // HOW TO START TESTS | |
| 51 | |
| 52 # define START_TEST( test ) test(0) | |
| 53 | |
| 54 // FUNCTIONS | |
| 55 | |
| 56 | |
| 57 externC void | |
| 58 cyg_package_start( void ) | |
| 59 { | |
| 60 cyg_iso_c_start(); | |
| 61 } // cyg_package_start() | |
| 62 | |
| 63 | |
| 64 static int my_strcmp(const char *s1, const char *s2) | |
| 65 { | |
| 66 for ( ; *s1 == *s2 ; s1++,s2++ ) | |
| 67 { | |
| 68 if ( *s1 == '\0' ) | |
| 69 break; | |
| 70 } // for | |
| 71 | |
| 72 return (*s1 - *s2); | |
| 73 } // my_strcmp() | |
| 74 | |
| 75 | |
| 76 static void | |
| 77 test( CYG_ADDRWORD data ) | |
| 78 { | |
| 79 time_t t; | |
| 80 char *ret; | |
| 81 char ret2[26]; | |
| 82 | |
| 83 // make this predictable - independent of the user option | |
| 84 cyg_libc_time_setzoneoffsets(0, 3600); | |
| 85 cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF ); | |
| 86 | |
| 87 t = (time_t)130710184; | |
| 88 | |
| 89 ret = ctime(&t); | |
| 90 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Thu Feb 21 20:23:04 1974\n"), | |
| 91 "ctime test #1"); | |
| 92 | |
| 93 t = (time_t)946689894; | |
| 94 | |
| 95 ret = ctime(&t); | |
| 96 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Sat Jan 01 01:24:54 2000\n"), | |
| 97 "ctime Y2K test #2"); | |
| 98 | |
| 99 cyg_libc_time_setdst( CYG_LIBC_TIME_DSTON ); | |
| 100 | |
| 101 t = (time_t)-113186106; | |
| 102 | |
| 103 ret = ctime(&t); | |
| 104 CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Tue Jun 01 00:24:54 1966\n"), | |
| 105 "ctime test #3"); | |
| 106 | |
| 107 #ifdef CYGFUN_LIBC_TIME_POSIX | |
| 108 cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF ); | |
| 109 | |
| 110 t = (time_t)915510061; | |
| 111 | |
| 112 ret = ctime_r(&t, ret2); | |
| 113 CYG_TEST_PASS_FAIL(!my_strcmp(ret2, "Tue Jan 05 04:21:01 1999\n"), | |
| 114 "ctime_r test #1"); | |
| 115 #endif | |
| 116 | |
| 117 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | |
| 118 "ctime() function"); | |
| 119 } // test() | |
| 120 | |
| 121 | |
| 122 int | |
| 123 main(int argc, char *argv[]) | |
| 124 { | |
| 125 CYG_TEST_INIT(); | |
| 126 | |
| 127 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 128 "ctime() function"); | |
| 129 | |
| 130 START_TEST( test ); | |
| 131 | |
| 132 CYG_TEST_NA("Testing is not applicable to this configuration"); | |
| 133 | |
| 134 } // main() | |
| 135 | |
| 136 // EOF ctime.c |
