[libgda] provider-meta: added unit test



commit eba1ebd3b3dba064130d61bf8cff341e085ddecc
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Sep 2 12:02:34 2018 -0500

    provider-meta: added unit test

 tests/Makefile.am                          |  14 ++-
 tests/data-models/check_data_select_iter.c |   2 +-
 tests/meson.build                          |  22 +++++
 tests/test-provider-meta.c                 | 132 +++++++++++++++++++++++++++++
 4 files changed, 166 insertions(+), 4 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b90048db5..d28869de4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,8 @@
 noinst_LTLIBRARIES = libgda-test-6.0.la
 
 TESTS_ENVIRONMENT = GDA_TOP_SRC_DIR="$(abs_top_srcdir)" GDA_TOP_BUILD_DIR="$(abs_top_builddir)"
-TESTS = test-ddl-creator test-bin-converter test-sql-identifier test-identifiers-quotes test-sql-builder 
test-connection-string-split test-input-parsers test-quark-list test-sql-renderer test-server-operation 
-check_PROGRAMS = test-ddl-creator test-bin-converter test-sql-identifier test-identifiers-quotes 
test-sql-builder test-connection-string-split test-input-parsers test-quark-list test-sql-renderer 
test-server-operation
+TESTS = test-ddl-creator test-bin-converter test-sql-identifier test-identifiers-quotes test-sql-builder 
test-connection-string-split test-input-parsers test-quark-list test-sql-renderer test-server-operation 
test-provider-meta
+check_PROGRAMS = test-ddl-creator test-bin-converter test-sql-identifier test-identifiers-quotes 
test-sql-builder test-connection-string-split test-input-parsers test-quark-list test-sql-renderer 
test-server-operation test-provider-meta
 
 if HAVE_UI
 UI_EXTENSION = ui
@@ -17,7 +17,8 @@ AM_CPPFLAGS = \
         $(COREDEPS_CFLAGS) \
        $(COREDEPS_WFLAGS) \
        -DCHECK_FILES=\""$(top_srcdir)"\" \
-       -DTOP_BUILD_DIR=\""$(top_builddir)"\"
+       -DTOP_BUILD_DIR=\""$(top_builddir)"\" \
+       -DBUILD_DIR=\""$(builddir)"\"
 
 test_headers = \
         raw-ddl-creator.h
@@ -109,6 +110,13 @@ test_server_operation_LDADD = \
         $(top_builddir)/libgda/libgda-6.0.la \
         $(COREDEPS_LIBS)
 
+test_provider_meta_SOURCES = \
+        test-provider-meta.c
+
+test_provider_meta_LDADD = \
+        $(top_builddir)/libgda/libgda-6.0.la \
+        $(COREDEPS_LIBS)
+
 EXTRA_DIST = dbstruct.xml
 
 DISTCLEANFILES= \
