Commit 5385bd12 authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

ddl-postgresql: added tables to ddl tables tests

parent 7e68d543
......@@ -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')
......
......@@ -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')
......@@ -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)));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment