1 //=================================================================
5 // Testcase for infra library diag_sprintf()
7 //=================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // -------------------------------------------
37 //####ECOSGPLCOPYRIGHTEND####
38 //=================================================================
39 //#####DESCRIPTIONBEGIN####
41 // Author(s): ctarpy, jlarmour
42 // Contributors: andrew lunn
44 // Description: Contains testcode for infra library diag_sprintf() function
47 //####DESCRIPTIONEND####
53 #include <cyg/infra/diag.h>
54 #include <cyg/infra/testcase.h>
58 // Functions to avoid having to use libc strings
61 my_strlen(const char *s)
66 for ( ptr=s ; *ptr != '\0' ; ptr++ )
74 my_strcmp(const char *s1, const char *s2)
76 for ( ; *s1 == *s2 ; s1++,s2++ )
87 my_strcpy(char *s1, const char *s2)
100 test( CYG_ADDRWORD data )
108 my_strcpy(x, "I'm afraid the shield generator");
109 ret = diag_sprintf(y, "%s will be quite operational - %5d%%%c%05X", x,
111 my_strcpy( z, "I'm afraid the shield generator will be "
112 "quite operational - 13%5089AB" );
113 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "%s%n%d%%%c%0X test");
115 CYG_TEST_PASS_FAIL(ret == my_strlen(z),
116 "%s%n%d%%%c%0X test return code" );
119 ret = diag_sprintf(y, "|%5d|%10s|%03d|%c|", 2, "times", 6, '=');
120 my_strcpy(z, "| 2| times|006|=|");
122 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "|%5d|%10s|%03d|%c| test");
124 CYG_TEST_PASS_FAIL(ret == my_strlen(z),
125 "|%5d|%10s|%03d|%c|%o| test return code" );
128 ret = diag_snprintf(y, 19, "print up to here >< and not this bit" );
129 my_strcpy(z, "print up to here >");
130 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "simple diag_snprintf test #1");
131 CYG_TEST_PASS_FAIL(ret == my_strlen(z),
132 "simple diag_snprintf test #1 return code" );
135 ret = diag_snprintf(y, 31, "print a bit of this number: %05d nyer", 1234);
136 my_strcpy(z, "print a bit of this number: 01");
137 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "simple diag_snprintf test #2");
138 CYG_TEST_PASS_FAIL(ret == my_strlen(z),
139 "simple diag_snprintf test #2 return code" );
141 CYG_TEST_FINISH("Finished tests from testcase " __FILE__
142 " for C library diag_sprintf() function");
147 main(int argc, char *argv[])
151 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for infra "
152 "library diag_sprintf() function");
153 CYG_TEST_INFO("These test combinations of diag_sprintf() features");
160 // EOF diag_sprintf2.c