From cb6872cc9790ee2cd04f54ee762c23f5e48d9f4b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 13 Mar 2022 00:15:35 +0100 Subject: bookmark_test: Add basic test --- bookmarks.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'bookmarks.c') diff --git a/bookmarks.c b/bookmarks.c index d701279..2a772cc 100644 --- a/bookmarks.c +++ b/bookmarks.c @@ -69,18 +69,19 @@ load_xpath_results(GtkListStore *list_store, xmlNodeSetPtr nodes) GtkTreeModel * bookmarks_completion_init() { - const xmlChar *xpathExpr = (const xmlChar *)"//bookmark/@href"; - char *filename = g_build_filename(g_get_user_data_dir(), "badwolf", "bookmarks.xbel", NULL); - xmlDocPtr doc = NULL; + xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtx = NULL; xmlXPathObjectPtr xpathObj = NULL; - GtkListStore *list_store = gtk_list_store_new(1, G_TYPE_STRING); + + const xmlChar *xpathExpr = (const xmlChar *)"//bookmark/@href"; + char *filename = g_build_filename(g_get_user_data_dir(), "badwolf", "bookmarks.xbel", NULL); + GtkListStore *list_store = gtk_list_store_new(1, G_TYPE_STRING); /* flawfinder: ignore, just a presence check */ if(access(filename, R_OK) != 0) { g_fprintf(stderr, _("Bookmarks: No loadable file found at %s\n"), filename); - return NULL; + goto failure; } g_fprintf(stderr, _("Bookmarks: loading at %s\n"), filename); @@ -88,8 +89,7 @@ bookmarks_completion_init() if(doc == NULL) { g_fprintf(stderr, _("Bookmarks: unable to parse file \"%s\"\n"), filename); - location_completion_cleanup(xpathObj, xpathCtx, doc); - return NULL; + goto failure; } xmlXIncludeProcess(doc); @@ -98,16 +98,14 @@ bookmarks_completion_init() if(xpathCtx == NULL) { g_fprintf(stderr, _("Bookmarks: unable to create new XPath context\n")); - location_completion_cleanup(xpathObj, xpathCtx, doc); - return NULL; + goto failure; } xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx); if(xpathObj == NULL) { g_fprintf(stderr, _("Bookmarks: unable to evaluate XPath expression \"%s\"\n"), xpathExpr); - location_completion_cleanup(xpathObj, xpathCtx, doc); - return NULL; + goto failure; } load_xpath_results(list_store, xpathObj->nodesetval); @@ -117,4 +115,9 @@ bookmarks_completion_init() g_fprintf(stderr, _("Bookmarks: Done.\n")); return GTK_TREE_MODEL(list_store); + +failure: + location_completion_cleanup(xpathObj, xpathCtx, doc); + g_free(filename); + return NULL; } -- cgit v1.3.1-23-gd82d