From patchwork Tue Dec 6 06:22:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Turner X-Patchwork-Id: 1696 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.86 with SMTP id o83csp2016897vsa; Mon, 5 Dec 2016 22:35:43 -0800 (PST) X-Received: by 10.28.126.146 with SMTP id z140mr1255001wmc.84.1481006143081; Mon, 05 Dec 2016 22:35:43 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m7si18332227wjg.231.2016.12.05.22.35.42; Mon, 05 Dec 2016 22:35:43 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 205DE689D75; Tue, 6 Dec 2016 08:35:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f66.google.com (mail-oi0-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D55F0689B0A for ; Tue, 6 Dec 2016 08:35:21 +0200 (EET) Received: by mail-oi0-f66.google.com with SMTP id u15so39931273oie.3 for ; Mon, 05 Dec 2016 22:35:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:subject:date:message-id; bh=PfKNhFY3mG6Jryhf5IIgVMqsokx6mynV8Rd/PQTsgtQ=; b=nwV0OuqkLuWTwkbpICSk2C1u6vWlE9mL3g3vMzExXax5CBySAPPwn/SSMBUAgrXBgj vnRfXL7F5jP75qlpVsPsZgxlfmHbvYQBUT/VFm8V9egPyBEaJhm1qV6nrKnupn5g2aaW j3X0MiB+ZWmmxCcGdNkh/8wBI9hVJUMm8xzKk/Yqn4DYW+nPfdJTnnmqqC70Xl3+n6Wu ClQPuN2CiBCZuZ/93Zb07/md/jVI/1yYMQHjFcsLvn1YemEYQ0TouMbiVrhuJKb0voxc b6//4qcxB+i27mPoh6qc6mrXFm+F+Qj8j4BAtWFfL0sRqTnBac3wt/xsh26iz/xVkqH8 +UDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=PfKNhFY3mG6Jryhf5IIgVMqsokx6mynV8Rd/PQTsgtQ=; b=e8YUnq4HHld0861oVaf/yAT547lwvEJObggDy2bljEgxIs/k0UgrjXPZFmyL94M/om 5xQqha4+p/OBn22be+At2plCYJOuzR1W6FkF6YIFNRKRXdASy+9Hv3M0OFTI662Sn12q k2fj9SnT+ukY0G1mNe5fC7TsE4/FZr2yCN0H0Yg7AdnNlZkmrK2Us68b2xUdjzfCAzeR 0zXGnCN+CbsaP9qAbLjpMswbm6SJ7pm0KuFIyW09FJ5FjGSrUMkmanJ88VsaaUIXLAAw wpyh/gpLBCMRwe9SZBmDCm+Z6RbcNypEHDQkw/ZRDjtYEnbt5RxrokmZKpiYf3FizW9M hCPQ== X-Gm-Message-State: AKaTC00kW9mwGue2iO+HjNCupyg403mlbmTigZ8cInFtxh7sahxwNuQqG4RFtQ3JLHvZUA== X-Received: by 10.157.52.118 with SMTP id v109mr31829582otb.125.1481005364168; Mon, 05 Dec 2016 22:22:44 -0800 (PST) Received: from Zany.attlocal.net (76-252-225-111.lightspeed.sndgca.sbcglobal.net. [76.252.225.111]) by smtp.gmail.com with ESMTPSA id c8sm7224673oia.14.2016.12.05.22.22.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Dec 2016 22:22:43 -0800 (PST) From: Thomas Turner To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Dec 2016 22:22:41 -0800 Message-Id: <1481005361-4060-1-git-send-email-thomastdt@googlemail.com> X-Mailer: git-send-email 1.9.1 Subject: [FFmpeg-devel] [PATCH] Added test for libavcodec/avpacket.c X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Thomas Turner --- libavcodec/Makefile | 3 +- libavcodec/tests/avpacket.c | 128 ++++++++++++++++++++++++++++++++++++++++++++ tests/fate/libavcodec.mak | 5 ++ 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 libavcodec/tests/avpacket.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 82f7fa2..6dd294e 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1003,7 +1003,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..90b7234 --- /dev/null +++ b/libavcodec/tests/avpacket.c @@ -0,0 +1,128 @@ +/* + * 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 +#include +#include +#include +#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)); + exit(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 ret; +} + +static int initializations(AVPacket* avpkt) +{ + const 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 = (uint8_t*)data; + avpkt->size = strlen(data); + avpkt->flags = AV_PKT_FLAG_DISCARD; + avpkt->duration = 100; + avpkt->pos = 3; + + ret = setup_side_data_entry(avpkt); + + return ret; +} + +int main(void) +{ + AVPacket avpkt; + AVPacket *avpkt_clone = NULL; + int ret = 0; + + if(initializations(&avpkt) < 0){ + 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 av_grow_packet*/ + if(av_grow_packet(avpkt_clone, 20) < 0){ + av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n"); + return 1; + } + 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; + } + /* 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 size error check in 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