# -*- Autotest -*- AT_BANNER([make_description]) ## -------------- ## ## flag_show_urls ## ## -------------- ## AT_TESTFUN([flag_show_urls], [[ #include "internal_libreport.h" #include int main(int argc, char **argv) { g_verbose = 3; problem_data_t *pd = problem_data_new(); char *description = make_description(pd, /*skipped names*/NULL, CD_MAX_TEXT_SIZE, MAKEDESC_SHOW_URLS); assert(description != NULL || !"Returns NULL for empty problem data"); assert(description[0] == '\0' || !"Returns non-empty description for empty problem data"); free(description); problem_data_add_text_noteditable(pd, FILENAME_REPORTED_TO, "Bugzilla: URL=https://bugzilla.redhat.com/1000000\n"); description = make_description(pd, /*skipped names*/NULL, CD_MAX_TEXT_SIZE, MAKEDESC_SHOW_URLS); char *expected = xasprintf("%s: %*s%s\n", "Reported", 14 - strlen("Reported"), "", "https://bugzilla.redhat.com/1000000"); if (strcmp(expected, description) != 0) { printf("E:\n'%s'\n\nC:\n'%s'\n", expected, description); assert(!"The description for a single Bugzilla URL do not matches the expected description"); } free(description); free(expected); problem_data_free(pd); pd = problem_data_new(); problem_data_add_text_noteditable(pd, FILENAME_REPORTED_TO, "Bugzilla: URL=https://bugzilla.redhat.com/1000000\n" "ABRT Server: BTHASH=81680083BIGBOOBS\n" "RHTSupport: TIME=12345678 URL=https://access.redhat.com/home MSG=The world's best IT support\n" "ABRT Server: URL=https://bug-report.itos.redhat.com\n"); description = make_description(pd, /*skipped names*/NULL, CD_MAX_TEXT_SIZE, MAKEDESC_SHOW_URLS); expected = xasprintf( /*0123456789ABCDEF*/ "Reported: https://bugzilla.redhat.com/1000000\n" " https://access.redhat.com/home\n" " https://bug-report.itos.redhat.com\n"); if (strcmp(expected, description) != 0) { printf("E:\n'%s'\n\nC:\n'%s'\n", expected, description); assert(!"The description do not matches the expected description"); } free(description); free(expected); problem_data_free(pd); pd = problem_data_new(); problem_data_add_text_noteditable(pd, FILENAME_REPORTED_TO, "ABRT Server: BTHASH=81680083BIGBOOBS\n"); description = make_description(pd, /*skipped names*/NULL, CD_MAX_TEXT_SIZE, MAKEDESC_SHOW_URLS); assert(description != NULL || !"Returns NULL for non empty problem data"); assert(description[0] == '\0' || !"Returns non-empty description for problem data without any URL"); free(description); problem_data_free(pd); pd = problem_data_new(); const int list_flags = CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE | CD_FLAG_LIST; problem_data_add(pd, FILENAME_PACKAGE, "libreport", list_flags); problem_data_add(pd, FILENAME_REASON, "will_segfault killed by SIGSEGV", list_flags); problem_data_add(pd, FILENAME_COUNT, "0", list_flags); problem_data_add_text_noteditable(pd, FILENAME_REPORTED_TO, "Bugzilla: URL=https://bugzilla.redhat.com/1000000\n" "ABRT Server: BTHASH=81680083BIGBOOBS\n" "RHTSupport: TIME=12345678 URL=https://access.redhat.com/home MSG=The world's best IT support\n" "ABRT Server: URL=https://bug-report.itos.redhat.com\n"); description = make_description(pd, /*skipped names*/NULL, CD_MAX_TEXT_SIZE, MAKEDESC_SHOW_ONLY_LIST | MAKEDESC_SHOW_URLS); expected = xasprintf( "%s: %*s%s\n" "%s: %*s%s\n" "%s: %*s%s\n" /*0123456789ABCDEF*/ "Reported: https://bugzilla.redhat.com/1000000\n" " https://access.redhat.com/home\n" " https://bug-report.itos.redhat.com\n", FILENAME_REASON, 14 - strlen(FILENAME_REASON), "", "will_segfault killed by SIGSEGV", FILENAME_PACKAGE, 14 - strlen(FILENAME_PACKAGE), "", "libreport", FILENAME_COUNT, 14 - strlen(FILENAME_COUNT), "", "0"); if (strcmp(expected, description) != 0) { printf("E:\n'%s'\n\nC:\n'%s'\n", expected, description); assert(!"The description do not matches the expected description"); } free(expected); free(description); const char *const backtrace = "Extremely long backtrace which does not make sense"; problem_data_add(pd, FILENAME_BACKTRACE, backtrace, CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE); description = make_description(pd, /*skipped names*/NULL, strlen(backtrace) - 1, MAKEDESC_SHOW_FILES | MAKEDESC_SHOW_URLS); expected = xasprintf( "%s: %*s%s\n" "%s: %*s%s\n" "%s: %*s%s\n" "%s: %*s%s\n" /*0123456789ABCDEF*/ "Reported: https://bugzilla.redhat.com/1000000\n" " https://access.redhat.com/home\n" " https://bug-report.itos.redhat.com\n" "\n" "%s: %*sText file, %llu bytes\n" "%s: %*sText file, %llu bytes\n", FILENAME_REASON, 14 - strlen(FILENAME_REASON), "", "will_segfault killed by SIGSEGV", FILENAME_PACKAGE, 14 - strlen(FILENAME_PACKAGE), "", "libreport", FILENAME_COUNT, 14 - strlen(FILENAME_COUNT), "", "0", FILENAME_BACKTRACE, 14 - strlen(FILENAME_BACKTRACE), "", backtrace, FILENAME_BACKTRACE, 14 - strlen(FILENAME_BACKTRACE), "", (long long unsigned)strlen(backtrace), FILENAME_REPORTED_TO,14 - strlen(FILENAME_REPORTED_TO),"", (long long unsigned)strlen(problem_data_get_content_or_NULL(pd, FILENAME_REPORTED_TO)) ); if (strcmp(expected, description) != 0) { printf("E:\n'%s'\n\nC:\n'%s'\n", expected, description); assert(!"The description do not matches the expected description"); } free(expected); free(description); problem_data_free(pd); /* SHOW_URLS DID NOT BREAK THE OLD BEHAVIOUR */ pd = problem_data_new(); problem_data_add(pd, FILENAME_PACKAGE, "libreport", list_flags); problem_data_add(pd, FILENAME_REASON, "will_segfault killed by SIGSEGV", list_flags); problem_data_add(pd, FILENAME_COUNT, "0", list_flags); problem_data_add(pd, FILENAME_BACKTRACE, backtrace, CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE); description = make_description(pd, /*skipped names*/NULL, strlen(backtrace) - 1, MAKEDESC_SHOW_FILES); expected = xasprintf( "%s: %*s%s\n" "%s: %*s%s\n" "%s: %*s%s\n" "%s: %*s%s\n" "\n" "%s: %*sText file, %llu bytes\n", FILENAME_REASON, 14 - strlen(FILENAME_REASON), "", "will_segfault killed by SIGSEGV", FILENAME_PACKAGE, 14 - strlen(FILENAME_PACKAGE), "", "libreport", FILENAME_COUNT, 14 - strlen(FILENAME_COUNT), "", "0", FILENAME_BACKTRACE, 14 - strlen(FILENAME_BACKTRACE), "", backtrace, FILENAME_BACKTRACE, 14 - strlen(FILENAME_BACKTRACE), "", (long long unsigned)strlen(backtrace) ); if (strcmp(expected, description) != 0) { printf("E:\n'%s'\n\nC:\n'%s'\n", expected, description); assert(!"The description do not matches the expected description"); } free(expected); free(description); problem_data_free(pd); return 0; } ]]) ## -------------- ## ## not_reportable ## ## -------------- ## AT_TESTFUN([not_reportable], [[ #include "internal_libreport.h" #include int main(int argc, char **argv) { g_verbose = 3; problem_data_t *pd = problem_data_new(); problem_data_add_text_noteditable(pd, FILENAME_NOT_REPORTABLE, "not-reportable"); char *description = make_description(pd, /*skipped names*/NULL, CD_MAX_TEXT_SIZE, MAKEDESC_SHOW_URLS); char *expected = xasprintf("%s: %*s%s\n", "Reported", 14 - strlen("Reported"), "", "cannot be reported"); if (strstr(description, expected) == NULL) { printf("E:\n'%s'\n\nC:\n'%s'\n", expected, description); assert(!"The description for not-reportable do not matches the expected description"); } free(description); free(expected); problem_data_free(pd); return 0; } ]])