diff mbox

[FFmpeg-devel] libavcodec/tests: Added test for libavcodec/avpacket.c

Message ID 1478579939-30410-1-git-send-email-thomastdt@googlemail.com
State Changes Requested
Headers show

Commit Message

Thomas Turner Nov. 8, 2016, 4:38 a.m. UTC
Signed-off-by: Thomas Turner <thomastdt@googlemail.com>
---
 libavcodec/Makefile         |   3 +-
 libavcodec/tests/avpacket.c | 134 ++++++++++++++++++++++++++++++++++++++++++++
 tests/fate/libavcodec.mak   |   5 ++
 3 files changed, 141 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/tests/avpacket.c

Comments

Michael Niedermayer Nov. 8, 2016, 1:05 p.m. UTC | #1
On Mon, Nov 07, 2016 at 08:38:59PM -0800, Thomas Turner wrote:
> Signed-off-by: Thomas Turner <thomastdt@googlemail.com>
> ---
>  libavcodec/Makefile         |   3 +-
>  libavcodec/tests/avpacket.c | 134 ++++++++++++++++++++++++++++++++++++++++++++
>  tests/fate/libavcodec.mak   |   5 ++
>  3 files changed, 141 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/tests/avpacket.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index f1d5bf1..46e3af7 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1019,7 +1019,8 @@ SKIPHEADERS-$(CONFIG_VDA)              += vda.h vda_vt_internal.h
>  SKIPHEADERS-$(CONFIG_VDPAU)            += vdpau.h vdpau_internal.h
>  SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX)     += videotoolbox.h vda_vt_internal.h
>  
> -TESTPROGS = imgconvert                                                  \
> +TESTPROGS = avpacket                                                    \
> +            imgconvert                                                  \
>              jpeg2000dwt                                                 \
>              mathops                                                    \
>              options                                                     \
> diff --git a/libavcodec/tests/avpacket.c b/libavcodec/tests/avpacket.c
> new file mode 100644
> index 0000000..4826522
> --- /dev/null
> +++ b/libavcodec/tests/avpacket.c
> @@ -0,0 +1,134 @@
> +/*
> + * 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 <stdlib.h>
> +#include <inttypes.h>
> +#include <string.h>
> +#include "libavcodec/avcodec.h"
> +#include "libavutil/error.h"
> +
> +
> +
> +static int setup_side_data_entry(AVPacket* avpkt)
> +{
> +    const uint8_t *data_name = NULL;
> +    int ret = 0, bytes;
> +    uint8_t *extra_data = NULL;
> +
> +
> +    /* get side_data_name string */
> +    data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA);
> +
> +    /* Allocate a memory bloc */
> +    bytes = strlen(data_name);
> +
> +    if(!(extra_data = av_malloc(bytes))){
> +        ret = AVERROR(ENOMEM);
> +        fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
> +        return 1;

error codes in ffmpeg are generally negative AVERROR() / AVERROR_*
while only cosmetic, i think its better to be consistent here
except where other things are needed for interfacing (like main()
return or oter APIs)


> +    }
> +    /* copy side_data_name to extra_data array */
> +    memcpy(extra_data, data_name, bytes);
> +
> +    /* create side data for AVPacket */
> +    ret = av_packet_add_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
> +                                        extra_data, bytes);
> +    if(ret < 0){
> +        fprintf(stderr,
> +                "Error occurred in av_packet_add_side_data: %s\n",
> +                av_err2str(ret));
> +        return 1;
> +    }
> +
> +    return 0;
> +}
> +
> +static int initializations(AVPacket* avpkt)
> +{

> +    static uint8_t data[] = "selftest for av_packet_clone(...)";

const static ...

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index f1d5bf1..46e3af7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1019,7 +1019,8 @@  SKIPHEADERS-$(CONFIG_VDA)              += vda.h vda_vt_internal.h
 SKIPHEADERS-$(CONFIG_VDPAU)            += vdpau.h vdpau_internal.h
 SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX)     += videotoolbox.h vda_vt_internal.h
 
-TESTPROGS = imgconvert                                                  \
+TESTPROGS = avpacket                                                    \
+            imgconvert                                                  \
             jpeg2000dwt                                                 \
             mathops                                                    \
             options                                                     \
