Add encoder support for Dirac using the Schroedinger library.
[vlc/asuraparaju-public.git] / src / test / dictionary.c
blob7cc3ed387b4bca8ac7e7d3f2aef05adbe8c7fc5d
2 /*****************************************************************************
3 * dictionary.c: Tests for vlc_dictionary_t
4 *****************************************************************************
5 * Copyright (C) 2007 Pierre d'Herbemont
6 * $Id$
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #undef NDEBUG
28 #include <assert.h>
30 #include <vlc_common.h>
31 #include "vlc_arrays.h"
33 #include <stdio.h>
34 #include <stdlib.h>
36 static void test_dictionary_validity (vlc_dictionary_t * p_dict, const char ** our_keys, int size )
38 /* Test values and keys now */
39 char ** keys = vlc_dictionary_all_keys( p_dict );
40 intptr_t i, j;
42 assert( keys );
44 for( j = 0; keys[j]; j++ )
46 bool found = false;
47 for( i = 0; i < size; i++ )
49 if(!strcmp( keys[j], our_keys[i] ))
51 found = true;
52 break;
55 free( keys[j] );
56 assert( found );
58 free( keys );
60 for( i = 0; i < size; i++ )
61 assert( vlc_dictionary_value_for_key( p_dict, our_keys[i] ) == (void *)i );
64 int main (void)
66 static const char * our_keys[] = {
67 "Hello", "Hella", "flowmeter", "Frostnipped", "frostnipped", "remiform", "quadrifoliolate", "singularity", "unafflicted"
69 const int size = sizeof(our_keys)/sizeof(our_keys[0]);
70 char ** keys;
71 intptr_t i = 0;
73 vlc_dictionary_t dict;
74 vlc_dictionary_init( &dict, 0 );
76 assert( vlc_dictionary_keys_count( &dict ) == 0 );
78 keys = vlc_dictionary_all_keys( &dict );
79 assert( keys && !keys[0] );
80 free(keys);
83 /* Insert some values */
84 for( i = 0; i < size; i++ )
85 vlc_dictionary_insert( &dict, our_keys[i], (void *)i );
87 test_dictionary_validity( &dict, our_keys, size );
89 vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1], NULL, NULL );
91 test_dictionary_validity( &dict, our_keys, size-1 );
93 vlc_dictionary_clear( &dict, NULL, NULL );
95 assert( vlc_dictionary_keys_count( &dict ) == 0 );
96 return 0;