/* * Test 1: gda_connection_open() when there is no error */ static guint test1 (void) { g_print ("============= %s started =============\n", __FUNCTION__); GdaConnection *cnc; GError *error = NULL; cnc = gda_connection_new_from_string ("SQLite", "DB_NAME=test-cnc-opendb", NULL, GDA_CONNECTION_OPTIONS_AUTO_META_DATA, &error); if (!cnc) { g_print ("gda_connection_new_from_string() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } guint counter = 0; setup_main_context (cnc, &counter); if (! gda_connection_open (cnc, &error)) { g_print ("gda_connection_open() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } if (counter == 0) { g_print ("gda_connection_open() failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); g_object_unref (cnc); return 0; }
/* * Test 2: */ static gpointer test2_th (GdaConnection *cnc) { /* setup main context */ guint counter = 0; setup_main_context (cnc, 10, &counter); #define LOCK_DELAY 50000 gda_lockable_lock (GDA_LOCKABLE (cnc)); /*g_print ("Locked by %p\n", g_thread_self());*/ g_usleep (LOCK_DELAY); gda_lockable_unlock (GDA_LOCKABLE (cnc)); g_thread_yield (); gda_lockable_lock (GDA_LOCKABLE (cnc)); /*g_print ("Locked by %p\n", g_thread_self());*/ g_usleep (LOCK_DELAY); gda_lockable_unlock (GDA_LOCKABLE (cnc)); g_thread_yield (); gda_lockable_lock (GDA_LOCKABLE (cnc)); /*g_print ("Locked by %p\n", g_thread_self());*/ g_usleep (LOCK_DELAY); gda_lockable_unlock (GDA_LOCKABLE (cnc)); g_thread_yield (); gda_lockable_lock (GDA_LOCKABLE (cnc)); /*g_print ("Locked by %p\n", g_thread_self());*/ g_usleep (LOCK_DELAY); gda_lockable_unlock (GDA_LOCKABLE (cnc)); guint *ret; ret = g_new (guint, 1); *ret = counter; return ret; }
static guint test4 (void) { g_print ("============= %s started =============\n", __FUNCTION__); GdaConnection *cnc; GError *error = NULL; cnc = gda_connection_new_from_string ("SQLite", "DB_NAMEEEE=test-cnc-opendb", NULL, GDA_CONNECTION_OPTIONS_AUTO_META_DATA, &error); if (!cnc) { g_print ("gda_connection_new_from_string() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } guint counter = 0; setup_main_context (cnc, &counter); GMainLoop *loop; loop = g_main_loop_new (gda_connection_get_main_context (cnc, NULL), FALSE); guint job_id; job_id = gda_connection_open_async (cnc, (GdaConnectionOpenFunc) test4_open_func, loop, &error); if (!job_id) { g_print ("gda_connection_open_async() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } else { g_print ("Connection opening job is %u\n", job_id); } g_main_loop_run (loop); gboolean opened; opened = gda_connection_is_opened (cnc); g_object_unref (cnc); if (counter == 0) { g_print ("gda_connection_open() failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); return opened ? 1 : 0; }
/* * Test 1: gda_connection_open() when there is no error */ static guint test1 (void) { g_print ("============= %s started =============\n", __FUNCTION__); GdaConnection *cnc; GError *error = NULL; gchar *cnc_string, *fname; fname = g_build_filename (ROOT_DIR, "data", NULL); cnc_string = g_strdup_printf ("DB_DIR=%s;DB_NAME=sales_test", fname); g_free (fname); cnc = gda_connection_new_from_string ("SQLite", cnc_string, NULL, GDA_CONNECTION_OPTIONS_READ_ONLY, NULL); if (!cnc) { g_print ("gda_connection_new_from_string([%s]) failed: %s\n", cnc_string, error && error->message ? error->message : "No detail"); g_free (cnc_string); return 1; } guint counter = 0; setup_main_context (cnc, &counter); /* connection open */ if (! gda_connection_open (cnc, &error)) { g_print ("gda_connection_open([%s]) failed: %s\n", cnc_string, error && error->message ? error->message : "No detail"); g_free (cnc_string); return 1; } g_free (cnc_string); if (counter == 0) { g_print ("gda_connection_open() failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); g_print ("Connection %p Opened\n", cnc); /* Update meta store */ counter = 0; if (! gda_connection_update_meta_store (cnc, NULL, &error)) { g_print ("gda_connection_update_meta_store () failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } if (counter == 0) { g_print ("gda_connection_update_meta_store() failed: did not make GMainContext 'run'\n"); g_object_unref (cnc); return 1; } else g_print ("Counter incremented to %u\n", counter); /* get meta data */ counter = 0; GdaDataModel *model; model = gda_connection_get_meta_store_data (cnc, GDA_CONNECTION_META_TABLES, &error, 0); if (!model) { g_print ("gda_connection_get_meta_store_data () failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } if (counter == 0) { g_print ("gda_connection_get_meta_store_data() failed: did not make GMainContext 'run'\n"); g_object_unref (cnc); return 1; } else g_print ("Counter incremented to %u\n", counter); gda_data_model_dump (model, NULL); g_object_unref (model); g_object_unref (cnc); return 0; }
/* * Test 5: open, close and open again, also tests signal's emission */ static guint test5 (void) { g_print ("============= %s started =============\n", __FUNCTION__); GdaConnection *cnc; GError *error = NULL; cnc = gda_connection_new_from_string ("SQLite", "DB_NAME=test-cnc-opendb", NULL, GDA_CONNECTION_OPTIONS_AUTO_META_DATA, &error); if (!cnc) { g_print ("gda_connection_new_from_string() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } guint nsignals = 0; g_signal_connect (cnc, "status-changed", G_CALLBACK (t5_status_changed_cb), &nsignals); guint counter = 0; setup_main_context (cnc, &counter); /* open */ if (! gda_connection_open (cnc, &error)) { g_print ("gda_connection_open() 1 failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } if (counter == 0) { g_print ("gda_connection_open() 1 failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); /* open */ counter = 0; if (! gda_connection_close (cnc, &error)) { g_print ("gda_connection_close() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } if (counter == 0) { g_print ("gda_connection_close() failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); /* open */ counter = 0; if (! gda_connection_open (cnc, &error)) { g_print ("gda_connection_open() 2 failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } if (counter == 0) { g_print ("gda_connection_open() 2 failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); g_object_unref (cnc); if (nsignals != 6) { g_print ("Expected %d signals and got %d\n", 6, nsignals); return 1; } return 0; }
/* * Test 1: gda_connection_open() when there is no error */ static guint test1 (void) { g_print ("============= %s started =============\n", __FUNCTION__); GdaConnection *cnc; GError *error = NULL; gchar *cnc_string, *fname; fname = g_build_filename (ROOT_DIR, "data", NULL); cnc_string = g_strdup_printf ("DB_DIR=%s;DB_NAME=sales_test", fname); g_free (fname); cnc = gda_connection_new_from_string ("SQLite", cnc_string, NULL, GDA_CONNECTION_OPTIONS_READ_ONLY, NULL); if (!cnc) { g_print ("gda_connection_new_from_string([%s]) failed: %s\n", cnc_string, error && error->message ? error->message : "No detail"); g_free (cnc_string); return 1; } guint counter = 0; setup_main_context (cnc, 0, &counter); /* connection open */ if (! gda_connection_open (cnc, &error)) { g_print ("gda_connection_open([%s]) failed: %s\n", cnc_string, error && error->message ? error->message : "No detail"); g_free (cnc_string); return 1; } g_free (cnc_string); if (counter == 0 && !connected) { g_print ("gda_connection_open() failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); g_print ("Connection %p Opened\n", cnc); /* SELECT */ counter = 0; GdaDataModel *model; model = gda_connection_execute_select_command (cnc, "SELECT * FROM customers", &error); if (model) { gda_data_model_dump (model, NULL); gint expnrows = 5; if (gda_data_model_get_n_rows (model) != expnrows) { g_print ("SELECT Exec() failed: expected %d and got %d\n", expnrows, gda_data_model_get_n_rows (model)); g_object_unref (model); g_object_unref (cnc); return 1; } g_object_unref (model); } else { g_print ("gda_connection_execute_select_command() failed: %s\n", error && error->message ? error->message : "No detail"); g_object_unref (cnc); return 1; } if (counter == 0 && !connected) { g_print ("gda_connection_open() failed: did not make GMainContext 'run'\n"); g_object_unref (cnc); return 1; } else g_print ("Counter incremented to %u\n", counter); g_object_unref (cnc); return 0; }