forked from libsndfile/libsndfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_log_printf.c
125 lines (99 loc) · 4.03 KB
/
test_log_printf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
** Copyright (C) 2003-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 2.1 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "sfconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include "common.h"
#include "test_main.h"
#define CMP_0_ARGS(line, err, fmt) \
{ psf->parselog.indx = 0 ; \
snprintf (buffer, sizeof (buffer), (fmt)) ; \
psf_log_printf (psf, (fmt)) ; \
err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \
}
#define CMP_2_ARGS(line, err, fmt, a) \
{ psf->parselog.indx = 0 ; \
snprintf (buffer, sizeof (buffer), (fmt), (a), (a)) ; \
psf_log_printf (psf, (fmt), (a), (a)) ; \
err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \
}
#define CMP_4_ARGS(line, err, fmt, a) \
{ psf->parselog.indx = 0 ; \
snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a)) ; \
psf_log_printf (psf, (fmt), (a), (a), (a), (a)) ; \
err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \
}
#define CMP_5_ARGS(line, err, fmt, a) \
{ psf->parselog.indx = 0 ; \
snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a), (a)) ; \
psf_log_printf (psf, (fmt), (a), (a), (a), (a), (a)) ; \
err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \
}
#define CMP_6_ARGS(line, err, fmt, a) \
{ psf->parselog.indx = 0 ; \
snprintf (buffer, sizeof (buffer), (fmt), (a), (a), (a), (a), (a), (a)) ; \
psf_log_printf (psf, (fmt), (a), (a), (a), (a), (a), (a)) ; \
err += compare_strings_or_die (line, fmt, buffer, psf->parselog.buf) ; \
}
static int
compare_strings_or_die (int linenum, const char *fmt, const char* s1, const char* s2)
{ int errors = 0 ;
/*-puts (s1) ;puts (s2) ;-*/
if (strcmp (s1, s2) != 0)
{ printf ("\n\nLine %d: string compare mismatch:\n\t", linenum) ;
printf ("\"%s\"\n", fmt) ;
printf ("\t\"%s\"\n\t\"%s\"\n", s1, s2) ;
errors ++ ;
} ;
return errors ;
} /* compare_strings_or_die */
void
test_log_printf (void)
{ static char buffer [2048] ;
SF_PRIVATE sf_private, *psf ;
int k, errors = 0 ;
int int_values [] = { 0, 1, 12, 123, 1234, 123456, -1, -12, -123, -1234, -123456 } ;
print_test_name ("Testing psf_log_printf") ;
psf = &sf_private ;
memset (psf, 0, sizeof (sf_private)) ;
CMP_0_ARGS (__LINE__, errors, " ->%%<- ") ;
/* Test printing of ints. */
for (k = 0 ; k < ARRAY_LEN (int_values) ; k++)
CMP_6_ARGS (__LINE__, errors, "int A : %d, % d, %4d, % 4d, %04d, % 04d", int_values [k]) ;
for (k = 0 ; k < ARRAY_LEN (int_values) ; k++)
CMP_5_ARGS (__LINE__, errors, "int B : %+d, %+4d, %+04d, %-d, %-4d", int_values [k]) ;
for (k = 0 ; k < ARRAY_LEN (int_values) ; k++)
CMP_2_ARGS (__LINE__, errors, "int C : %- d, %- 4d", int_values [k]) ;
/* Test printing of unsigned ints. */
for (k = 0 ; k < ARRAY_LEN (int_values) ; k++)
CMP_4_ARGS (__LINE__, errors, "D : %u, %4u, %04u, %0u", int_values [k]) ;
/* Test printing of hex ints. */
for (k = 0 ; k < ARRAY_LEN (int_values) ; k++)
CMP_4_ARGS (__LINE__, errors, "E : %X, %4X, %04X, %0X", int_values [k]) ;
/* Test printing of strings. */
CMP_4_ARGS (__LINE__, errors, "B %s, %3s, %8s, %-8s", "str") ;
CMP_4_ARGS (__LINE__, errors, "B %.2s, %.8s, %-8.8s, %-4.2s", "str") ;
if (errors)
{ puts ("\nExiting due to errors.\n") ;
exit (1) ;
} ;
puts ("ok") ;
} /* test_log_printf */