From c51438492d1defa320d6480dbd9fc6f419933665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 30 Jun 2016 20:48:47 +0300 Subject: [PATCH] test: unit test for stream FIFO --- test/Makefile.am | 3 ++ test/src/input/stream_fifo.c | 97 ++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 test/src/input/stream_fifo.c diff --git a/test/Makefile.am b/test/Makefile.am index d8759c4ef9..4e9b1f29ab 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -24,6 +24,7 @@ check_PROGRAMS = \ test_src_misc_variables \ test_src_crypto_update \ test_src_input_stream \ + test_src_input_stream_fifo \ test_src_interface_dialog \ test_src_misc_bits \ test_src_misc_epg \ @@ -99,6 +100,8 @@ test_src_input_stream_LDADD = $(LIBVLCCORE) $(LIBVLC) test_src_input_stream_net_SOURCES = src/input/stream.c test_src_input_stream_net_CFLAGS = $(AM_CFLAGS) -DTEST_NET test_src_input_stream_net_LDADD = $(LIBVLCCORE) $(LIBVLC) +test_src_input_stream_fifo_SOURCES = src/input/stream_fifo.c +test_src_input_stream_fifo_LDADD = $(LIBVLCCORE) $(LIBVLC) test_src_misc_bits_SOURCES = src/misc/bits.c test_src_misc_bits_LDADD = $(LIBVLC) test_src_misc_epg_SOURCES = src/misc/epg.c diff --git a/test/src/input/stream_fifo.c b/test/src/input/stream_fifo.c new file mode 100644 index 0000000000..427470994c --- /dev/null +++ b/test/src/input/stream_fifo.c @@ -0,0 +1,97 @@ +/***************************************************************************** + * stream_fifo.c: FIFO stream unit test + ***************************************************************************** + * Copyright © 2016 Rémi Denis-Courmont + * + * This program 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. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 + +#undef NDEBUG +#include +#include +#include +#include + +#include +#include +#include "../../../lib/libvlc_internal.h" +#include "../../libvlc/test.h" + +#include + +static libvlc_instance_t *vlc; +static vlc_object_t *parent; +static stream_t *s; + +int main(void) +{ + ssize_t val; + char buf[16]; + bool b; + + test_init(); + + vlc = libvlc_new(0, NULL); + assert(vlc != NULL); + parent = VLC_OBJECT(vlc->p_libvlc_int); + + s = vlc_stream_fifo_New(parent); + assert(s != NULL); + val = stream_Control(s, STREAM_CAN_SEEK, &b); + assert(val == VLC_SUCCESS && !b); + val = stream_GetSize(s, &(uint64_t){ 0 }); + assert(val < 0); + val = stream_Control(s, STREAM_GET_PTS_DELAY, &(int64_t){ 0 }); + assert(val == VLC_SUCCESS); + stream_Delete(s); + vlc_stream_fifo_Close(s); + + s = vlc_stream_fifo_New(parent); + assert(s != NULL); + val = vlc_stream_fifo_Write(s, "123", 3); + vlc_stream_fifo_Close(s); + val = stream_Read(s, buf, sizeof (buf)); + assert(val == 3); + assert(memcmp(buf, "123", 3) == 0); + val = stream_Read(s, buf, sizeof (buf)); + assert(val == 0); + stream_Delete(s); + + s = vlc_stream_fifo_New(parent); + assert(s != NULL); + val = vlc_stream_fifo_Write(s, "Hello ", 6); + assert(val == 6); + val = vlc_stream_fifo_Write(s, "world!\n", 7); + assert(val == 7); + val = vlc_stream_fifo_Write(s, "blahblah", 8); + assert(val == 8); + + val = stream_Read(s, buf, 13); + assert(val == 13); + assert(memcmp(buf, "Hello world!\n", 13) == 0); + stream_Delete(s); + + val = vlc_stream_fifo_Write(s, "cough cough", 11); + assert(val == -1 && errno == EPIPE); + vlc_stream_fifo_Close(s); + + libvlc_release(vlc); + + return 0; +} -- GitLab