de9d45bcf7312ab3fab2d2f7677504929f85afd2
2 ** Copyright (C) 2003-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "test_main.h"
31 #define CMP_0_ARGS(line,err,fmt) \
32 { psf->logindex = 0 ; \
33 snprintf (buffer, sizeof (buffer), (fmt)) ; \
34 psf_log_printf (psf, (fmt)) ; \
35 err += compare_strings_or_die (line, fmt, buffer, psf->logbuffer) ; \
38 #define CMP_2_ARGS(line,err,fmt,a) \
39 { psf->logindex = 0 ; \
40 snprintf (buffer, sizeof (buffer), (fmt), (a), (a)) ; \
41 psf_log_printf (psf, (fmt), (a), (a)) ; \
42 err += compare_strings_or_die (line, fmt, buffer, psf->logbuffer) ; \
45 #define CMP_4_ARGS(line,err,fmt,a) \
46 { psf->logindex = 0 ; \
47 snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a)) ; \
48 psf_log_printf (psf, (fmt), (a), (a), (a), (a)) ; \
49 err += compare_strings_or_die (line, fmt, buffer, psf->logbuffer) ; \
52 #define CMP_5_ARGS(line,err,fmt,a) \
53 { psf->logindex = 0 ; \
54 snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a), (a)) ; \
55 psf_log_printf (psf, (fmt), (a), (a), (a), (a), (a)) ; \
56 err += compare_strings_or_die (line, fmt, buffer, psf->logbuffer) ; \
59 #define CMP_6_ARGS(line,err,fmt,a) \
60 { psf->logindex = 0 ; \
61 snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a), (a), (a)) ; \
62 psf_log_printf (psf, (fmt), (a), (a), (a), (a), (a), (a)) ; \
63 err += compare_strings_or_die (line, fmt, buffer, psf->logbuffer) ; \
67 compare_strings_or_die (int linenum
, const char *fmt
, const char* s1
, const char* s2
)
69 /*-puts (s1) ;puts (s2) ;-*/
71 if (strcmp (s1
, s2
) != 0)
72 { printf ("\n\nLine %d: string compare mismatch:\n\t", linenum
) ;
73 printf ("\"%s\"\n", fmt
) ;
74 printf ("\t\"%s\"\n\t\"%s\"\n", s1
, s2
) ;
79 } /* compare_strings_or_die */
82 test_log_printf (void)
83 { static char buffer
[2048] ;
84 SF_PRIVATE sf_private
, *psf
;
86 int int_values
[] = { 0, 1, 12, 123, 1234, 123456, -1, -12, -123, -1234, -123456 } ;
88 print_test_name ("Testing psf_log_printf") ;
91 memset (psf
, 0, sizeof (sf_private
)) ;
93 CMP_0_ARGS (__LINE__
, errors
, " ->%%<- ") ;
95 /* Test printing of ints. */
96 for (k
= 0 ; k
< ARRAY_LEN (int_values
) ; k
++)
97 CMP_6_ARGS (__LINE__
, errors
, "int A : %d, % d, %4d, % 4d, %04d, % 04d", int_values
[k
]) ;
99 for (k
= 0 ; k
< ARRAY_LEN (int_values
) ; k
++)
100 CMP_5_ARGS (__LINE__
, errors
, "int B : %+d, %+4d, %+04d, %-d, %-4d", int_values
[k
]) ;
102 for (k
= 0 ; k
< ARRAY_LEN (int_values
) ; k
++)
103 CMP_2_ARGS (__LINE__
, errors
, "int C : %- d, %- 4d", int_values
[k
]) ;
105 /* Test printing of unsigned ints. */
106 for (k
= 0 ; k
< ARRAY_LEN (int_values
) ; k
++)
107 CMP_4_ARGS (__LINE__
, errors
, "D : %u, %4u, %04u, %0u", int_values
[k
]) ;
109 /* Test printing of hex ints. */
110 for (k
= 0 ; k
< ARRAY_LEN (int_values
) ; k
++)
111 CMP_4_ARGS (__LINE__
, errors
, "E : %X, %4X, %04X, %0X", int_values
[k
]) ;
113 /* Test printing of strings. */
114 CMP_4_ARGS (__LINE__
, errors
, "B %s, %3s, %8s, %-8s", "str") ;
117 { puts ("\nExiting due to errors.\n") ;
122 } /* test_log_printf */