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 *****************************************************************************/
27 #include "vlc_arrays.h"
32 static void test_dictionary_validity (vlc_dictionary_t * p_dict, const char ** our_keys, int size )
34 /* Test values and keys now */
35 char ** keys = vlc_dictionary_all_keys( p_dict );
40 for( j = 0; keys[j]; j++ )
43 for( i = 0; i < size; i++ )
45 if(!strcmp( keys[j], our_keys[i] ))
56 for( i = 0; i < size; i++ )
57 assert( vlc_dictionary_value_for_key( p_dict, our_keys[i] ) == (void*)i );
62 static const char * our_keys[] = {
63 "Hello", "Hella", "flowmeter", "Frostnipped", "frostnipped", "remiform", "quadrifoliolate", "singularity", "unafflicted"
65 const int size = sizeof(our_keys)/sizeof(our_keys[0]);
69 vlc_dictionary_t dict;
70 vlc_dictionary_init( &dict, 0 );
72 assert( vlc_dictionary_keys_count( &dict ) == 0 );
74 keys = vlc_dictionary_all_keys( &dict );
75 assert( keys && !keys[0] );
79 /* Insert some values */
80 for( i = 0; i < size; i++ )
81 vlc_dictionary_insert( &dict, our_keys[i], (void*)i );
83 test_dictionary_validity( &dict, our_keys, size );
85 vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1] );
87 test_dictionary_validity( &dict, our_keys, size-1 );
89 vlc_dictionary_clear( &dict );
91 assert( vlc_dictionary_keys_count( &dict ) == 0 );