00001 00015 #define GITK_TESTS_DIALOG_C 00016 00017 #include "libgitk.h" 00018 00019 00023 static void test_setup(void) { 00024 gitk_log("-- beg -----------------------"); 00025 } 00026 00030 static void test_teardown(void) { 00031 gitk_log("-- end -----------------------\n\n"); 00032 } 00033 00034 00037 static gchar *dialog1_desc=\ 00038 "<?xml version=\"1.0\" ?>"\ 00039 "<!DOCTYPE giml SYSTEM \"http://gitk.sourceforge.net/giml.dtd\">"\ 00040 "<giml xmlns=\""GITK_NS_URL"\""\ 00041 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""\ 00042 " xmlns:i18n=\""I18N_NS_URL"\""\ 00043 " >"\ 00044 " <dialog>"\ 00045 " <meta>"\ 00046 " <dc:title><i18n:text>dialog 1</i18n:text></dc:title>"\ 00047 " </meta>"\ 00048 " <widgetgroup><widget/></widgetgroup>"\ 00049 " </dialog>"\ 00050 "</giml>"; 00051 00054 static gchar *dialog2_desc=\ 00055 "<?xml version=\"1.0\" ?>"\ 00056 "<!DOCTYPE giml SYSTEM \"http://gitk.sourceforge.net/giml.dtd\">"\ 00057 "<giml xmlns=\""GITK_NS_URL"\""\ 00058 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""\ 00059 " xmlns:i18n=\""I18N_NS_URL"\""\ 00060 " >"\ 00061 " <dialog>"\ 00062 " <meta>"\ 00063 " <dc:title><i18n:text>dialog 2</i18n:text></dc:title>"\ 00064 " </meta>"\ 00065 " <widgetgroup><widget/></widgetgroup>"\ 00066 " </dialog>"\ 00067 "</giml>"; 00068 00071 static gchar *dialog3_desc=\ 00072 "<?xml version=\"1.0\" ?>"\ 00073 "<!DOCTYPE giml SYSTEM \"http://gitk.sourceforge.net/giml.dtd\">"\ 00074 "<giml xmlns=\""GITK_NS_URL"\""\ 00075 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""\ 00076 " xmlns:i18n=\""I18N_NS_URL"\""\ 00077 " >"\ 00078 " <dialog>"\ 00079 " <meta>"\ 00080 " <dc:title><i18n:text>dialog 3</i18n:text></dc:title>"\ 00081 " </meta>"\ 00082 " <widgetgroup><widget/></widgetgroup>"\ 00083 " </dialog>"\ 00084 "</giml>"; 00085 00089 START_TEST(test_gitk_dialog_new_from_string_1) { 00090 GitkDialogPtr dialog1; 00091 00092 gitk_init(&test_argc,&test_argvptr,PACKAGE,LOCALEDIR); 00093 if((dialog1=gitk_dialog_new_from_string(dialog1_desc))) { 00094 gitk_dialog_free(dialog1); 00095 } 00096 else { 00097 snprintf(errormsg,ERROR_STR_LENGTH,"error parsing dialog => %d : %s",gitk_get_error_code(),gitk_get_error_str()); 00098 fail(errormsg); 00099 } 00100 gitk_done(); 00101 } 00102 END_TEST 00103 00107 START_TEST(test_gitk_dialog_show_1) { 00108 GitkDialogPtr dialog1=NULL,dialog2=NULL,dialog3=NULL; 00109 00110 gitk_init(&test_argc,&test_argvptr,PACKAGE,LOCALEDIR); 00111 if((dialog1=gitk_dialog_new_from_string(dialog1_desc)) && 00112 (dialog2=gitk_dialog_new_from_string(dialog2_desc)) && 00113 (dialog3=gitk_dialog_new_from_string(dialog3_desc))) { 00114 mark_point(); 00115 00116 fail_unless(gitk_context_get_highest_used_priority()==0,"initial priority should be 0"); 00117 gitk_dialog_show(dialog1,FALSE); 00118 mark_point(); 00119 fail_unless(gitk_context_get_highest_used_priority()==0,"initial priority should still be 0"); 00120 gitk_dialog_show(dialog2,FALSE); 00121 mark_point(); 00122 fail_unless(gitk_context_get_highest_used_priority()==0,"initial priority should still be 0"); 00123 gitk_dialog_show(dialog3,TRUE); 00124 mark_point(); 00125 fail_unless(gitk_context_get_highest_used_priority()==1,"initial priority should now be 1"); 00126 mark_point(); 00127 00128 gitk_dialog_hide(dialog3); 00129 mark_point(); 00130 fail_unless(gitk_context_get_highest_used_priority()==0,"initial priority should again be 0"); 00131 gitk_dialog_hide(dialog2); 00132 gitk_dialog_hide(dialog1); 00133 } 00134 else { 00135 snprintf(errormsg,ERROR_STR_LENGTH,"error parsing dialog => %d : %s",gitk_get_error_code(),gitk_get_error_str()); 00136 fail(errormsg); 00137 } 00138 if(dialog1) gitk_dialog_free(dialog1); 00139 if(dialog2) gitk_dialog_free(dialog2); 00140 if(dialog3) gitk_dialog_free(dialog3); 00141 gitk_done(); 00142 } 00143 END_TEST 00144 00148 START_TEST(test_gitk_dialog_show_2) { 00149 GitkDialogPtr dialog1=NULL,dialog2=NULL,dialog3=NULL; 00150 00151 gitk_init(&test_argc,&test_argvptr,PACKAGE,LOCALEDIR); 00152 if((dialog1=gitk_dialog_new_from_string(dialog1_desc)) && 00153 (dialog2=gitk_dialog_new_from_string(dialog2_desc)) && 00154 (dialog3=gitk_dialog_new_from_string(dialog3_desc))) { 00155 mark_point(); 00156 00157 fail_unless(gitk_context_activate()==NULL,"no context should be activatable"); 00158 gitk_dialog_show(dialog1,FALSE); 00159 mark_point(); 00160 fail_unless(gitk_context_activate()==dialog1,"activated wrong context"); 00161 gitk_dialog_show(dialog2,FALSE); 00162 mark_point(); 00163 fail_unless(gitk_context_activate()==NULL,"no context should be activatable"); 00164 gitk_dialog_show(dialog3,TRUE); 00165 mark_point(); 00166 fail_unless(gitk_context_activate()==dialog3,"activated wrong context"); 00167 mark_point(); 00168 00169 gitk_dialog_hide(dialog3); 00170 gitk_dialog_hide(dialog2); 00171 mark_point(); 00172 fail_unless(gitk_context_activate()==dialog1,"activated wrong context"); 00173 gitk_dialog_hide(dialog1); 00174 } 00175 else { 00176 snprintf(errormsg,ERROR_STR_LENGTH,"error parsing dialog => %d : %s",gitk_get_error_code(),gitk_get_error_str()); 00177 fail(errormsg); 00178 } 00179 if(dialog1) gitk_dialog_free(dialog1); 00180 if(dialog2) gitk_dialog_free(dialog2); 00181 if(dialog3) gitk_dialog_free(dialog3); 00182 gitk_done(); 00183 } 00184 END_TEST 00185 00186 00190 TCase *libgitk_dialog_tcase(void) { 00191 TCase *tc = tcase_create("Dialog"); 00192 00193 tcase_add_test(tc,test_gitk_dialog_new_from_string_1); 00194 tcase_add_test(tc,test_gitk_dialog_show_1); 00195 tcase_add_test(tc,test_gitk_dialog_show_2); 00196 tcase_add_unchecked_fixture(tc, test_setup, test_teardown); 00197 return(tc); 00198 }