diff --git a/libavcodec/tests/avpacket.c b/libavcodec/tests/avpacket.c
new file mode 100644
index 0000000..4826522
--- /dev/null
+++ b/libavcodec/tests/avpacket.c
@@ -0,0 +1,134 @@ 
+/*
+ * 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 <stdlib.h>
+#include <inttypes.h>
+#include <string.h>
+#include "libavcodec/avcodec.h"
+#include "libavutil/error.h"
+
+
+
+static int setup_side_data_entry(AVPacket* avpkt)
+{
+    const uint8_t *data_name = NULL;
+    int ret = 0, bytes;
+    uint8_t *extra_data = NULL;
+
+
+    /* get side_data_name string */
+    data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA);
+
+    /* Allocate a memory bloc */
+    bytes = strlen(data_name);
+
+    if(!(extra_data = av_malloc(bytes))){
+        ret = AVERROR(ENOMEM);
+        fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
+        return 1;
+    }
+    /* copy side_data_name to extra_data array */
+    memcpy(extra_data, data_name, bytes);
+
+    /* create side data for AVPacket */
+    ret = av_packet_add_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
+                                        extra_data, bytes);
+    if(ret < 0){
+        fprintf(stderr,
+                "Error occurred in av_packet_add_side_data: %s\n",
+                av_err2str(ret));
+        return 1;
+    }
+
+    return 0;
+}
+
+static int initializations(AVPacket* avpkt)
+{
+    static uint8_t data[] = "selftest for av_packet_clone(...)";
+    int ret = 0;
+
+    /* initialize avpkt */
+    av_init_packet(avpkt);
+
+    /* set values for avpkt */
+    avpkt->pts = 17;
+    avpkt->dts = 2;
+    avpkt->data = data;
+    avpkt->size = strlen(data);
+    avpkt->flags = AV_PKT_FLAG_DISCARD;
+    avpkt->duration = 100;
+    avpkt->pos = 3;
+
+    if(setup_side_data_entry(avpkt))
+        ret = 1;
+
+    return ret;
+}
+
+int main(void)
+{
+    AVPacket avpkt;
+    AVPacket *avpkt_clone = NULL;
+    int ret = 0;
+
+    if(initializations(&avpkt)){
+        printf("failed to initialize variables\n");
+        return 1;
+    }
+
+    /* test av_packet_clone*/
+    avpkt_clone = av_packet_clone(&avpkt);
+
+    if(!avpkt_clone) {
+        av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n");
+        return 1;
+    }
+    /* test size error check in av_new_packet*/
+    if(av_new_packet(avpkt_clone, INT_MAX) == 0){
+        printf( "av_new_packet failed to return error "
+                "when \"size\" parameter is too large.\n" );
+        ret = 1;
+    }
+
+    /*test av_grow_packet*/
+    if(av_grow_packet(avpkt_clone, INT_MAX) == 0){
+        printf( "av_grow_packet failed to return error "
+                "when \"grow_by\" parameter is too large.\n" );
+        ret = 1;
+    }
+    if(av_grow_packet(avpkt_clone, 20) < 0){
+        av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n");
+        return 1;
+    }
+
+    /*test av_packet_from_data*/
+    if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){
+        printf("av_packet_from_data failed to return error "
+                "when \"size\" parameter is too large.\n" );
+        ret = 1;
+    }
+
+    /*clean up*/
+    av_packet_free(&avpkt_clone);
+    av_packet_unref(&avpkt);
+
+
+    return ret;
+}
diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
index cf25285..3bc74c1 100644
--- a/tests/fate/libavcodec.mak
+++ b/tests/fate/libavcodec.mak
@@ -1,3 +1,8 @@ 
+FATE_LIBAVCODEC-yes += fate-avpacket
+fate-avpacket: libavcodec/tests/avpacket$(EXESUF)
+fate-avpacket: CMD = run libavcodec/tests/avpacket
+fate-avpacket: REF = /dev/null
+
 FATE_LIBAVCODEC-$(CONFIG_CABAC) += fate-cabac
 fate-cabac: libavcodec/tests/cabac$(EXESUF)
 fate-cabac: CMD = run libavcodec/tests/cabac