From 19bdca43c31388bcbd67afc4e0dced93887d418b Mon Sep 17 00:00:00 2001 From: Pierre d'Herbemont Date: Fri, 15 Feb 2008 22:19:44 +0000 Subject: [PATCH] test/dictionary.c: Add a new test entry for the vlc_dictionary_t type. --- src/test/dictionary.c | 93 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/test/dictionary.c diff --git a/src/test/dictionary.c b/src/test/dictionary.c new file mode 100644 index 0000000000..81189943a7 --- /dev/null +++ b/src/test/dictionary.c @@ -0,0 +1,93 @@ +/***************************************************************************** + * 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 General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 + +#include +#include "vlc_arrays.h" + +#include +#include + +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 ); + int i, j; + + assert( keys ); + + for( j = 0; keys[j]; j++ ) + { + vlc_bool_t found = VLC_FALSE; + for( i = 0; i < size; i++ ) + { + if(!strcmp( keys[j], our_keys[i] )) + { + found = VLC_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; + int j, 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] ); + + test_dictionary_validity( &dict, our_keys, size-1 ); + + vlc_dictionary_clear( &dict ); + + assert( vlc_dictionary_keys_count( &dict ) == 0 ); + return 0; +} -- 2.39.2