3 * unit test for adapter
5 * Copyright (C) <2005> Wim Taymans <wim at fluendo dot com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
25 #include <gst/base/gstadapter.h>
27 /* does some implementation dependent checking that should
32 * Start peeking on an adapter with 1 buffer pushed.
34 GST_START_TEST (test_peek1)
39 const guint8 *bufdata, *data1, *data2;
41 adapter = gst_adapter_new ();
42 fail_if (adapter == NULL);
44 /* push single buffer in adapter */
45 buffer = gst_buffer_new_and_alloc (512);
46 bufdata = GST_BUFFER_DATA (buffer);
48 fail_if (buffer == NULL);
49 gst_adapter_push (adapter, buffer);
51 /* available and available_fast should return the size of the
53 avail = gst_adapter_available (adapter);
54 fail_if (avail != 512);
55 avail = gst_adapter_available_fast (adapter);
56 fail_if (avail != 512);
58 /* should g_critical with NULL as result */
59 ASSERT_CRITICAL (data1 = gst_adapter_peek (adapter, 0));
60 fail_if (data1 != NULL);
62 /* should return NULL as result */
63 data1 = gst_adapter_peek (adapter, 513);
64 fail_if (data1 != NULL);
66 /* this should work */
67 data1 = gst_adapter_peek (adapter, 512);
68 fail_if (data1 == NULL);
69 /* it should point to the buffer data as well */
70 fail_if (data1 != bufdata);
71 data2 = gst_adapter_peek (adapter, 512);
72 fail_if (data2 == NULL);
73 /* second peek should return the same pointer */
74 fail_if (data2 != data1);
76 /* this should fail since we don't have that many bytes */
77 ASSERT_CRITICAL (gst_adapter_flush (adapter, 513));
79 /* this should work fine */
80 gst_adapter_flush (adapter, 10);
82 /* see if we have 10 bytes less available */
83 avail = gst_adapter_available (adapter);
84 fail_if (avail != 502);
85 avail = gst_adapter_available_fast (adapter);
86 fail_if (avail != 502);
88 /* should return NULL as result */
89 data2 = gst_adapter_peek (adapter, 503);
90 fail_if (data2 != NULL);
92 /* should work fine */
93 data2 = gst_adapter_peek (adapter, 502);
94 fail_if (data2 == NULL);
95 /* peek should return the same old pointer + 10 */
96 fail_if (data2 != data1 + 10);
97 fail_if (data2 != bufdata + 10);
100 gst_adapter_flush (adapter, 500);
102 /* see if we have 2 bytes available */
103 avail = gst_adapter_available (adapter);
104 fail_if (avail != 2);
105 avail = gst_adapter_available_fast (adapter);
106 fail_if (avail != 2);
108 data2 = gst_adapter_peek (adapter, 2);
109 fail_if (data2 == NULL);
110 fail_if (data2 != data1 + 510);
111 fail_if (data2 != bufdata + 510);
113 /* flush some more */
114 gst_adapter_flush (adapter, 2);
116 /* see if we have 0 bytes available */
117 avail = gst_adapter_available (adapter);
118 fail_if (avail != 0);
119 avail = gst_adapter_available_fast (adapter);
120 fail_if (avail != 0);
122 /* silly clear just for fun */
123 gst_adapter_clear (adapter);
125 g_object_unref (adapter);
130 /* Start peeking on an adapter with 2 non-mergeable buffers
133 GST_START_TEST (test_peek2)
139 /* Start peeking on an adapter with 2 mergeable buffers
142 GST_START_TEST (test_peek3)
148 /* take data from an adapter with 1 buffer pushed.
150 GST_START_TEST (test_take1)
153 GstBuffer *buffer, *buffer2;
155 guint8 *data, *data2;
157 adapter = gst_adapter_new ();
158 fail_unless (adapter != NULL);
160 buffer = gst_buffer_new_and_alloc (100);
161 fail_unless (buffer != NULL);
162 fail_unless (GST_BUFFER_DATA (buffer) != NULL);
163 fail_unless (GST_BUFFER_SIZE (buffer) == 100);
165 data = GST_BUFFER_DATA (buffer);
167 /* push in the adapter */
168 gst_adapter_push (adapter, buffer);
170 avail = gst_adapter_available (adapter);
171 fail_unless (avail == 100);
173 /* take out buffer */
174 buffer2 = gst_adapter_take_buffer (adapter, 100);
175 fail_unless (buffer2 != NULL);
176 fail_unless (GST_BUFFER_DATA (buffer2) != NULL);
177 fail_unless (GST_BUFFER_SIZE (buffer2) == 100);
178 data2 = GST_BUFFER_DATA (buffer2);
180 avail = gst_adapter_available (adapter);
181 fail_unless (avail == 0);
183 /* the buffer should be the same */
184 fail_unless (buffer == buffer2);
185 fail_unless (data == data2);
187 gst_buffer_unref (buffer2);
189 g_object_unref (adapter);
194 /* take data from an adapter with 2 non-mergeable buffers
197 GST_START_TEST (test_take2)
203 /* take data from an adapter with 2 mergeable buffers
206 GST_START_TEST (test_take3)
209 GstBuffer *buffer, *buffer2;
211 guint8 *data, *data2;
213 adapter = gst_adapter_new ();
214 fail_unless (adapter != NULL);
216 buffer = gst_buffer_new_and_alloc (100);
217 fail_unless (buffer != NULL);
218 fail_unless (GST_BUFFER_DATA (buffer) != NULL);
219 fail_unless (GST_BUFFER_SIZE (buffer) == 100);
221 data = GST_BUFFER_DATA (buffer);
223 /* set up and push subbuffers */
224 buffer2 = gst_buffer_create_sub (buffer, 0, 25);
225 gst_adapter_push (adapter, buffer2);
226 buffer2 = gst_buffer_create_sub (buffer, 25, 25);
227 gst_adapter_push (adapter, buffer2);
228 buffer2 = gst_buffer_create_sub (buffer, 50, 25);
229 gst_adapter_push (adapter, buffer2);
230 buffer2 = gst_buffer_create_sub (buffer, 75, 25);
231 gst_adapter_push (adapter, buffer2);
233 gst_buffer_unref (buffer);
235 avail = gst_adapter_available (adapter);
236 fail_unless (avail == 100);
238 /* take out buffer */
239 buffer2 = gst_adapter_take_buffer (adapter, 100);
240 fail_unless (buffer2 != NULL);
241 fail_unless (GST_BUFFER_DATA (buffer2) != NULL);
242 fail_unless (GST_BUFFER_SIZE (buffer2) == 100);
243 data2 = GST_BUFFER_DATA (buffer2);
245 avail = gst_adapter_available (adapter);
246 fail_unless (avail == 0);
248 /* the data should be the same */
249 fail_unless (data == data2);
251 gst_buffer_unref (buffer2);
253 g_object_unref (adapter);
259 create_and_fill_adapter (void)
264 adapter = gst_adapter_new ();
265 fail_unless (adapter != NULL);
267 for (i = 0; i < 10000; i += 4) {
268 GstBuffer *buf = gst_buffer_new_and_alloc (sizeof (guint32) * 4);
271 fail_unless (buf != NULL);
272 data = GST_BUFFER_DATA (buf);
274 for (j = 0; j < 4; j++) {
275 GST_WRITE_UINT32_LE (data, i + j);
276 data += sizeof (guint32);
278 gst_adapter_push (adapter, buf);
284 /* Fill a buffer with a sequence of 32 bit ints and read them back out,
285 * checking that they're still in the right order */
286 GST_START_TEST (test_take_order)
291 adapter = create_and_fill_adapter ();
292 while (gst_adapter_available (adapter) >= sizeof (guint32)) {
293 guint8 *data = gst_adapter_take (adapter, sizeof (guint32));
295 fail_unless (GST_READ_UINT32_LE (data) == i);
299 fail_unless (gst_adapter_available (adapter) == 0,
300 "Data was left in the adapter");
302 g_object_unref (adapter);
307 /* Fill a buffer with a sequence of 32 bit ints and read them back out
308 * using take_buffer, checking that they're still in the right order */
309 GST_START_TEST (test_take_buf_order)
314 adapter = create_and_fill_adapter ();
315 while (gst_adapter_available (adapter) >= sizeof (guint32)) {
316 GstBuffer *buf = gst_adapter_take_buffer (adapter, sizeof (guint32));
318 fail_unless (GST_READ_UINT32_LE (GST_BUFFER_DATA (buf)) == i);
321 gst_buffer_unref (buf);
323 fail_unless (gst_adapter_available (adapter) == 0,
324 "Data was left in the adapter");
326 g_object_unref (adapter);
331 GST_START_TEST (test_timestamp)
336 GstClockTime timestamp;
341 adapter = gst_adapter_new ();
342 fail_unless (adapter != NULL);
344 buffer = gst_buffer_new_and_alloc (100);
346 /* push in the adapter */
347 gst_adapter_push (adapter, buffer);
348 avail = gst_adapter_available (adapter);
349 fail_unless (avail == 100);
351 /* timestamp is now undefined */
352 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
353 fail_unless (timestamp == GST_CLOCK_TIME_NONE);
354 fail_unless (dist == 0);
356 gst_adapter_flush (adapter, 50);
357 avail = gst_adapter_available (adapter);
358 fail_unless (avail == 50);
360 /* still undefined, dist changed, though */
361 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
362 fail_unless (timestamp == GST_CLOCK_TIME_NONE);
363 fail_unless (dist == 50);
365 buffer = gst_buffer_new_and_alloc (100);
366 GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
368 /* push in the adapter */
369 gst_adapter_push (adapter, buffer);
370 avail = gst_adapter_available (adapter);
371 fail_unless (avail == 150);
373 /* timestamp is still undefined */
374 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
375 fail_unless (timestamp == GST_CLOCK_TIME_NONE);
376 fail_unless (dist == 50);
378 /* flush out first buffer we are now at the second buffer timestamp */
379 gst_adapter_flush (adapter, 50);
380 avail = gst_adapter_available (adapter);
381 fail_unless (avail == 100);
383 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
384 fail_unless (timestamp == 1 * GST_SECOND);
385 fail_unless (dist == 0);
387 /* move some more, still the same timestamp but further away */
388 gst_adapter_flush (adapter, 50);
389 avail = gst_adapter_available (adapter);
390 fail_unless (avail == 50);
392 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
393 fail_unless (timestamp == 1 * GST_SECOND);
394 fail_unless (dist == 50);
396 /* push a buffer without timestamp in the adapter */
397 buffer = gst_buffer_new_and_alloc (100);
398 gst_adapter_push (adapter, buffer);
399 avail = gst_adapter_available (adapter);
400 fail_unless (avail == 150);
401 /* push a buffer with timestamp in the adapter */
402 buffer = gst_buffer_new_and_alloc (100);
403 GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
404 gst_adapter_push (adapter, buffer);
405 avail = gst_adapter_available (adapter);
406 fail_unless (avail == 250);
408 /* timestamp still as it was before the push */
409 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
410 fail_unless (timestamp == 1 * GST_SECOND);
411 fail_unless (dist == 50);
413 /* flush away buffer with the timestamp */
414 gst_adapter_flush (adapter, 50);
415 avail = gst_adapter_available (adapter);
416 fail_unless (avail == 200);
417 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
418 fail_unless (timestamp == 1 * GST_SECOND);
419 fail_unless (dist == 100);
421 /* move into the second buffer */
422 gst_adapter_flush (adapter, 50);
423 avail = gst_adapter_available (adapter);
424 fail_unless (avail == 150);
425 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
426 fail_unless (timestamp == 1 * GST_SECOND);
427 fail_unless (dist == 150);
429 /* move to third buffer we move to the new timestamp */
430 gst_adapter_flush (adapter, 50);
431 avail = gst_adapter_available (adapter);
432 fail_unless (avail == 100);
433 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
434 fail_unless (timestamp == 2 * GST_SECOND);
435 fail_unless (dist == 0);
437 /* move everything out */
438 gst_adapter_flush (adapter, 100);
439 avail = gst_adapter_available (adapter);
440 fail_unless (avail == 0);
441 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
442 fail_unless (timestamp == 2 * GST_SECOND);
443 fail_unless (dist == 100);
445 /* clear everything */
446 gst_adapter_clear (adapter);
447 avail = gst_adapter_available (adapter);
448 fail_unless (avail == 0);
449 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
450 fail_unless (timestamp == GST_CLOCK_TIME_NONE);
451 fail_unless (dist == 0);
453 /* push an empty buffer with timestamp in the adapter */
454 buffer = gst_buffer_new ();
455 GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
456 gst_adapter_push (adapter, buffer);
457 avail = gst_adapter_available (adapter);
458 fail_unless (avail == 0);
459 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
460 fail_unless (timestamp == 2 * GST_SECOND);
461 fail_unless (dist == 0);
463 /* push another empty buffer */
464 buffer = gst_buffer_new ();
465 GST_BUFFER_TIMESTAMP (buffer) = 3 * GST_SECOND;
466 gst_adapter_push (adapter, buffer);
467 avail = gst_adapter_available (adapter);
468 fail_unless (avail == 0);
469 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
470 fail_unless (timestamp == 2 * GST_SECOND);
471 fail_unless (dist == 0);
473 /* push a buffer with timestamp in the adapter */
474 buffer = gst_buffer_new_and_alloc (100);
475 GST_BUFFER_TIMESTAMP (buffer) = 4 * GST_SECOND;
476 gst_adapter_push (adapter, buffer);
477 avail = gst_adapter_available (adapter);
478 fail_unless (avail == 100);
479 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
480 fail_unless (timestamp == 2 * GST_SECOND);
481 fail_unless (dist == 0);
483 gst_adapter_flush (adapter, 1);
484 avail = gst_adapter_available (adapter);
485 fail_unless (avail == 99);
486 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
487 fail_unless (timestamp == 4 * GST_SECOND);
488 fail_unless (dist == 1);
490 /* push an empty buffer with timestamp in the adapter */
491 buffer = gst_buffer_new ();
492 GST_BUFFER_TIMESTAMP (buffer) = 5 * GST_SECOND;
493 gst_adapter_push (adapter, buffer);
494 avail = gst_adapter_available (adapter);
495 fail_unless (avail == 99);
496 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
497 fail_unless (timestamp == 4 * GST_SECOND);
498 fail_unless (dist == 1);
500 /* push buffer without timestamp */
501 buffer = gst_buffer_new_and_alloc (100);
502 gst_adapter_push (adapter, buffer);
503 avail = gst_adapter_available (adapter);
504 fail_unless (avail == 199);
505 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
506 fail_unless (timestamp == 4 * GST_SECOND);
507 fail_unless (dist == 1);
509 /* remove first buffer, timestamp of empty buffer is visible */
510 buffer = gst_adapter_take_buffer (adapter, 99);
511 fail_unless (buffer != NULL);
512 fail_unless (GST_BUFFER_SIZE (buffer) == 99);
513 gst_buffer_unref (buffer);
514 avail = gst_adapter_available (adapter);
515 fail_unless (avail == 100);
516 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
517 fail_unless (timestamp == 5 * GST_SECOND);
518 fail_unless (dist == 0);
520 /* remove empty buffer, timestamp still visible */
521 cdata = gst_adapter_peek (adapter, 50);
522 fail_unless (cdata != NULL);
523 data = gst_adapter_take (adapter, 50);
524 fail_unless (data != NULL);
526 avail = gst_adapter_available (adapter);
527 fail_unless (avail == 50);
528 timestamp = gst_adapter_prev_timestamp (adapter, &dist);
529 fail_unless (timestamp == 5 * GST_SECOND);
530 fail_unless (dist == 50);
532 g_object_unref (adapter);
537 GST_START_TEST (test_scan)
545 adapter = gst_adapter_new ();
546 fail_unless (adapter != NULL);
548 buffer = gst_buffer_new_and_alloc (100);
549 data = GST_BUFFER_DATA (buffer);
550 /* fill with pattern */
551 for (i = 0; i < 100; i++)
554 gst_adapter_push (adapter, buffer);
556 /* find first bytes */
558 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 0, 100);
559 fail_unless (offset == 0);
561 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x01020304, 0, 100);
562 fail_unless (offset == 1);
564 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x01020304, 1, 99);
565 fail_unless (offset == 1);
566 /* offset is past the pattern start */
568 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x01020304, 2, 98);
569 fail_unless (offset == -1);
570 /* not enough bytes to find the pattern */
572 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x02030405, 2, 3);
573 fail_unless (offset == -1);
575 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x02030405, 2, 4);
576 fail_unless (offset == 2);
577 /* size does not include the last scanned byte */
579 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x40414243, 0, 0x41);
580 fail_unless (offset == -1);
582 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x40414243, 0, 0x43);
583 fail_unless (offset == -1);
585 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x40414243, 0, 0x44);
586 fail_unless (offset == 0x40);
589 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x40414243, 65, 10);
590 fail_unless (offset == -1);
592 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x40414243, 64, 5);
593 fail_unless (offset == 64);
595 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x60616263, 65, 35);
596 fail_unless (offset == 0x60);
598 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x60616263, 0x60, 4);
599 fail_unless (offset == 0x60);
602 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x60616263, 0x61, 3);
603 fail_unless (offset == -1);
606 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x60616263, 99, 1);
607 fail_unless (offset == -1);
609 /* add another buffer */
610 buffer = gst_buffer_new_and_alloc (100);
611 data = GST_BUFFER_DATA (buffer);
612 /* fill with pattern */
613 for (i = 0; i < 100; i++)
616 gst_adapter_push (adapter, buffer);
620 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x60616263, 0x61, 6);
621 fail_unless (offset == -1);
622 /* this should work */
624 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x61626364, 0x61, 4);
625 fail_unless (offset == 0x61);
626 /* not enough data */
628 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x62636465, 0x61, 4);
629 fail_unless (offset == -1);
631 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x62636465, 0x61, 5);
632 fail_unless (offset == 0x62);
634 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x62636465, 0, 120);
635 fail_unless (offset == 0x62);
637 /* border conditions */
639 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x62636465, 0, 200);
640 fail_unless (offset == 0x62);
642 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x63646566, 0, 200);
643 fail_unless (offset == 0x63);
644 /* we completely searched the first list */
646 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x64656667, 0, 200);
647 fail_unless (offset == 0x64);
648 /* skip first buffer */
650 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x64656667, 0x64,
652 fail_unless (offset == 0x64);
655 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x64656667, 0x65,
657 fail_unless (offset == -1);
658 /* not enough data to scan */
660 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x64656667, 0x63, 4);
661 fail_unless (offset == -1);
663 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x64656667, 0x63, 5);
664 fail_unless (offset == 0x64);
666 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0xc4c5c6c7, 0, 199);
667 fail_unless (offset == -1);
669 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0xc4c5c6c7, 0x62,
671 fail_unless (offset == 0xc4);
672 /* different masks */
674 gst_adapter_masked_scan_uint32 (adapter, 0x00ffffff, 0x00656667, 0x64,
676 fail_unless (offset == 0x64);
678 gst_adapter_masked_scan_uint32 (adapter, 0x000000ff, 0x00000000, 0, 100);
679 fail_unless (offset == -1);
681 gst_adapter_masked_scan_uint32 (adapter, 0x000000ff, 0x00000003, 0, 100);
682 fail_unless (offset == 0);
684 gst_adapter_masked_scan_uint32 (adapter, 0x000000ff, 0x00000061, 0x61,
686 fail_unless (offset == -1);
688 gst_adapter_masked_scan_uint32 (adapter, 0xff000000, 0x61000000, 0, 0x62);
689 fail_unless (offset == -1);
690 /* does not even exist */
691 ASSERT_CRITICAL (offset =
692 gst_adapter_masked_scan_uint32 (adapter, 0x00ffffff, 0xffffffff, 0x65,
694 fail_unless (offset == -1);
696 /* flush some bytes */
697 gst_adapter_flush (adapter, 0x20);
700 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x20212223, 0, 100);
701 fail_unless (offset == 0);
703 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x20212223, 0, 4);
704 fail_unless (offset == 0);
706 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0xc4c5c6c7, 0x62,
708 fail_unless (offset == 0xa4);
710 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0xc4c5c6c7, 0, 168);
711 fail_unless (offset == 0xa4);
714 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0xc4c5c6c7, 164, 4);
715 fail_unless (offset == 0xa4);
717 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0xc4c5c6c7, 0x44,
719 fail_unless (offset == 0xa4);
720 /* not enough bytes */
722 gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0xc4c5c6c7, 0x44,
724 fail_unless (offset == -1);
726 g_object_unref (adapter);
731 /* Fill a buffer with a sequence of 32 bit ints and read them back out
732 * using take_buffer, checking that they're still in the right order */
733 GST_START_TEST (test_take_list)
738 adapter = create_and_fill_adapter ();
739 while (gst_adapter_available (adapter) >= sizeof (guint32)) {
745 list = gst_adapter_take_list (adapter, sizeof (guint32) * 5);
746 fail_unless (list != NULL);
748 for (walk = list; walk; walk = g_list_next (walk)) {
750 data = GST_BUFFER_DATA (buf);
751 size = GST_BUFFER_SIZE (buf);
754 fail_unless (GST_READ_UINT32_LE (data) == i);
756 data += sizeof (guint32);
757 size -= sizeof (guint32);
759 gst_buffer_unref (buf);
763 fail_unless (gst_adapter_available (adapter) == 0,
764 "Data was left in the adapter");
766 g_object_unref (adapter);
772 gst_adapter_suite (void)
774 Suite *s = suite_create ("adapter");
775 TCase *tc_chain = tcase_create ("general");
777 suite_add_tcase (s, tc_chain);
778 tcase_add_test (tc_chain, test_peek1);
779 tcase_add_test (tc_chain, test_peek2);
780 tcase_add_test (tc_chain, test_peek3);
781 tcase_add_test (tc_chain, test_take1);
782 tcase_add_test (tc_chain, test_take2);
783 tcase_add_test (tc_chain, test_take3);
784 tcase_add_test (tc_chain, test_take_order);
785 tcase_add_test (tc_chain, test_take_buf_order);
786 tcase_add_test (tc_chain, test_timestamp);
787 tcase_add_test (tc_chain, test_scan);
788 tcase_add_test (tc_chain, test_take_list);
793 GST_CHECK_MAIN (gst_adapter);