int main (int argc, char *argv[])
{
	g_test_init (&argc, &argv, NULL);	
	
	midgard_init();

	/* FIXME, it should be fixed with API... */
	MidgardSchema *schema = g_object_new(MIDGARD_TYPE_SCHEMA, NULL);
	midgard_schema_init(schema, NULL);
	midgard_schema_read_dir(schema, NULL);

	MidgardConfig *config = NULL;
	guint loghandler =
		g_log_set_handler("midgard-core", G_LOG_LEVEL_MASK, midgard_error_default_log, NULL);
	mgd_global = midgard_test_connection_open_user_config(CONFIG_CONFIG_NAME, &config);
	//midgard_connection_set_loglevel(mgd_global, "debug", NULL);

	MidgardWorkspace *mw = NULL;

	g_test_add("/midgard_workspace/new", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,  
			midgard_test_workspace_new, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/create", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,  
			midgard_test_workspace_create, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/update", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,
			midgard_test_workspace_update, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/purge", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,
			midgard_test_workspace_purge, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/exists", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,
			midgard_test_workspace_exists, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/get_by_path", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,  
			midgard_test_workspace_get_by_path, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/get_path", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,
			midgard_test_workspace_get_path, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/list_workspace_names", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,
			midgard_test_workspace_list_workspace_names, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/get_workspace_by_name", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,
			midgard_test_workspace_get_workspace_by_name, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/list_children", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,  
			midgard_test_workspace_list_children, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/get_context", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,  
			midgard_test_workspace_get_context, midgard_test_workspace_teardown_foo);
	g_test_add("/midgard_workspace/is_in_context", MidgardWorkspaceTest, mw, midgard_test_workspace_setup,  
			midgard_test_workspace_is_in_context, midgard_test_workspace_teardown_foo);

	/* Finalize */
	///_MGD_TEST_UNREF_GOBJECT(user)
	//_MGD_TEST_UNREF_SCHEMA
	//_MGD_TEST_UNREF_MIDGARD

	return g_test_run();
}
int main (int argc, char *argv[])
{
	g_test_init (&argc, &argv, NULL);	
	
	midgard_init();

	/* FIXME, it should be fixed with API... */
	MidgardSchema *schema = g_object_new(MIDGARD_TYPE_SCHEMA, NULL);
	midgard_schema_init(schema, NULL);
	midgard_schema_read_dir(schema, NULL);

	MidgardConfig *config = NULL;
	guint loghandler =
		g_log_set_handler("midgard-core", G_LOG_LEVEL_MASK, midgard_error_default_log, NULL);
	mgd_global = midgard_test_connection_open_user_config(CONFIG_CONFIG_NAME, &config);
	midgard_connection_set_loglevel(mgd_global, "debug", NULL);

	MidgardWorkspace *mw = NULL;

	g_test_add("/midgard_object/workspace/create", MidgardObjectWorkspaceTest, mw, midgard_test_object_workspace_setup,  
			midgard_test_object_workspace_create, midgard_test_object_workspace_teardown_foo);
	g_test_add("/midgard_object/workspace/select_created", MidgardObjectWorkspaceTest, mw, midgard_test_object_workspace_setup,  
			midgard_test_object_workspace_select_created, midgard_test_object_workspace_teardown_foo);
	g_test_add("/midgard_object/workspace_context/select_created", MidgardObjectWorkspaceTest, mw, midgard_test_object_workspace_setup,  
			midgard_test_object_workspace_context_select_created, midgard_test_object_workspace_teardown_foo);
	g_test_add("/midgard_object/workspace/update", MidgardObjectWorkspaceTest, mw, midgard_test_object_workspace_setup,  
			midgard_test_object_workspace_update, midgard_test_object_workspace_teardown_foo);
	g_test_add("/midgard_object/workspace_context/update", MidgardObjectWorkspaceTest, mw, midgard_test_object_workspace_setup,  
			midgard_test_object_workspace_context_update, midgard_test_object_workspace_teardown_foo);
	g_test_add("/midgard_object/workspace/select_updated", MidgardObjectWorkspaceTest, mw, midgard_test_object_workspace_setup,  
			midgard_test_object_workspace_select_updated, midgard_test_object_workspace_teardown_foo);
	g_test_add("/midgard_object/workspace/delete", MidgardObjectWorkspaceTest, mw, midgard_test_object_workspace_setup,  
			midgard_test_object_workspace_delete, midgard_test_object_workspace_teardown_foo);

	/* Finalize */
	///_MGD_TEST_UNREF_GOBJECT(user)
	//_MGD_TEST_UNREF_SCHEMA
	//_MGD_TEST_UNREF_MIDGARD

	return g_test_run();
}
예제 #3
0
gboolean __midgard_connection_open(
		MidgardConnection *mgd, 
		GHashTable **hashtable, gboolean init_schema)
{
	g_return_val_if_fail(mgd != NULL, FALSE);

	MIDGARD_ERRNO_SET (mgd, MGD_ERR_OK);

	gchar *host, *dbname, *dbuser, *dbpass, *loglevel, *tmpstr;
	guint port = 0;
	gchar *auth = NULL;
	MidgardConfig *config = mgd->priv->config;
	host = config->host;
	dbname = config->database;
	dbuser = config->dbuser;
	dbpass = config->dbpass;
	loglevel = config->loglevel;
	port = config->dbport;
	gboolean enable_threads = config->gdathreads;

	/* Get 30% performance boost for non threaded applications */
	if(!enable_threads) 
		g_setenv("LIBGDA_NO_THREADS", "yes", TRUE);

	/* Initialize libgda */
	gda_init ();

	midgard_connection_set_loglevel(mgd, loglevel, NULL);

	if(config->priv->dbtype == MIDGARD_DB_TYPE_SQLITE) {

		gchar *path = NULL;
		gchar *dbdir = config->dbdir;
		if (!dbdir || *dbdir == '\0') {
			const gchar *sqlite_dir[] = {"data", NULL};
			path = midgard_core_config_build_path(sqlite_dir, NULL, TRUE);
		} else {
			path = g_strdup(dbdir);
		}

		tmpstr = g_strconcat("DB_DIR=", path, ";", "DB_NAME=", dbname, NULL);
		g_free(path);

	} else if (config->priv->dbtype == MIDGARD_DB_TYPE_ORACLE) {

		GString *cnc = g_string_sized_new(100);
		cnc_add_part(cnc, "TNSNAME", dbname, MGD_MYSQL_HOST);
		cnc_add_part(cnc, "HOST", host, MGD_MYSQL_HOST);
		cnc_add_part(cnc, "DB_NAME", dbname, MGD_MYSQL_DATABASE);
		tmpstr = g_string_free(cnc, FALSE);
		cnc = g_string_sized_new(100);
		cnc_add_part(cnc, "USERNAME", dbuser, MGD_MYSQL_USERNAME);
		cnc_add_part(cnc, "PASSWORD", dbpass, MGD_MYSQL_PASSWORD);
		auth = g_string_free(cnc, FALSE);

	} else { 
		
		GString *cnc = g_string_sized_new(100);
		cnc_add_part(cnc, "HOST", host, MGD_MYSQL_HOST);

		if (port > 0) {

			GString *_strp = g_string_new("");
			g_string_append_printf (_strp, "%d", port);
			cnc_add_part (cnc, "PORT", _strp->str, "");
			g_string_free (_strp, TRUE);
		}

		cnc_add_part(cnc, "DB_NAME", dbname, MGD_MYSQL_DATABASE);
		tmpstr = g_string_free(cnc, FALSE);
		GString *auth_str = g_string_sized_new(100);
		cnc_add_part(auth_str, "USERNAME", dbuser, MGD_MYSQL_USERNAME);
		cnc_add_part(auth_str, "PASSWORD", dbpass, MGD_MYSQL_PASSWORD);
		auth = g_string_free(auth_str, FALSE);
	}

	GError *error = NULL;
	GdaConnection *connection = gda_connection_open_from_string(
			config->dbtype, tmpstr, auth, GDA_CONNECTION_OPTIONS_NONE, &error);
	g_free(auth);	

	if(connection == NULL) {

		MIDGARD_ERRNO_SET_STRING (mgd, MGD_ERR_NOT_CONNECTED, 
				" Database [%s]. %s", tmpstr, error->message);

		g_free(tmpstr);

		return FALSE;
	
	} 

	g_free(tmpstr);

	mgd->priv->parser = gda_connection_create_parser (connection);
	if (!mgd->priv->parser)
		mgd->priv->parser = gda_sql_parser_new();
	g_assert (mgd->priv->parser != NULL);

	mgd->priv->connection = connection;
	midgard_core_connection_connect_error_callback (mgd);	

	if(init_schema) {
		
		if(!g_type_from_name("midgard_quota")) {
			
			MidgardSchema *schema = g_object_new(MIDGARD_TYPE_SCHEMA, NULL);
			gchar *path = g_build_path(G_DIR_SEPARATOR_S, config->sharedir, "MidgardObjects.xml", NULL);
			midgard_schema_init(schema, (const gchar *)path);
			g_free(path);
			midgard_schema_read_dir(schema, config->sharedir);
			
			mgd->priv->schema = schema;
		}
	}

	//midgard_connection_set_loglevel(mgd, loglevel, NULL);

	/* Loads available authentication types */
	midgard_core_connection_initialize_auth_types(mgd);

	g_signal_emit (mgd, MIDGARD_CONNECTION_GET_CLASS (mgd)->signal_id_connected, 0);

	return TRUE;
}