]> saetta.ns0.it Git - zakbookmarks/libzakbookmarks/commitdiff
Added test. Bugfixes. master
authorAndrea Zagli <azagli@libero.it>
Sun, 21 Jul 2019 09:16:10 +0000 (11:16 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 21 Jul 2019 09:16:10 +0000 (11:16 +0200)
Makefile.am
configure.ac
plugins/db/Makefile.am
plugins/db/plgdb.c
plugins/db/schema.sql [new file with mode: 0644]
src/bks.c
src/libzakbookmarks.h
tests/Makefile.am [new file with mode: 0644]
tests/test.c [new file with mode: 0644]

index cb252225f4609adfcef06f15c4857dc3c47e20e6..627bb173345d6edb94f14d0041dc6ed9dac57d77 100644 (file)
@@ -1,6 +1,6 @@
 DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
 
-SUBDIRS = src plugins
+SUBDIRS = src plugins tests
 
 EXTRA_DIST = libzakbookmarks.pc.in
 
index 373e80217e547e4a8f06b3e02cf42ec8842b7f22..7d11c7e7daad9ccb4d7dd81ad0ca872801e6b8b7 100644 (file)
@@ -60,6 +60,7 @@ AC_CONFIG_FILES([
   src/Makefile
   plugins/Makefile
   plugins/db/Makefile
+  tests/Makefile
 ])
 
 AC_OUTPUT
index b1ddff1f93807f2f94c72ec02fd5e1f33ba6d79a..9baa42e6e2977210c6524a58d7e76d7cb6c22d71 100644 (file)
@@ -17,3 +17,5 @@ libdb_la_LIBADD = \
                   $(LIBZAKBOOKMARKS_LIBS)
 
 plugins_DATA = db.plugin
+
+EXTRA_DIST = schema.sql
index 6d5ab500c7a41ff704e7b648ec3b94d818890da0..9b04d6e07325969407543d52a0f58a2718128b5c 100644 (file)
@@ -153,13 +153,18 @@ static GList
 
        gdaex_sql_builder_from (sqlb, "bookmarks", NULL);
 
-       gdaex_sql_builder_order (sqlb, "name", NULL);
+       gdaex_sql_builder_fields (sqlb,
+                                 "bookmarks", "name", "", NULL,
+                                 "bookmarks", "url", "", NULL,
+                                 NULL);
+
+       gdaex_sql_builder_order (sqlb, "bookmarks", "name", "", TRUE, NULL);
 
        dm = gdaex_sql_builder_query (sqlb, priv->gdaex, NULL);
        if (!gdaex_data_model_is_empty (dm))
                {
                        iter = gda_data_model_create_iter (dm);
-                       while (gda_data_model_iter_next (dm, iter))
+                       while (gda_data_model_iter_move_next (iter))
                                {
                                        ZakBksBookmark *bk;
                                        bk = g_new0 (ZakBksBookmark, 1);
@@ -194,10 +199,9 @@ zak_bks_db_plugin_add_bookmark (ZakBksPluggable *pluggable, ZakBksBookmark *bk)
                                 GDA_SQL_OPERATOR_TYPE_EQ,
                                 gval,
                                 NULL);
-       g_value_unset (gval);
 
        dm = gdaex_sql_builder_query (sqlb, priv->gdaex, NULL);
-       if (!gdaex_data_model_is_empty (dm))
+       if (gdaex_data_model_is_empty (dm))
                {
                        sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
 
@@ -205,19 +209,15 @@ zak_bks_db_plugin_add_bookmark (ZakBksPluggable *pluggable, ZakBksBookmark *bk)
                        g_value_init (gval, G_TYPE_STRING);
                        g_value_set_string (gval, bk->name);
                        gdaex_sql_builder_field (sqlb,
-                                                "bookmarks", "name", NULL,
+                                                "bookmarks", "name", "",
                                                 gval);
-                       g_value_unset (gval);
 
                        gval = g_new0 (GValue, 1);
                        g_value_init (gval, G_TYPE_STRING);
                        g_value_set_string (gval, bk->url);
                        gdaex_sql_builder_field (sqlb,
-                                                "bookmarks", "url", NULL,
+                                                "bookmarks", "url", "",
                                                 gval);
-                       g_value_unset (gval);
-
-                       gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL);
                }
        else
                {
@@ -227,9 +227,8 @@ zak_bks_db_plugin_add_bookmark (ZakBksPluggable *pluggable, ZakBksBookmark *bk)
                        g_value_init (gval, G_TYPE_STRING);
                        g_value_set_string (gval, bk->name);
                        gdaex_sql_builder_field (sqlb,
-                                                "bookmarks", "name", NULL,
+                                                "bookmarks", "name", "",
                                                 gval);
-                       g_value_unset (gval);
 
                        gval = g_new0 (GValue, 1);
                        g_value_init (gval, G_TYPE_STRING);
@@ -239,10 +238,9 @@ zak_bks_db_plugin_add_bookmark (ZakBksPluggable *pluggable, ZakBksBookmark *bk)
                                                 GDA_SQL_OPERATOR_TYPE_EQ,
                                                 gval,
                                                 NULL);
-                       g_value_unset (gval);
-
-                       gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL);
                }
