configure: Improve detection of ibtool
[vlc.git] / src / test / dictionary.c
blob2e686e4859eccceb055381b42d4b1ea380c3cb3a
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 it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * 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++ )
86 vlc_dictionary_insert( &dict, our_keys[i], (void *)i );
87 assert( vlc_dictionary_has_key(&dict, our_keys[i]) );
88 for( int j = i + 1; j < size; j++ )
89 assert( !vlc_dictionary_has_key(&dict, our_keys[j]) );
92 test_dictionary_validity( &dict, our_keys, size );
94 vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1], NULL, NULL );
96 test_dictionary_validity( &dict, our_keys, size-1 );
98 vlc_dictionary_clear( &dict, NULL, NULL );
100 assert( vlc_dictionary_keys_count( &dict ) == 0 );
101 return 0;