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

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

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
2
//
3
//        strptime.c
4
//
5
//        Testcase for C library strptime() 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, 2003 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:  gthomas
44
// Date:          1999-03-05
45
// Description:   Contains testcode for C library strptime() 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
#include <string.h>                     // strlen()
59
// HOW TO START TESTS
60
 
61
# define START_TEST( test ) test(0)
62
 
63
// FUNCTIONS
64
 
65
static int my_strcmp(const char *s1, const char *s2)
66
{
67
    for ( ; *s1 == *s2 ; s1++,s2++ )
68
    {
69
        if ( *s1 == '\0' )
70
            break;
71
    } // for
72
 
73
    return (*s1 - *s2);
74
} // my_strcmp()
75
 
76
static void
77
test( CYG_ADDRWORD data )
78
{
79
    struct tm tm1;
80
    char s[1000], *sp, *dp, *fp;
81
    size_t size;
82
 
83
    dp = "Fri Jan 24 08:33:14 2003";
84
    fp = "%a %b %d %H:%M:%S %Y";
85
    sp = strptime(dp, fp, &tm1);
86
 
87
    // Set an invalid year day. The following converters don't use
88
    // this, so it should not cause a problem.
89
    tm1.tm_yday = 1000;
90
 
91
    CYG_TEST_PASS_FAIL(((sp!=NULL) && (*sp=='\0')), "strptime test #1");
92
    size = strftime(s, sizeof(s), fp, &tm1);
93
    CYG_TEST_PASS_FAIL(((size==strlen(dp)) && (my_strcmp(s, dp) == 0)), "strptime test #2");
94
 
95
    dp = "Friday January 24 08:33:14 2003";
96
    fp = "%A %B %d %H:%M:%S %Y";
97
    sp = strptime(dp, fp, &tm1);
98
    CYG_TEST_PASS_FAIL(((sp!=NULL) && (*sp=='\0')), "strptime test #3");
99
    size = strftime(s, sizeof(s), fp, &tm1);
100
    CYG_TEST_PASS_FAIL(((size==strlen(dp)) && (my_strcmp(s, dp) == 0)), "strptime test #4");
101
 
102
    dp = "2006:06:13 12:22:01";
103
    fp = "%x %X";
104
    sp = strptime(dp, fp, &tm1);
105
    CYG_TEST_PASS_FAIL(((sp!=NULL) && (*sp=='\0')), "strptime test #5");
106
    CYG_TEST_PASS_FAIL((tm1.tm_sec == 01) &&
107
                       (tm1.tm_min == 22) &&
108
                       (tm1.tm_hour == 12) &&
109
                       (tm1.tm_mday == 13) &&
110
                       (tm1.tm_mon ==  (06 - 1)) &&
111
                       (tm1.tm_year == (2006 - 1900)), "strptime test #6");
112
    size = strftime(s, sizeof(s), fp, &tm1);
113
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
114
                    "strptime() 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
                  "strptime() function");
125
 
126
    START_TEST( test );
127
 
128
    CYG_TEST_NA("Testing is not applicable to this configuration");
129
 
130
} // main()
131
 
132
// EOF strptime.c

powered by: WebSVN 2.1.0

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