+
+       gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL);
 }
 
 static void
@@ -265,7 +263,6 @@ zak_bks_db_plugin_remove_bookmark (ZakBksPluggable *pluggable, ZakBksBookmark *b
                                 GDA_SQL_OPERATOR_TYPE_EQ,
                                 gval,
                                 NULL);
-       g_value_unset (gval);
 
        gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL);
 }
diff --git a/plugins/db/schema.sql b/plugins/db/schema.sql
new file mode 100644 (file)
index 0000000..76441b2
--- /dev/null
@@ -0,0 +1,6 @@
+CREATE TABLE bookmarks
+(
+       name character varying,
+       url character varying,
+       CONSTRAINT bookmarks_pkey PRIMARY KEY (url)
+);
index 2a7fc3acb7c49ec9f8da451496d45cfe5526b851..8143e22c606ec53575e46f7d3af4eaaf6c9ad1a4 100644 (file)
--- a/src/bks.c
+++ b/src/bks.c
@@ -216,6 +216,49 @@ PeasPluginInfo
        return ppinfo;
 }
 
+GList
+*zak_bks_bks_get_bookmarks (ZakBksBks *bks)
+{
+       GList *ret;
+
+       if (bks->pluggable == NULL)
+               {
+                       g_warning ("Not initialized.");
+               }
+       else
+               {
+                       ret = zak_bks_pluggable_get_bookmarks (bks->pluggable);
+               }
+
+       return ret;
+}
+
+void
+zak_bks_bks_add_bookmark (ZakBksBks *bks, ZakBksBookmark *bk)
+{
+       if (bks->pluggable == NULL)
+               {
+                       g_warning ("Not initialized.");
+               }
+       else
+               {
+                       zak_bks_pluggable_add_bookmark (bks->pluggable, bk);
+               }
+}
+
+void
+zak_bks_bks_remove_bookmark (ZakBksBks *bks, ZakBksBookmark *bk)
+{
+       if (bks->pluggable == NULL)
+               {
+                       g_warning ("Not initialized.");
+               }
+       else
+               {
+                       zak_bks_pluggable_remove_bookmark (bks->pluggable, bk);
+               }
+}
+
 /**
  * zak_bks_bks_destroy:
  * @bks: a #ZakBksBks object.
index c64a6ec4af7d22cfab85d5238333c568fe84dfa1..70380a29630a71361a7203a7f636d1b19e3024aa 100644 (file)
@@ -41,7 +41,7 @@ GList *zak_bks_bks_get_bookmarks (ZakBksBks *bks);
 void zak_bks_bks_add_bookmark (ZakBksBks *bks, ZakBksBookmark *bk);
 void zak_bks_bks_remove_bookmark (ZakBksBks *bks, ZakBksBookmark *bk);
 
-void zak_bks_destroy (ZakBksBks *bks);
+void zak_bks_bks_destroy (ZakBksBks *bks);
 
 
 G_END_DECLS
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..d2e1797
--- /dev/null
@@ -0,0 +1,13 @@
+AM_CPPFLAGS = $(WARN_CFLAGS) \
+              $(DISABLE_DEPRECATED_CFLAGS) \
+              $(LIBZAKBOOKMARKS_CFLAGS) \
+              -I$(top_srcdir)/src \
+              -DPLUGINSDIR=\""$(top_builddir)/plugins"\"
+
+LIBS = $(LIBZAKBOOKMARKS_LIBS) \
+       -L$(top_builddir)/src -lzakbookmarks \
+       -export-dynamic
+
+LDADD = $(top_builddir)/src/libzakbookmarks.la
+
+noinst_PROGRAMS = test
diff --git a/tests/test.c b/tests/test.c
new file mode 100644 (file)
index 0000000..86007dd
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2019 Andrea Zagli <azagli@libero.it>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib/gprintf.h>
+#include <libpeas/peas.h>
+
+#include "libzakbookmarks.h"
+
+static void
+list_func (gpointer data,
+           gpointer user_data)
+{
+       ZakBksBookmark *bk = (ZakBksBookmark *)data;
+
+       g_printf ("Bookmark: %s - %s\n", bk->name, bk->url);
+}
+
+int
+main (int argc, char **argv)
+{
+       PeasEngine *engine;
+       ZakBksBks *bks;
+       PeasPluginInfo *ppinfo;
+
+       GList *list;
+
+       ZakBksBookmark *bk;
+
+       if (argc < 2)
+               {
+                       g_error ("Usage: test <connection string>");
+                       return 0;
+               }
+
+       engine = peas_engine_get_default ();
+       peas_engine_add_search_path (engine, PLUGINSDIR, NULL);
+
+       bks = zak_bks_bks_new (argv[1]);
+       if (bks == NULL)
+               {
+                       g_error ("Error on initialization.");
+                       return 0;
+               }
+
+       ppinfo = zak_bks_bks_get_plugin_info (bks);
+       g_printf ("Plugin info\n");
+       g_printf ("Name: %s\n", peas_plugin_info_get_name (ppinfo));
+       g_printf ("Module dir: %s\n", peas_plugin_info_get_module_dir (ppinfo));
+       g_printf ("Module name: %s\n", peas_plugin_info_get_module_name (ppinfo));
+       g_printf ("\n");
+
+       g_printf ("BOOKMARKS ORIGINAL LIST\n");
+       g_printf ("-----------------------\n");
+       list = zak_bks_bks_get_bookmarks (bks);
+       g_list_foreach (list, list_func, NULL);
+       g_printf ("-----------------------\n\n");
+
+       bk = g_new0 (ZakBksBookmark, 1);
+       bk->name = g_strdup ("Google");
+       bk->url = g_strdup ("https://www.google.it");
+       zak_bks_bks_add_bookmark (bks, bk);
+
+       bk = g_new0 (ZakBksBookmark, 1);
+       bk->name = g_strdup ("DuckDuckGo");
+       bk->url = g_strdup ("https://www.duckduckgo.com");
+       zak_bks_bks_add_bookmark (bks, bk);
+
+       g_printf ("ADDED 2 BOOKMARKS\n");
+       g_printf ("-----------------------\n");
+       list = zak_bks_bks_get_bookmarks (bks);
+       g_list_foreach (list, list_func, NULL);
+       g_printf ("-----------------------\n\n");
+
+       bk = g_new0 (ZakBksBookmark, 1);
+       bk->url = g_strdup ("https://www.google.it");
+       zak_bks_bks_remove_bookmark (bks, bk);
+
+       g_printf ("REMOVED GOOGLE BOOKMARK\n");
+       g_printf ("-----------------------\n");
+       list = zak_bks_bks_get_bookmarks (bks);
+       g_list_foreach (list, list_func, NULL);
+       g_printf ("-----------------------\n\n");
+
+       zak_bks_bks_destroy (bks);
+
+       return 0;
+}