History

tests/callback_test.c : Add a callback test where the callback returns a zero count without setting the data pointer. The problem can only be detected when run under valgrind.

Erik de Castro Lopo committed 18 years ago

Commit 53b18bf1 parent 0964cf62 files · +104 −0Browse files

Unified · Split

2 files
  1. ChangeLog +4 −0
  2. tests/callback_test.c +100 −0
ChangeLog+4−0
@@ -4,6 +4,10 @@ · 3 unmodified lines
44 Fix a valgrind warning which occured when the call back function returns
55 a count of zero without modifying the pointer value. Thanks to Paul Kelly.
66
7+ * tests/callback_test.c
8+ Add a callback test where the callback returns a zero count without setting
9+ the data pointer. The problem can only be detected when run under valgrind.
10+
711 2008-07-09 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
812
913 * src/src_sinc.c
tests/callback_test.c+100−0
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 #define CB_READ_LEN 256
3030
3131 static void callback_test (int converter, double ratio) ;
32+static void end_of_stream_test (int converter) ;
3233
3334 int
3435 main (void)
@@ -54,6 +55,12 @@ main (void) · 19 unmodified lines
5455
5556 puts ("") ;
5657
58+ puts (" End of stream test :") ;
59+ end_of_stream_test (SRC_ZERO_ORDER_HOLD) ;
60+ end_of_stream_test (SRC_LINEAR) ;
61+ end_of_stream_test (SRC_SINC_FASTEST) ;
62+
63+ puts ("") ;
5764 return 0 ;
5865 } /* main */
5966
@@ -63,6 +70,7 @@ main (void) · 3 unmodified lines
6370 typedef struct
6471 { int channels ;
6572 long count, total ;
73+ int end_of_data ;
6674 float data [BUFFER_LEN] ;
6775 } TEST_CB_DATA ;
6876
@@ -105,6 +113,7 @@ callback_test (int converter, double src_ratio) · 36 unmodified lines
105113
106114 test_callback_data.channels = 2 ;
107115 test_callback_data.count = 0 ;
116+ test_callback_data.end_of_data = 0 ;
108117 test_callback_data.total = ARRAY_LEN (test_callback_data.data) ;
109118
110119 if ((src_state = src_callback_new (test_callback_func, converter, test_callback_data.channels, &error, &test_callback_data)) == NULL)
@@ -141,3 +150,94 @@ callback_test (int converter, double src_ratio) · 30 unmodified lines
141150 return ;
142151 } /* callback_test */
143152
153+/*=====================================================================================
154+*/
155+
156+static long
157+eos_callback_func (void *cb_data, float **data)
158+{
159+ TEST_CB_DATA *pcb_data ;
160+ long frames ;
161+
162+ if (data == NULL)
163+ return 0 ;
164+
165+ if ((pcb_data = cb_data) == NULL)
166+ return 0 ;
167+
168+ /*
169+ ** Return immediately if there is no more data.
170+ ** In this case, the output pointer 'data' will not be set and
171+ ** valgrind should not warn about it.
172+ */
173+ if (pcb_data->end_of_data)
174+ return 0 ;
175+
176+ if (pcb_data->total - pcb_data->count > CB_READ_LEN)
177+ frames = CB_READ_LEN / pcb_data->channels ;
178+ else
179+ frames = (pcb_data->total - pcb_data->count) / pcb_data->channels ;
180+
181+ *data = pcb_data->data + pcb_data->count ;
182+ pcb_data->count += frames ;
183+
184+ /*
185+ ** Set end_of_data so that the next call to the callback function will
186+ ** return zero ocunt without setting the 'data' pointer.
187+ */
188+ if (pcb_data->total < 2 * pcb_data->count)
189+ pcb_data->end_of_data = 1 ;
190+
191+ return frames ;
192+} /* eos_callback_data */
193+
194+
195+static void
196+end_of_stream_test (int converter)
197+{ static TEST_CB_DATA test_callback_data ;
198+ static float output [BUFFER_LEN] ;
199+
200+ SRC_STATE *src_state ;
201+
202+ double src_ratio = 0.3 ;
203+ long read_count, read_total ;
204+ int error ;
205+
206+ printf ("\t%-30s ........... ", src_get_name (converter)) ;
207+ fflush (stdout) ;
208+
209+ test_callback_data.channels = 2 ;
210+ test_callback_data.count = 0 ;
211+ test_callback_data.end_of_data = 0 ;
212+ test_callback_data.total = ARRAY_LEN (test_callback_data.data) ;
213+
214+ if ((src_state = src_callback_new (eos_callback_func, converter, test_callback_data.channels, &error, &test_callback_data)) == NULL)
215+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
216+ exit (1) ;
217+ } ;
218+
219+ read_total = 0 ;
220+ do
221+ { /* We will be throwing away output data, so just grab as much as possible. */
222+ read_count = ARRAY_LEN (output) / test_callback_data.channels ;
223+ read_count = src_callback_read (src_state, src_ratio, read_count, output) ;
224+ read_total += read_count ;
225+ }
226+ while (read_count > 0) ;
227+
228+ if ((error = src_error (src_state)) != 0)
229+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
230+ exit (1) ;
231+ } ;
232+
233+ src_state = src_delete (src_state) ;
234+
235+ if (test_callback_data.end_of_data == 0)
236+ { printf ("\n\nLine %d : test_callback_data.end_of_data should not be 0."
237+ " This is a bug in the test.\n\n", __LINE__) ;
238+ exit (1) ;
239+ } ;
240+
241+ puts ("ok") ;
242+ return ;
243+} /* end_of_stream_test */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t