diff options
bookmark_test: Add basic test
1 files changed, 14 insertions, 11 deletions
| -rw-r--r-- | bookmarks.c | 25 |
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; } |