[libgda] ddl-postgresql: added tables to ddl tables tests



commit 5385bd12fa2175db07841f8993214d16469b4365
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Thu Dec 13 17:52:13 2018 -0600

    ddl-postgresql: added tables to ddl tables tests

 meson.build                              |   2 +
 meson_options.txt                        |   1 +
 tests/ddl/check-ddl-creator-postgresql.c | 210 +++++++++++++++++++++++++------
 3 files changed, 172 insertions(+), 41 deletions(-)
---
diff --git a/meson.build b/meson.build
index 61db044ab..d276dc420 100644
--- a/meson.build
+++ b/meson.build
@@ -372,7 +372,9 @@ libgda_report_pc = configure_file(
        )
 endif
 
+if get_option('enable-tools')
 subdir('tools')
+endif
 subdir('tests')
 subdir('testing')
 if get_option('with-examples')
diff --git a/meson_options.txt b/meson_options.txt
index aea75eaab..8395954de 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -13,4 +13,5 @@ option('enable-debug', type : 'boolean', value : false, description : 'Enable de
 option('system-sqlite', type : 'boolean', value : true, description : 'Use SQLite installed on the system 
[default=false')
 option('with-examples', type : 'boolean', value : false, description : 'Compile examples [default=false')
 option('system-sqlcipher', type : 'boolean', value : true, description : 'Use SQLCipher installed on the 
system [default=false')
+option('enable-tools', type : 'boolean', value : false, description : 'Enable build GUI Tools')
 
diff --git a/tests/ddl/check-ddl-creator-postgresql.c b/tests/ddl/check-ddl-creator-postgresql.c
index 56df63ad8..79373c683 100644
--- a/tests/ddl/check-ddl-creator-postgresql.c
+++ b/tests/ddl/check-ddl-creator-postgresql.c
@@ -31,50 +31,130 @@ typedef struct {
   gboolean started_db;
 } CheckDdlObject;
 
-static void
-test_ddl_creator_start (CheckDdlObject *self,
-                     gconstpointer user_data)
-{
-  gda_init();
-  self->xmlfile = NULL;
-  self->creator = NULL;
-  self->cnc = NULL;
-  self->started_db = FALSE;
 
-  const gchar *topsrcdir = g_getenv ("GDA_TOP_SRC_DIR");
 
-  g_print ("ENV: %s\n",topsrcdir);
-  g_assert_nonnull (topsrcdir);
+static void create_users_table (CheckDdlObject *self) {
+  GError *error = NULL;
+  gboolean res = FALSE;
+  GdaDdlTable *table = NULL;
+  GdaDdlColumn *column_id;
+  GdaDdlColumn *column_name;
+  GdaDdlColumn *column_ctime;
+  GdaDdlColumn *column_ts;
+  GdaDdlColumn *column_state;
 
-  self->xmlfile = g_build_filename(topsrcdir,
-                                   "tests",
-                                   "ddl",
-                                   "ddl-db.xml",NULL);
+  if (self->cnc == NULL) {
+    return;
+  }
 
-  g_assert_nonnull (self->xmlfile);
+  g_assert_nonnull (self->creator);
+
+  table = gda_ddl_table_new ();
+  gda_ddl_base_set_name (GDA_DDL_BASE(table), "users");
+
+  column_id = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_id,"id");
+  gda_ddl_column_set_type (column_id, G_TYPE_INT);
+  gda_ddl_column_set_autoinc (column_id, TRUE);
+  gda_ddl_column_set_pkey (column_id, TRUE);
+
+  gda_ddl_table_append_column (table, column_id);
+
+  column_name = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_name, "name");
+  gda_ddl_column_set_type (column_name, G_TYPE_STRING);
+  gda_ddl_column_set_size (column_name, 50);
+
+  gda_ddl_table_append_column (table, column_name);
+
+  column_ctime = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_ctime, "create_time");
+  gda_ddl_column_set_type (column_ctime, GDA_TYPE_TIME);
+
+  gda_ddl_table_append_column (table, column_ctime);
+
+  column_state = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_state, "state");
+  gda_ddl_column_set_type (column_state, G_TYPE_BOOLEAN);
+
+  gda_ddl_table_append_column (table,column_state);
+
+  column_ts = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_ts, "mytimestamp");
+  gda_ddl_column_set_type (column_ts, G_TYPE_DATE_TIME);
+
+  gda_ddl_table_append_column (table, column_ts);
+
+  gda_ddl_creator_append_table (self->creator, table);
+  res = gda_ddl_table_create (table, self->cnc, TRUE, &error);
+  if (!res) {
+    g_warning ("Error Creating table: %s", error->message);
+  }
+  g_assert_true (res);
+}
+
+static void create_companies_table (CheckDdlObject *self) {
+  GError *error = NULL;
+  gboolean res = FALSE;
+  GdaDdlTable *table = NULL;
+  GdaDdlColumn *column_id;
+  GdaDdlColumn *column_name;
+  GdaDdlColumn *column_ctime;
+  GdaDdlColumn *column_ts;
+  GdaDdlColumn *column_state;
 
-  self->cnc = gda_connection_new_from_string("Postgresql",
-                                             "DB_NAME=test;HOST=localhost;USERNAME=test;PASSWORD=test1",
-                                             NULL,
-                                             GDA_CONNECTION_OPTIONS_NONE,
-                                             NULL);
   if (self->cnc == NULL) {
-    g_print ("Postgres test not run, please setup a database 'test', owned by 'test' role with password 
'test1' at localhost\n");
-    g_print ("Test Skip.\n");
     return;
   }
 
-  g_assert_nonnull (self->cnc);
+  g_assert_nonnull (self->creator);
 
-  gboolean openres = gda_connection_open(self->cnc, NULL);
-  g_assert_true (openres);
+  table = gda_ddl_table_new ();
+  gda_ddl_base_set_name (GDA_DDL_BASE(table), "companies");
 
-  self->creator = gda_connection_create_ddl_creator (self->cnc);
+  column_id = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_id,"id");
+  gda_ddl_column_set_type (column_id, G_TYPE_INT);
+  gda_ddl_column_set_autoinc (column_id, TRUE);
+  gda_ddl_column_set_pkey (column_id, TRUE);
 
-  g_assert_nonnull (self->creator);
+  gda_ddl_table_append_column (table, column_id);
 
-  /* Create DataBase structure */
+  column_name = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_name, "name");
+  gda_ddl_column_set_type (column_name, G_TYPE_STRING);
+  gda_ddl_column_set_size (column_name, 50);
+
+  gda_ddl_table_append_column (table, column_name);
+
+  column_ctime = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_ctime, "create_time");
+  gda_ddl_column_set_type (column_ctime, GDA_TYPE_TIME);
+
+  gda_ddl_table_append_column (table, column_ctime);
 