diff --git a/tests/data-models/check_data_select_iter.c b/tests/data-models/check_data_select_iter.c
index a9001595b..c8e1983ce 100644
--- a/tests/data-models/check_data_select_iter.c
+++ b/tests/data-models/check_data_select_iter.c
@@ -1,4 +1,4 @@
-/* check-ddl-creator.c
+/* check-data-select-iter.c
  *
  * Copyright 2018 Daniel Espinosa <esodan gmail com>
  *
diff --git a/tests/meson.build b/tests/meson.build
index 723a9d3d5..4c66858a1 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -252,6 +252,28 @@ test('ServerOperation', tso,
                ]
        )
 
+tmp = executable('test-provider-meta',
+       ['test-provider-meta.c'] ,
+       c_args: [
+               '-include',
+               meson.build_root() + '/config.h',
+               '-DBUILD_DIR="'+meson.current_build_dir()+'"'
+               ],
+       link_with: libgda,
+       dependencies: [
+               libgda_dep,
+               inc_rooth_dep,
+               inc_sqliteh_dep
+               ],
+       install: false
+       )
+test('ProviderMeta', tso,
+       env: [
+               'GDA_TOP_SRC_DIR='+meson.source_root(),
+               'GDA_TOP_BUILD_DIR='+meson.build_root()
+               ]
+       )
+
 subdir('data-models')
 subdir('meta-store')
 subdir('multi-threading')
diff --git a/tests/test-provider-meta.c b/tests/test-provider-meta.c
new file mode 100644
index 000000000..2f9c783f7
--- /dev/null
+++ b/tests/test-provider-meta.c
@@ -0,0 +1,132 @@
+/* test-provider-meta.c
+ *
+ * Copyright 2018 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <locale.h>
+#include <libgda/libgda.h>
+#include <libgda/gda-provider-meta.h>
+
+typedef struct {
+  GdaConnection *cnn;
+} CheckProviderMeta;
+
+void init_data (CheckProviderMeta *data, gconstpointer user_data);
+void finish_data (CheckProviderMeta *data, gconstpointer user_data);
+void test_iface (CheckProviderMeta *data, gconstpointer user_data);
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  setlocale (LC_ALL,"");
+
+  gda_init ();
+
+
+  g_test_init (&argc,&argv,NULL);
+
+  g_test_add ("/gda/provider-meta/iface",
+              CheckProviderMeta,
+              NULL,
+              init_data,
+              test_iface,
+              finish_data);
+
+  return g_test_run();
+}
+
+void
+init_data (CheckProviderMeta *data, gconstpointer user_data) {
+  GString *strc, *cstr;
+  GdaConnection *cnn;
+  GError *error = NULL;
+  GFile *dir, *dbf;
+
+  dir = g_file_new_for_path (BUILD_DIR);
+  g_assert (g_file_query_exists (dir, NULL));
+  cstr = g_string_new ("");
+  g_string_printf (cstr, "%s/iter.db", g_file_get_uri (dir));
+  dbf = g_file_new_for_uri (cstr->str);
+  if (g_file_query_exists (dbf, NULL)) {
+    g_file_delete (dbf, NULL, &error);
+    if (error) {
+      g_print ("Error deleting DB file: %s", error->message != NULL ? error->message : "No detail");
+      g_assert_not_reached ();
+    }
+  }
+  g_object_unref (dbf);
+
+  strc = g_string_new ("");
+  g_string_printf (strc,"DB_DIR=%s;DB_NAME=iter", g_file_get_path (dir));
+
+  cnn = gda_connection_open_from_string ("SQLite",
+                                         strc->str,
+                                         NULL,
+                                         GDA_CONNECTION_OPTIONS_NONE,
+                                         &error);
+
+  g_string_free (strc, TRUE);
+
+  if (error) {
+    g_print ("Error creating/opening database: %s", error->message != NULL ? error->message : "No detail");
+    g_assert_not_reached ();
+  }
+  g_print ("Initializing DB\n");
+  gint rows = 0;
+  gda_connection_execute_non_select_command (cnn, "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)", 
&error);
+  if (error) {
+    g_print ("Error creating table users: %s", error->message != NULL ? error->message : "No detail");
+    g_assert_not_reached ();
+  }
+  rows = gda_connection_execute_non_select_command (cnn, "INSERT INTO users (name) VALUES (\'user1\');", 
&error);
+  g_assert (rows == 1);
+  if (error) {
+    g_print ("Error inserting data into table users: %s", error->message != NULL ? error->message : "No 
detail");
+    g_assert_not_reached ();
+  }
+  rows = gda_connection_execute_non_select_command (cnn, "INSERT INTO users (name) VALUES (\'user2\');", 
&error);
+  g_assert (rows == 1);
+  if (error) {
+    g_print ("Error inserting data into table users: %s", error->message != NULL ? error->message : "No 
detail");
+    g_assert_not_reached ();
+  }
+  rows = gda_connection_execute_non_select_command (cnn, "INSERT INTO users (name) VALUES (\'user3\');", 
&error);
+  g_assert (rows == 1);
+  if (error) {
+    g_print ("Error inserting data into table users: %s", error->message != NULL ? error->message : "No 
detail");
+    g_assert_not_reached ();
+  }
+  data->cnn = cnn;
+}
+
+
+void
+finish_data (CheckProviderMeta *data, gconstpointer user_data) {
+  g_object_unref (data->cnn);
+}
+
+
+void test_iface (CheckProviderMeta *data, gconstpointer user_data) {
+  GdaConnection *cnn = data->cnn;
+  GdaServerProvider *prov = gda_connection_get_provider (cnn);
+
+  g_assert (prov != NULL);
+  g_assert (GDA_IS_PROVIDER_META (prov));
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]