Summary Files Commits Branches @commit @diff @stats
path: root / bookmarks.c
diff options
context:
space:
mode:
Commitcb6872cc9790ee2cd04f54ee762c23f5e48d9f4b (patch)
Author
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2022-03-13 00:15:35 +0100
Committer
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2022-03-13 00:15:35 +0100
Files6837fa0a76434dba56aec60842c34501fa203f83 /bookmarks.c
goodwolf-cb6872cc9790ee2cd04f54ee762c23f5e48d9f4b.tar
goodwolf-cb6872cc9790ee2cd04f54ee762c23f5e48d9f4b.tar.gz
goodwolf-cb6872cc9790ee2cd04f54ee762c23f5e48d9f4b.zip
Parentedbe278f8dcf822504e25f055dc89dcfcd9e3656 (diff)
bookmark_test: Add basic test
1 files changed, 14 insertions, 11 deletions
-rw-r--r--bookmarks.c25
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;
}