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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [infra/] [current/] [tests/] [diag_sprintf2.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
2
//
3
//        diag_sprintf2.c
4
//
5
//        Testcase for infra library diag_sprintf()
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, 2006 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):       ctarpy, jlarmour
43
// Contributors:    andrew lunn
44
// Date:            2005-02-09
45
// Description:     Contains testcode for infra library diag_sprintf() function
46
//
47
//
48
//####DESCRIPTIONEND####
49
 
50
// CONFIGURATION
51
 
52
// INCLUDES
53
 
54
#include <cyg/infra/diag.h>
55
#include <cyg/infra/testcase.h>
56
 
57
// FUNCTIONS
58
 
59
// Functions to avoid having to use libc strings
60
 
61
static int
62
my_strlen(const char *s)
63
{
64
    const char *ptr;
65
 
66
    ptr = s;
67
    for ( ptr=s ; *ptr != '\0' ; ptr++ )
68
        ;
69
 
70
    return (int)(ptr-s);
71
} // my_strlen()
72
 
73
 
74
static int
75
my_strcmp(const char *s1, const char *s2)
76
{
77
    for ( ; *s1 == *s2 ; s1++,s2++ )
78
    {
79
        if ( *s1 == '\0' )
80
            break;
81
    } // for
82
 
83
    return (*s1 - *s2);
84
} // my_strcmp()
85
 
86
 
87
static char *
88
my_strcpy(char *s1, const char *s2)
89
{
90
    while (*s2 != '\0') {
91
        *(s1++) = *(s2++);
92
    }
93
    *s1 = '\0';
94
 
95
    return s1;
96
} // my_strcpy()
97
 
98
 
99
 
100
static void
101
test( CYG_ADDRWORD data )
102
{
103
    static char x[200];
104
    static char y[200];
105
    static char z[200];
106
    int ret;
107
 
108
    // Check 1
109
    my_strcpy(x, "I'm afraid the shield generator");
110
    ret = diag_sprintf(y, "%s will be quite operational - %5d%%%c%05X", x,
111
                   13, '5', 0x89ab);
112
    my_strcpy( z, "I'm afraid the shield generator will be "
113
                  "quite operational -    13%5089AB" );
114
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "%s%n%d%%%c%0X test");
115
 
116
    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
117
                       "%s%n%d%%%c%0X test return code" );
118
 
119
    // Check 2
120
    ret = diag_sprintf(y, "|%5d|%10s|%03d|%c|", 2, "times", 6, '=');
121
    my_strcpy(z, "|    2|     times|006|=|");
122
 
123
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "|%5d|%10s|%03d|%c| test");
124
 
125
    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
126
                       "|%5d|%10s|%03d|%c|%o| test return code" );
127
 
128
    // Check 3
129
    ret = diag_snprintf(y, 19, "print up to here >< and not this bit" );
130
    my_strcpy(z, "print up to here >");
131
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "simple diag_snprintf test #1");
132
    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
133
                       "simple diag_snprintf test #1 return code" );
134
 
135
    // Check 4
136
    ret = diag_snprintf(y, 31, "print a bit of this number: %05d nyer", 1234);
137
    my_strcpy(z, "print a bit of this number: 01");
138
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "simple diag_snprintf test #2");
139
    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
140
                       "simple diag_snprintf test #2 return code" );
141
 
142
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__
143
                    " for C library diag_sprintf() function");
144
 
145
} // test()
146
 
147
void
148
cyg_user_start(void)
149
{
150
    CYG_TEST_INIT();
151
 
152
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for infra "
153
                  "library diag_sprintf() function");
154
    CYG_TEST_INFO("These test combinations of diag_sprintf() features");
155
 
156
    test(0);
157
} // cyg_user_start()
158
 
159
// EOF diag_sprintf2.c

powered by: WebSVN 2.1.0

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