| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
#ifdef HAVE_CONFIG_H |
|---|
| 23 |
# include "config.h" |
|---|
| 24 |
#endif |
|---|
| 25 |
|
|---|
| 26 |
#undef NDEBUG |
|---|
| 27 |
#include <assert.h> |
|---|
| 28 |
|
|---|
| 29 |
#include <vlc_common.h> |
|---|
| 30 |
#include "vlc_arrays.h" |
|---|
| 31 |
|
|---|
| 32 |
#include <stdio.h> |
|---|
| 33 |
#include <stdlib.h> |
|---|
| 34 |
|
|---|
| 35 |
static void test_dictionary_validity (vlc_dictionary_t * p_dict, const char ** our_keys, int size ) |
|---|
| 36 |
{ |
|---|
| 37 |
|
|---|
| 38 |
char ** keys = vlc_dictionary_all_keys( p_dict ); |
|---|
| 39 |
int i, j; |
|---|
| 40 |
|
|---|
| 41 |
assert( keys ); |
|---|
| 42 |
|
|---|
| 43 |
for( j = 0; keys[j]; j++ ) |
|---|
| 44 |
{ |
|---|
| 45 |
bool found = false; |
|---|
| 46 |
for( i = 0; i < size; i++ ) |
|---|
| 47 |
{ |
|---|
| 48 |
if(!strcmp( keys[j], our_keys[i] )) |
|---|
| 49 |
{ |
|---|
| 50 |
found = true; |
|---|
| 51 |
break; |
|---|
| 52 |
} |
|---|
| 53 |
} |
|---|
| 54 |
free( keys[j] ); |
|---|
| 55 |
assert( found ); |
|---|
| 56 |
} |
|---|
| 57 |
free( keys ); |
|---|
| 58 |
|
|---|
| 59 |
for( i = 0; i < size; i++ ) |
|---|
| 60 |
assert( vlc_dictionary_value_for_key( p_dict, our_keys[i] ) == (void*)i ); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
int main (void) |
|---|
| 64 |
{ |
|---|
| 65 |
static const char * our_keys[] = { |
|---|
| 66 |
"Hello", "Hella", "flowmeter", "Frostnipped", "frostnipped", "remiform", "quadrifoliolate", "singularity", "unafflicted" |
|---|
| 67 |
}; |
|---|
| 68 |
const int size = sizeof(our_keys)/sizeof(our_keys[0]); |
|---|
| 69 |
char ** keys; |
|---|
| 70 |
int i = 0; |
|---|
| 71 |
|
|---|
| 72 |
vlc_dictionary_t dict; |
|---|
| 73 |
vlc_dictionary_init( &dict, 0 ); |
|---|
| 74 |
|
|---|
| 75 |
assert( vlc_dictionary_keys_count( &dict ) == 0 ); |
|---|
| 76 |
|
|---|
| 77 |
keys = vlc_dictionary_all_keys( &dict ); |
|---|
| 78 |
assert( keys && !keys[0] ); |
|---|
| 79 |
free(keys); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
for( i = 0; i < size; i++ ) |
|---|
| 84 |
vlc_dictionary_insert( &dict, our_keys[i], (void*)i ); |
|---|
| 85 |
|
|---|
| 86 |
test_dictionary_validity( &dict, our_keys, size ); |
|---|
| 87 |
|
|---|
| 88 |
vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1] ); |
|---|
| 89 |
|
|---|
| 90 |
test_dictionary_validity( &dict, our_keys, size-1 ); |
|---|
| 91 |
|
|---|
| 92 |
vlc_dictionary_clear( &dict ); |
|---|
| 93 |
|
|---|
| 94 |
assert( vlc_dictionary_keys_count( &dict ) == 0 ); |
|---|
| 95 |
return 0; |
|---|
| 96 |
} |
|---|