1 /*****************************************************************************
2 * dictionary.c: Tests for vlc_dictionary_t
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
29 #include <vlc_common.h>
30 #include "vlc_arrays.h"
35 static void test_dictionary_validity (vlc_dictionary_t * p_dict, const char ** our_keys, int size )
37 /* Test values and keys now */
38 char ** keys = vlc_dictionary_all_keys( p_dict );
43 for( j = 0; keys[j]; j++ )
46 for( i = 0; i < size; i++ )
48 if(!strcmp( keys[j], our_keys[i] ))
59 for( i = 0; i < size; i++ )
60 assert( vlc_dictionary_value_for_key( p_dict, our_keys[i] ) == (void*)i );
65 static const char * our_keys[] = {
66 "Hello", "Hella", "flowmeter", "Frostnipped", "frostnipped", "remiform", "quadrifoliolate", "singularity", "unafflicted"
68 const int size = sizeof(our_keys)/sizeof(our_keys[0]);
72 vlc_dictionary_t dict;
73 vlc_dictionary_init( &dict, 0 );
75 assert( vlc_dictionary_keys_count( &dict ) == 0 );
77 keys = vlc_dictionary_all_keys( &dict );
78 assert( keys && !keys[0] );
82 /* Insert some values */
83 for( i = 0; i < size; i++ )
84 vlc_dictionary_insert( &dict, our_keys[i], (void*)i );
86 test_dictionary_validity( &dict, our_keys, size );
88 vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1] );
90 test_dictionary_validity( &dict, our_keys, size-1 );
92 vlc_dictionary_clear( &dict );
94 assert( vlc_dictionary_keys_count( &dict ) == 0 );