2 /*****************************************************************************
3 * dictionary.c: Tests for vlc_dictionary_t
4 *****************************************************************************
5 * Copyright (C) 2007 Pierre d'Herbemont
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 *****************************************************************************/
30 #include <vlc_common.h>
31 #include "vlc_arrays.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
);
44 for( j
= 0; keys
[j
]; j
++ )
47 for( i
= 0; i
< size
; i
++ )
49 if(!strcmp( keys
[j
], our_keys
[i
] ))
60 for( i
= 0; i
< size
; i
++ )
61 assert( vlc_dictionary_value_for_key( p_dict
, our_keys
[i
] ) == (void *)i
);
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]);
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] );
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 );