00001 #include <eh_utils.h> 00002 #include <check.h> 00003 00004 START_TEST ( test_create_symbol_table ) 00005 { 00006 Eh_symbol_table t; 00007 00008 t = eh_symbol_table_new( ); 00009 00010 fail_unless( t>0 , "Bad symbol table handle" ); 00011 fail_unless( eh_symbol_table_size(t)==0 , "Empty symbol table should be size 0" ); 00012 00013 t = eh_symbol_table_destroy( t ); 00014 00015 fail_unless( t==NULL , "Destroyed symbol table should be set to NULL" ); 00016 } 00017 END_TEST 00018 00019 START_TEST ( test_add_value ) 00020 { 00021 Eh_symbol_table t; 00022 gchar* label = g_strdup( "test label" ); 00023 gchar* value = g_strdup( "test value" ); 00024 gchar* stored_value; 00025 00026 t = eh_symbol_table_new( ); 00027 00028 eh_symbol_table_insert( t , label , value ); 00029 00030 fail_unless( eh_symbol_table_size(t)==1 , "Symbol table should be size 1" ); 00031 fail_unless( eh_symbol_table_has_label(t,label) , "Added label not found" ); 00032 00033 stored_value = eh_symbol_table_value( t , label ); 00034 00035 fail_unless( stored_value!=value , "A copy of the value should be returned" ); 00036 fail_unless( g_ascii_strcasecmp(stored_value,value)==0 , "Added value not returned" ); 00037 00038 eh_free( stored_value ); 00039 00040 stored_value = eh_symbol_table_lookup( t , label ); 00041 fail_unless( stored_value!=value , "A copy of the value should be stored" ); 00042 00043 t = eh_symbol_table_destroy( t ); 00044 } 00045 END_TEST 00046 00047 Suite *eh_symbol_table_suite( void ) 00048 { 00049 Suite *s = suite_create( "Eh_symbol_table" ); 00050 TCase *test_case_core = tcase_create( "Core" ); 00051 00052 suite_add_tcase( s , test_case_core ); 00053 00054 tcase_add_test( test_case_core , test_create_symbol_table ); 00055 tcase_add_test( test_case_core , test_add_value ); 00056 00057 return s; 00058 } 00059 00060 int test_symbol_table( void ) 00061 { 00062 int n; 00063 00064 { 00065 Suite *s = eh_symbol_table_suite(); 00066 SRunner *sr = srunner_create( s ); 00067 00068 srunner_run_all( sr , CK_NORMAL ); 00069 n = srunner_ntests_failed( sr ); 00070 srunner_free( sr ); 00071 } 00072 00073 return n; 00074 } 00075