forked from videolan/vlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary.c
97 lines (77 loc) · 2.8 KB
/
dictionary.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*****************************************************************************
* dictionary.c: Tests for vlc_dictionary_t
*****************************************************************************
* Copyright (C) 2007 Pierre d'Herbemont
* $Id$
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#undef NDEBUG
#include <assert.h>
#include <vlc_common.h>
#include "vlc_arrays.h"
#include <stdio.h>
#include <stdlib.h>
static void test_dictionary_validity (vlc_dictionary_t * p_dict, const char ** our_keys, int size )
{
/* Test values and keys now */
char ** keys = vlc_dictionary_all_keys( p_dict );
intptr_t i, j;
assert( keys );
for( j = 0; keys[j]; j++ )
{
bool found = false;
for( i = 0; i < size; i++ )
{
if(!strcmp( keys[j], our_keys[i] ))
{
found = true;
break;
}
}
free( keys[j] );
assert( found );
}
free( keys );
for( i = 0; i < size; i++ )
assert( vlc_dictionary_value_for_key( p_dict, our_keys[i] ) == (void *)i );
}
int main (void)
{
static const char * our_keys[] = {
"Hello", "Hella", "flowmeter", "Frostnipped", "frostnipped", "remiform", "quadrifoliolate", "singularity", "unafflicted"
};
const int size = sizeof(our_keys)/sizeof(our_keys[0]);
char ** keys;
intptr_t i = 0;
vlc_dictionary_t dict;
vlc_dictionary_init( &dict, 0 );
assert( vlc_dictionary_keys_count( &dict ) == 0 );
keys = vlc_dictionary_all_keys( &dict );
assert( keys && !keys[0] );
free(keys);
/* Insert some values */
for( i = 0; i < size; i++ )
vlc_dictionary_insert( &dict, our_keys[i], (void *)i );
test_dictionary_validity( &dict, our_keys, size );
vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1], NULL, NULL );
test_dictionary_validity( &dict, our_keys, size-1 );
vlc_dictionary_clear( &dict, NULL, NULL );
assert( vlc_dictionary_keys_count( &dict ) == 0 );
return 0;
}