Browse Source

test: test the ancillary API

pull/132/head
Thomas Guillem 5 years ago
parent
commit
d0547192a7
  1. 3
      test/Makefile.am
  2. 118
      test/src/misc/ancillary.c

3
test/Makefile.am

@ -23,6 +23,7 @@ check_PROGRAMS = \
test_libvlc_renderer_discoverer \
test_libvlc_slaves \
test_src_config_chain \
test_src_misc_ancillary \
test_src_misc_variables \
test_src_input_stream \
test_src_input_stream_fifo \
@ -103,6 +104,8 @@ test_libvlc_slaves_SOURCES = libvlc/slaves.c
test_libvlc_slaves_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_libvlc_meta_SOURCES = libvlc/meta.c
test_libvlc_meta_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_misc_ancillary_SOURCES = src/misc/ancillary.c
test_src_misc_ancillary_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_misc_variables_SOURCES = src/misc/variables.c
test_src_misc_variables_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_config_chain_SOURCES = src/config/chain.c

118
test/src/misc/ancillary.c

@ -0,0 +1,118 @@
/*****************************************************************************
* ancillary.c: test for ancillary
*****************************************************************************
* Copyright (C) 2021 the VideoLAN team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_frame.h>
#include <vlc_picture.h>
#include <vlc_ancillary.h>
#include <assert.h>
static void
ancillary_free(void *data)
{
assert(strncmp(data, "test", 4) == 0);
free(data);
}
int main( void )
{
vlc_frame_t *frame = vlc_frame_Alloc(1);
assert(frame);
int ret;
struct vlc_ancillary *ancillary;
/* Create and try to attach 3 ancillaries to the frame, only 2 will be
* attached. */
for (size_t i = 0; i < 3; ++i)
{
char *data;
ret = asprintf(&data, "test%zu", i);
assert(ret > 0);
vlc_ancillary_id id;
switch (i)
{
case 0:
/* Check that only one ancillary of the same id is added (the
* last one take precedence). */
case 1: id = VLC_ANCILLARY_ID('t','s','t','1'); break;
case 2: id = VLC_ANCILLARY_ID('t','s','t','2'); break;
default: vlc_assert_unreachable();
}
ancillary = vlc_ancillary_CreateWithFreeCb(data, id, ancillary_free);
assert(ancillary);
ret = vlc_frame_AttachAncillary(frame, ancillary);
assert(ret == VLC_SUCCESS);
vlc_ancillary_Release(ancillary);
}
/* Check that ancillaries are copied via a vlc_frame_CopyProperties() (done
* by vlc_frame_Duplicate()). */
vlc_frame_t *copy_frame = vlc_frame_Duplicate(frame);
assert(copy_frame);
vlc_frame_Release(frame);
frame = copy_frame;
picture_t *picture = picture_New(VLC_CODEC_NV12, 1, 1, 1, 1);
assert(picture);
/* Manually attach both ancillaries to a newly allocated picture. */
ancillary = vlc_frame_GetAncillary(frame, VLC_ANCILLARY_ID('t','s','t','1'));
assert(ancillary);
picture_AttachAncillary(picture, ancillary);
ancillary = vlc_frame_GetAncillary(frame, VLC_ANCILLARY_ID('t','s','t','2'));
assert(ancillary);
picture_AttachAncillary(picture, ancillary);
vlc_frame_Release(frame);
/* Check that ancillaries are copied via a picture_Clone(). */
picture_t *clone = picture_Clone(picture);
assert(clone);
picture_Release(picture);
/* Check that ancillaries are copied via a picture_Copy(). */
picture_t *copy = picture_New(VLC_CODEC_I420, 1, 1, 1, 1);
assert(copy);
picture_Copy(copy, clone);
picture_Release(clone);
/* Check that ancillaries are still valid. */
ancillary = picture_GetAncillary(copy, VLC_ANCILLARY_ID('t','s','t','1'));
assert(ancillary);
assert(strcmp("test1", vlc_ancillary_GetData(ancillary)) == 0);
ancillary = picture_GetAncillary(copy, VLC_ANCILLARY_ID('t','s','t','2'));
assert(ancillary);
assert(strcmp("test2", vlc_ancillary_GetData(ancillary)) == 0);
picture_Release(copy);
return 0;
}
Loading…
Cancel
Save