diff mbox

[FFmpeg-devel,1/3] Improve selftest coverage for libavutil library

Message ID 1476158213-7542-1-git-send-email-thomastdt@gmail.com
State Changes Requested
Headers show

Commit Message

Thomas Turner Oct. 11, 2016, 3:56 a.m. UTC
Code coverage for av_fifo_generic_peek(...) and av_fifo_grow(...) .
---
 libavutil/tests/fifo2.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 libavutil/tests/fifo2.c

Comments

Michael Niedermayer Oct. 12, 2016, 6:38 p.m. UTC | #1
On Mon, Oct 10, 2016 at 08:56:51PM -0700, Thomas Turner wrote:
> Code coverage for av_fifo_generic_peek(...) and av_fifo_grow(...) .
> ---
>  libavutil/tests/fifo2.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 77 insertions(+)
>  create mode 100644 libavutil/tests/fifo2.c
> 
> diff --git a/libavutil/tests/fifo2.c b/libavutil/tests/fifo2.c
> new file mode 100644
> index 0000000..923feee
> --- /dev/null
> +++ b/libavutil/tests/fifo2.c

We generally put all tests for "something" into the same file
these could be put into fifo.c
[...]

> +    data_arr = (int32_t*)malloc(fifo_size);

the cast is unneeded in C

also please dont add code that is changed in the immedeatly next patch
that makes review difficult

thx

[...]
diff mbox

Patch

diff --git a/libavutil/tests/fifo2.c b/libavutil/tests/fifo2.c
new file mode 100644
index 0000000..923feee
--- /dev/null
+++ b/libavutil/tests/fifo2.c
@@ -0,0 +1,77 @@ 
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+#include "libavutil/fifo.h"
+
+
+
+int main(void)
+{
+
+    int16_t offset, fifo_size, space_size, data_size;
+    int32_t data, *data_arr;
+    int32_t elem[] = {0, 2, 4, 6, 8, 10, 12};
+    AVFifoBuffer* fifo;
+
+    data_size = sizeof(elem[0]);
+    fifo = av_fifo_alloc(sizeof(elem));
+
+    /*fill fifo buffer*/
+
+    if (av_fifo_generic_write(fifo, (void*)elem, av_fifo_space(fifo), NULL) != sizeof(elem)) {
+
+        fprintf(stderr, "written incorrect number of bytes\n");
+        return 1;
+    }
+
+
+    /* generic peek at fifo */
+
+    fifo_size = av_fifo_size(fifo);
+    data_arr = (int32_t*)malloc(fifo_size);
+
+    (void) av_fifo_generic_peek(fifo, data_arr, fifo_size, NULL);
+
+    printf("fifo->buffer: ");
+    for(offset = 0; offset < fifo_size/data_size; ++offset){
+        printf("%" PRId32 ", ", data_arr[offset]);
+    }
+
+    space_size = av_fifo_space(fifo);
+    printf("\nspace before av_fifo_grow\t:%" PRId16 "\n", space_size);
+
+    /* grow AVFifoBuffer */
+
+    data = av_fifo_grow(fifo, data_size);
+    if(data < 0)
+        printf("\n%s\n", "failure growing fifo\n");
+
+
+    space_size = av_fifo_space(fifo);
+    printf("space after av_fifo_grow\t:%" PRId16 "\n", space_size);
+
+    
+    /* free AVFifoBuffer and data_arr */
+
+    av_fifo_free(fifo);
+    free(data_arr);
+
+    return 0;
+}