[libgda: 1/6] DDL new test for DB generation
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda: 1/6] DDL new test for DB generation
- Date: Mon, 8 Oct 2018 16:18:02 +0000 (UTC)
commit 79e6f444694925038410fd0543f9892b0ee92a95
Author: Pavlo Solntsev <p sun fun gmail com>
Date: Sun Sep 23 21:37:49 2018 -0500
DDL new test for DB generation
tests/ddl/check-ddl-db-create.c | 117 ++++++++++++++++++++++++++++++++++++++++
tests/ddl/check_db.xml | 39 ++++++++++++++
tests/ddl/meson.build | 22 ++++++++
3 files changed, 178 insertions(+)
---
diff --git a/tests/ddl/check-ddl-db-create.c b/tests/ddl/check-ddl-db-create.c
new file mode 100644
index 000000000..9a0e03f15
--- /dev/null
+++ b/tests/ddl/check-ddl-db-create.c
@@ -0,0 +1,117 @@
+/* check-ddl-creator.c
+ *
+ * Copyright 2018 Pavlo Solntsev <p sun fun 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-ddl-creator.h>
+#include <libgda/gda-ddl-base.h>
+#include <sql-parser/gda-sql-parser.h>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+typedef struct {
+ GdaDdlCreator *creator;
+ GdaConnection *cnc;
+ gchar *xmlfile;
+
+
+}CheckCreatedb;
+
+static void
+test_ddl_db_create_start(CheckCreatedb *self,
+ gconstpointer user_data)
+{
+ gda_init ();
+ self->creator = NULL;
+ self->cnc = NULL;
+
+ const gchar *topsrcdir = g_getenv ("GDA_TOP_SRC_DIR");
+
+ g_print ("ENV: %s\n",topsrcdir);
+ g_assert_nonnull (topsrcdir);
+
+ self->xmlfile = g_build_filename(topsrcdir,
+ "tests",
+ "ddl",
+ "check_db.xml",NULL);
+
+ g_assert_nonnull (self->xmlfile);
+
+ self->creator = gda_ddl_creator_new();
+
+ self->cnc = gda_connection_new_from_string("SQLite",
+ "DB_DIR=.;DB_NAME=ddl_test",
+ NULL,
+ GDA_CONNECTION_OPTIONS_NONE,
+ NULL);
+
+ g_assert_nonnull (self->cnc);
+
+ gboolean res = gda_connection_open(self->cnc,NULL);
+ g_assert_true (res);
+
+ res = gda_ddl_creator_validate_file_from_path (self->xmlfile,NULL);
+ g_assert_true (res);
+
+ res = gda_ddl_creator_parse_file_from_path(self->creator,
+ self->xmlfile,
+ NULL);
+
+ g_assert_true (res);
+}
+
+static void
+test_ddl_db_create_finish (CheckCreatedb *self,
+ gconstpointer user_data)
+{
+ gda_connection_close (self->cnc, NULL);
+ g_free (self->xmlfile);
+ g_object_unref (self->creator);
+ g_object_unref (self->cnc);
+}
+
+static void
+test_ddl_db_create_test1 (CheckCreatedb *self,
+ gconstpointer user_data)
+{
+
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ setlocale (LC_ALL,"");
+
+ g_test_init (&argc,&argv,NULL);
+
+ g_test_add ("/test-ddl/CheckCreatedb",
+ CheckCreatedb,
+ NULL,
+ test_ddl_db_create_start,
+ test_ddl_db_create_test1,
+ test_ddl_db_create_finish);
+
+ return g_test_run();
+}
+
diff --git a/tests/ddl/check_db.xml b/tests/ddl/check_db.xml
new file mode 100644
index 000000000..343be3558
--- /dev/null
+++ b/tests/ddl/check_db.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE schema SYSTEM "../../libgda/libgda-ddl-creator.dtd">
+<schema>
+ <table name="employee" temptable="FALSE">
+ <comment>employee table</comment>
+ <column name="id" type="int" pkey="TRUE"
+ unique="TRUE" nnul="TRUE" autoinc="FALSE">
+ </column>
+ <column name="employee_id" type="int" unique="TRUE"
+ nnul="TRUE" pkey="TRUE">
+ </column>
+ <column name="last_name" type="string" nnul="TRUE">
+ <comment>Some comments here</comment>
+ <value>Smith</value>
+ </column>
+ <column name="start_time" type="timestamp">
+ <value>now()</value>
+ </column>
+ <column name="remote" type="boolean">
+ </column>
+ <column name="hight" type="numeric">
+ <value scale="2">123.45</value>
+ </column>
+ <column name="job_site_id" type="int" nnul="TRUE">
+ </column>
+ <fkey reftable="job_site">
+ <fk_field name="job_site_id" reffield="id"/>
+ </fkey>
+ </table>
+ <table name="job_site" temptable="FALSE">
+ <comment>employee table</comment>
+ <column name="id" type="int" pkey="TRUE"
+ unique="TRUE" nnul="TRUE" autoinc="FALSE">
+ </column>
+ <column name="location" type="string">
+ </column>
+ </table>
+</schema>
+
diff --git a/tests/ddl/meson.build b/tests/ddl/meson.build
index 7dce8932c..7319fe77f 100644
--- a/tests/ddl/meson.build
+++ b/tests/ddl/meson.build
@@ -120,3 +120,25 @@ test('ddlfkey', ddlfkey,
'GDA_TOP_BUILD_DIR='+meson.build_root()
]
)
+ddlcreate = executable('check_ddl_create',
+ 'check-ddl-db-create.c',
+ c_args: [
+ '-include',
+ meson.build_root() + '/config.h',
+ '-DCHECK_FILES="'+meson.source_root()+'"',
+ '-DTOP_BUILD_DIR="'+meson.build_root()+'"'
+ ],
+ link_with: libgda,
+ dependencies: [
+ libgda_dep,
+ inc_rooth_dep,
+ inc_sqliteh_dep
+ ],
+ install: false
+ )
+test('ddlcreate', ddlcreate,
+ env: [
+ 'GDA_TOP_SRC_DIR='+meson.source_root(),
+ 'GDA_TOP_BUILD_DIR='+meson.build_root()
+ ]
+ )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]