[vlc-commits] epg: add tests

Francois Cartegnie git at videolan.org
Sat Feb 13 15:44:06 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Feb 13 14:22:06 2016 +0100| [f630cb66ecaaae5095ec49554470ef60acecda06] | committer: Francois Cartegnie

epg: add tests

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f630cb66ecaaae5095ec49554470ef60acecda06
---

 test/Makefile.am    |    3 +
 test/src/misc/epg.c |  189 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 192 insertions(+)

diff --git a/test/Makefile.am b/test/Makefile.am
index 4360573..d431c5d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -24,6 +24,7 @@ check_PROGRAMS = \
 	test_src_input_stream \
 	test_src_interface_dialog \
 	test_src_misc_bits \
+	test_src_misc_epg \
 	test_modules_packetizer_hxxx \
 	test_modules_keystore \
 	test_modules_tls \
@@ -93,6 +94,8 @@ test_src_input_stream_net_CFLAGS = $(AM_CFLAGS) -DTEST_NET
 test_src_input_stream_net_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
+test_src_misc_epg_LDADD = $(LIBVLC)
 test_src_interface_dialog_SOURCES = src/interface/dialog.c
 test_src_interface_dialog_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_packetizer_hxxx_SOURCES = modules/packetizer/hxxx.c
diff --git a/test/src/misc/epg.c b/test/src/misc/epg.c
new file mode 100644
index 0000000..8f5a571
--- /dev/null
+++ b/test/src/misc/epg.c
@@ -0,0 +1,189 @@
+/*****************************************************************************
+ * epg.c test EPG
+ *****************************************************************************
+ * Copyright (C) 2016 - VideoLAN Authors
+ *
+ * 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *****************************************************************************/
+#include "../../libvlc/test.h"
+#ifdef NDEBUG
+ #undef NDEBUG
+#endif
+#include <vlc_common.h>
+#include <vlc_epg.h>
+#include <assert.h>
+
+static void assert_current( const vlc_epg_t *p_epg, const char *psz_name )
+{
+    if( (void*)psz_name == (void*)p_epg->p_current )
+    {
+        assert( psz_name == NULL );
+    }
+    else
+    {
+        assert( p_epg->p_current );
+        assert( p_epg->p_current->psz_name );
+        assert( psz_name[0] == p_epg->p_current->psz_name[0] );
+    }
+}
+
+static void print_order( const vlc_epg_t *p_epg )
+{
+    printf("order: ");
+    for( int i=0; i<p_epg->i_event; i++ )
+        printf("%s ", p_epg->pp_event[i]->psz_name );
+    printf("\n");
+}
+
+static void assert_events( const vlc_epg_t *p_epg, const char *psz_names, int i_names )
+{
+    assert( p_epg->i_event == i_names );
+    for( int i=0; i<p_epg->i_event; i++ )
+    {
+        assert( p_epg->pp_event[i]->psz_name &&
+                p_epg->pp_event[i]->psz_name[0] == psz_names[i] );
+    }
+}
+
+#define EPG_ADD(epg, start, duration, a) \
+    vlc_epg_AddEvent( epg, start, duration, a, NULL, NULL, 0 )
+
+int main( void )
+{
+    test_init();
+
+    int i=1;
+
+    /* Simple insert/current test */
+    printf("--test %d\n", i++);
+    vlc_epg_t *p_epg = vlc_epg_New( NULL );
+    assert(p_epg);
+    EPG_ADD( p_epg,  42, 20, "A" );
+    EPG_ADD( p_epg,  62, 20, "B" );
+    EPG_ADD( p_epg,  82, 20, "C" );
+    EPG_ADD( p_epg, 102, 20, "D" );
+    print_order( p_epg );
+    assert_events( p_epg, "ABCD", 4 );
+    assert_current( p_epg, NULL );
+
+    vlc_epg_SetCurrent( p_epg, 82 );
+    assert_current( p_epg, "C" );
+
+    vlc_epg_Delete( p_epg );
+
+
+    /* Test reordering / head/tail inserts */
+    printf("--test %d\n", i++);
+    p_epg = vlc_epg_New( NULL );
+    assert(p_epg);
+    EPG_ADD( p_epg,  82, 20, "C" );
+    EPG_ADD( p_epg,  62, 20, "B" );
+    EPG_ADD( p_epg, 102, 20, "D" );
+    EPG_ADD( p_epg,  42, 20, "A" );
+    print_order( p_epg );
+    assert_events( p_epg, "ABCD", 4 );
+    vlc_epg_Delete( p_epg );
+
+    /* Test reordering/bisect lookup on insert */
+    printf("--test %d\n", i++);
+    p_epg = vlc_epg_New( NULL );
+    assert(p_epg);
+    EPG_ADD( p_epg, 142, 20, "F" );
+    EPG_ADD( p_epg, 122, 20, "E" );
+    EPG_ADD( p_epg, 102, 20, "D" );
+    EPG_ADD( p_epg,  82, 20, "C" );
+    EPG_ADD( p_epg,  42, 20, "A" );
+    EPG_ADD( p_epg,  62, 20, "B" );
+    print_order( p_epg );
+    assert_events( p_epg, "ABCDEF", 6 );
+    vlc_epg_Delete( p_epg );
+
+    /* Test deduplication and current pointer rebasing on insert */
+    printf("--test %d\n", i++);
+    p_epg = vlc_epg_New( NULL );
+    assert(p_epg);
+    EPG_ADD( p_epg,  62, 20, "E" );
+    EPG_ADD( p_epg,  62, 20, "F" );
+    EPG_ADD( p_epg,  42, 20, "A" );
+    vlc_epg_SetCurrent( p_epg, 62 );
+    EPG_ADD( p_epg,  82, 20, "C" );
+    EPG_ADD( p_epg,  62, 20, "B" );
+    EPG_ADD( p_epg, 102, 20, "D" );
+    print_order( p_epg );
+    assert_events( p_epg, "ABCD", 4 );
+    assert_current( p_epg, "B" );
+    vlc_epg_Delete( p_epg );
+
+
+    /* Test epg merging */
+    printf("--test %d\n", i++);
+    p_epg = vlc_epg_New( NULL );
+    assert(p_epg);
+    EPG_ADD( p_epg, 142, 20, "F" );
+    EPG_ADD( p_epg, 122, 20, "E" );
+    EPG_ADD( p_epg,  42, 20, "A" );
+    EPG_ADD( p_epg,  62, 20, "B" );
+    print_order( p_epg );
+
+    vlc_epg_t *p_epg2 = vlc_epg_New( NULL );
+    assert(p_epg2);
+    EPG_ADD( p_epg2, 102, 20, "D" );
+    EPG_ADD( p_epg2,  82, 20, "C" );
+    print_order( p_epg2 );
+
+    vlc_epg_Merge( p_epg, p_epg2 );
+    printf("merged " );
+    print_order( p_epg );
+
+    assert_events( p_epg, "ABCDEF", 6 );
+    assert_events( p_epg2, "CD", 2 ); /* should be untouched */
+    vlc_epg_Delete( p_epg );
+    vlc_epg_Delete( p_epg2 );
+
+
+    /* Test event overlapping */
+    printf("--test %d\n", i++);
+    p_epg = vlc_epg_New( NULL );
+    assert(p_epg);
+    EPG_ADD( p_epg,  42, 20, "A" );
+    EPG_ADD( p_epg,  62, 20, "B" );
+    EPG_ADD( p_epg,  82, 20, "C" );
+    EPG_ADD( p_epg, 102, 20, "D" );
+    print_order( p_epg );
+    vlc_epg_SetCurrent( p_epg, 62 );
+
+    p_epg2 = vlc_epg_New( NULL );
+    assert(p_epg2);
+    EPG_ADD( p_epg2,  41, 30, "E" );
+    print_order( p_epg2 );
+
+    vlc_epg_Merge( p_epg, p_epg2 );
+    printf("merged " );
+    print_order( p_epg );
+    assert_events( p_epg, "ECD", 3 );
+
+    assert_current( p_epg, NULL );
+
+    EPG_ADD( p_epg2,  70, 42, "F" );
+    print_order( p_epg2 );
+    vlc_epg_Merge( p_epg, p_epg2 );
+    printf("merged " );
+    print_order( p_epg );
+    assert_events( p_epg, "F", 1 );
+
+    vlc_epg_Delete( p_epg );
+    vlc_epg_Delete( p_epg2 );
+
+    return 0;
+}



More information about the vlc-commits mailing list