+  column_state = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_state, "state");
+  gda_ddl_column_set_type (column_state, G_TYPE_BOOLEAN);
+
+  gda_ddl_table_append_column (table,column_state);
+
+  column_ts = gda_ddl_column_new ();
+  gda_ddl_column_set_name (column_ts, "mytimestamp");
+  gda_ddl_column_set_type (column_ts, G_TYPE_DATE_TIME);
+
+  gda_ddl_table_append_column (table, column_ts);
+
+  gda_ddl_creator_append_table (self->creator, table);
+  res = gda_ddl_table_create (table, self->cnc, TRUE, &error);
+  if (!res) {
+    g_warning ("Error Creating table: %s", error->message);
+  }
+  g_assert_true (res);
+}
+
+
+static void create_countries_table (CheckDdlObject *self) {
   GError *error = NULL;
   gboolean res = FALSE;
   GdaDdlTable *table = NULL;
@@ -91,7 +171,7 @@ test_ddl_creator_start (CheckDdlObject *self,
   g_assert_nonnull (self->creator);
 
   table = gda_ddl_table_new ();
-  gda_ddl_base_set_name (GDA_DDL_BASE(table),"dntypes");
+  gda_ddl_base_set_name (GDA_DDL_BASE(table), "countries");
 
   column_id = gda_ddl_column_new ();
   gda_ddl_column_set_name (column_id,"id");
@@ -99,32 +179,32 @@ test_ddl_creator_start (CheckDdlObject *self,
   gda_ddl_column_set_autoinc (column_id, TRUE);
   gda_ddl_column_set_pkey (column_id, TRUE);
 
-  gda_ddl_table_append_column (table,column_id);
+  gda_ddl_table_append_column (table, column_id);
 
   column_name = gda_ddl_column_new ();
-  gda_ddl_column_set_name (column_name,"name");
+  gda_ddl_column_set_name (column_name, "name");
   gda_ddl_column_set_type (column_name, G_TYPE_STRING);
   gda_ddl_column_set_size (column_name, 50);
 
-  gda_ddl_table_append_column (table,column_name);
+  gda_ddl_table_append_column (table, column_name);
 
   column_ctime = gda_ddl_column_new ();
-  gda_ddl_column_set_name (column_ctime,"create_time");
+  gda_ddl_column_set_name (column_ctime, "create_time");
   gda_ddl_column_set_type (column_ctime, GDA_TYPE_TIME);
 
-  gda_ddl_table_append_column (table,column_ctime);
+  gda_ddl_table_append_column (table, column_ctime);
 
   column_state = gda_ddl_column_new ();
-  gda_ddl_column_set_name (column_state,"state");
+  gda_ddl_column_set_name (column_state, "state");
   gda_ddl_column_set_type (column_state, G_TYPE_BOOLEAN);
 
   gda_ddl_table_append_column (table,column_state);
 
   column_ts = gda_ddl_column_new ();
-  gda_ddl_column_set_name (column_ts,"mytimestamp");
+  gda_ddl_column_set_name (column_ts, "mytimestamp");
   gda_ddl_column_set_type (column_ts, G_TYPE_DATE_TIME);
 
-  gda_ddl_table_append_column (table,column_ts);
+  gda_ddl_table_append_column (table, column_ts);
 
   gda_ddl_creator_append_table (self->creator, table);
   res = gda_ddl_table_create (table, self->cnc, TRUE, &error);
@@ -134,6 +214,54 @@ test_ddl_creator_start (CheckDdlObject *self,
   g_assert_true (res);
 }
 
+static void
+test_ddl_creator_start (CheckDdlObject *self,
+                     gconstpointer user_data)
+{
+  gda_init();
+  self->xmlfile = NULL;
+  self->creator = NULL;
+  self->cnc = NULL;
+  self->started_db = FALSE;
+
+  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",
+                                   "ddl-db.xml",NULL);
+
+  g_assert_nonnull (self->xmlfile);
+
+  self->cnc = gda_connection_new_from_string("Postgresql",
+                                             "DB_NAME=test;HOST=localhost;USERNAME=test;PASSWORD=test1",
+                                             NULL,
+                                             GDA_CONNECTION_OPTIONS_NONE,
+                                             NULL);
+  if (self->cnc == NULL) {
+    g_print ("Postgres test not run, please setup a database 'test', owned by 'test' role with password 
'test1' at localhost\n");
+    g_print ("Test Skip.\n");
+    return;
+  }
+
+  g_assert_nonnull (self->cnc);
+
+  gboolean openres = gda_connection_open(self->cnc, NULL);
+  g_assert_true (openres);
+
+  self->creator = gda_connection_create_ddl_creator (self->cnc);
+
+  g_assert_nonnull (self->creator);
+
+  /* Create DataBase structure */
+  create_users_table (self);
+  create_companies_table (self);
+  create_countries_table (self);
+}
+
 static void
 test_ddl_creator_finish (CheckDdlObject *self,
                       gconstpointer user_data)
@@ -156,9 +284,9 @@ test_tables (CheckDdlObject *self,
   GList *tables = gda_ddl_creator_get_tables (self->creator);
   g_assert (tables != NULL);
   g_assert (g_list_length (tables) != 0);
-  g_assert (g_list_length (tables) == 1);
+  g_assert (g_list_length (tables) == 3);
   GList *lt = NULL;
-  for (lt = tables; lt; lt = tables->next) {
+  for (lt = tables; lt; lt = lt->next) {
     GdaDdlTable *table = (GdaDdlTable *) lt->data;
     g_message ("Table found: %s", gda_ddl_base_get_full_name (GDA_DDL_BASE (table)));
   }


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