Commit c91def4b authored by François Cartegnie's avatar François Cartegnie 🤞

epg: fix current replacement and add tests

parent f28e8996
......@@ -195,7 +195,7 @@ void vlc_epg_Merge( vlc_epg_t *p_dst_epg, const vlc_epg_t *p_src_epg )
int i_src=0;
for( ; i_src < p_src_epg->i_event; i_src++ )
{
const bool b_current = ( p_src_epg->pp_event[i_src] == p_src_epg->p_current );
bool b_current = ( p_src_epg->pp_event[i_src] == p_src_epg->p_current );
vlc_epg_event_t *p_src = vlc_epg_Event_Duplicate( p_src_epg->pp_event[i_src] );
if( unlikely(!p_src) )
......@@ -218,8 +218,11 @@ void vlc_epg_Merge( vlc_epg_t *p_dst_epg, const vlc_epg_t *p_src_epg )
( i_dst_end > p_src->i_start && i_dst_end <= i_src_end ) )
{
vlc_epg_Event_Delete( p_dst );
if( p_dst_epg->p_current )
if( p_dst_epg->p_current == p_dst )
{
b_current |= true;
p_dst_epg->p_current = NULL;
}
TAB_ERASE( p_dst_epg->i_event, p_dst_epg->pp_event, i_dst );
}
else
......
......@@ -43,6 +43,8 @@ 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 );
if( p_epg->p_current )
printf(" current %s", p_epg->p_current->psz_name );
printf("\n");
}
......@@ -173,7 +175,7 @@ int main( void )
print_order( p_epg );
assert_events( p_epg, "ECD", 3 );
assert_current( p_epg, NULL );
assert_current( p_epg, "E" );
EPG_ADD( p_epg2, 70, 42, "F" );
print_order( p_epg2 );
......@@ -182,6 +184,28 @@ int main( void )
print_order( p_epg );
assert_events( p_epg, "F", 1 );
/* Test current overwriting */
printf("--test %d\n", i++);
vlc_epg_SetCurrent( p_epg, 70 );
assert_current( p_epg, "F" );
print_order( p_epg );
print_order( p_epg2 );
vlc_epg_Merge( p_epg, p_epg2 );
printf("merged " );
print_order( p_epg );
assert_events( p_epg, "F", 1 );
assert_current( p_epg, "F" );
printf("--test %d\n", i++);
print_order( p_epg );
EPG_ADD( p_epg2, 270, 42, "Z" );
vlc_epg_SetCurrent( p_epg2, 270 );
print_order( p_epg2 );
vlc_epg_Merge( p_epg, p_epg2 );
printf("merged " );
print_order( p_epg );
assert_current( p_epg, "Z" );
vlc_epg_Delete( p_epg );
vlc_epg_Delete( p_epg2 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment