コード例 #1
0
END_TEST


START_TEST (detect_smart_no)
{
    OSyncError *error = NULL;

    OSyncFormatEnv *env = osync_format_env_new(&error);
    fail_unless(error == NULL);

    OSyncObjFormat *format1 = osync_objformat_new("Format1", "Type1", &error);
    OSyncObjFormat *format2 = osync_objformat_new("Format2", "Type1", &error);
    fail_unless(error == NULL);

    OSyncFormatConverter *conv = osync_converter_new_detector(format2, format1, detect_false, &error);
    fail_unless(error == NULL);

    osync_format_env_register_converter(env, conv, &error);

    mark_point();

    OSyncData *data = osync_data_new("test", 5, format2, &error);
    fail_unless(error == NULL);

    OSyncObjFormat *result = osync_format_env_detect_objformat(env, data);
    fail_unless(!result);
    fail_unless(osync_data_get_objformat(data) == format2);

    osync_data_unref(data);
    osync_format_env_unref(env);
}
コード例 #2
0
ファイル: support.c プロジェクト: luizluca/opensync-luizluca
OSyncFormatEnv *osync_testing_load_formatenv(const char *formatdir)
{
	OSyncError *error = NULL;
	OSyncFormatEnv *formatenv = osync_format_env_new(&error);
	fail_unless(formatenv != NULL, NULL);
	fail_unless(error == NULL, NULL);
	fail_unless(osync_format_env_load_plugins(formatenv, formatdir, &error));
	return formatenv;
}
コード例 #3
0
END_TEST

START_TEST (mapping_compare)
{
	char *testbed = setup_testbed(NULL);
	char *formatdir = g_strdup_printf("%s/formats",  testbed);
	
	OSyncError *error = NULL;
	
	OSyncFormatEnv *formatenv = osync_format_env_new(&error);
	fail_unless(formatenv != NULL, NULL);
	fail_unless(error == NULL, NULL);
	
	fail_unless(osync_format_env_load_plugins(formatenv, formatdir, &error), NULL);
	fail_unless(error == NULL, NULL);
	
	OSyncObjFormat *format = osync_format_env_find_objformat(formatenv, "mockformat1");
	fail_unless(format != NULL, NULL);
	
	/*OSyncChange *change = osync_change_new(&error);
	fail_unless(change != NULL, NULL);
	fail_unless(error == NULL, NULL);
	osync_change_set_uid(change, "uid");*/
	
	OSyncData *data1 = osync_data_new("test", 5, format, &error);
	fail_unless(data1 != NULL, NULL);
	fail_unless(error == NULL, NULL);
	
	OSyncMapping *mapping = osync_mapping_new(&error);
	fail_unless(mapping != NULL, NULL);
	fail_unless(error == NULL, NULL);
	
	OSyncMappingEntry *entry = osync_mapping_entry_new(&error);
	fail_unless(entry != NULL, NULL);
	fail_unless(error == NULL, NULL);
	//osync_mapping_entry_update(entry, change);
	
	osync_format_env_free(formatenv);
	
	g_free(formatdir);
	
	destroy_testbed(testbed);
}
コード例 #4
0
static osync_bool plugin_list(OSyncError **error) {
	OSyncList *plugins;
	OSyncList *list;
	
	assert(!plugin_env);

	if (!(plugin_env = osync_plugin_env_new(error)))
		goto error;

	if (!(format_env = osync_format_env_new(error)))
		goto error_free_pluginenv;

	if (!osync_format_env_load_plugins(format_env, formatpath, error))
		goto error_free_formatenv;

	if (!osync_plugin_env_load(plugin_env, pluginpath, error))
		goto error_free_formatenv;

	plugins = osync_plugin_env_get_plugins(plugin_env);
	list = plugins;
	while(list) {
		OSyncPlugin* plugin = (OSyncPlugin*)list->data;
		fprintf (stdout, "Name:        %s\n", osync_plugin_get_name(plugin));
		fprintf (stdout, "Description: %s\n", osync_plugin_get_description(plugin));
		list = list->next;
	}
	osync_list_free(plugins);
	return TRUE;
	
 error_free_formatenv:
	osync_format_env_unref(format_env);
	format_env = NULL;
 error_free_pluginenv:
	osync_plugin_env_unref(plugin_env);
	plugin_env = NULL;
 error:	
	return FALSE;
}
コード例 #5
0
static osync_bool init(OSyncError **error) {
	OSyncPluginConfig *config;
	assert(!plugin);
	assert(!plugin_env);

	if (!(plugin_env = osync_plugin_env_new(error)))
		goto error;

	if (!(format_env = osync_format_env_new(error)))
		goto error_free_pluginenv;

	if (!osync_format_env_load_plugins(format_env, formatpath, error))
		goto error_free_formatenv;

	if (osync_error_is_set(error)) {
		fprintf(stderr, "WARNING! Some plugins couldn't get loaded in "
				"format plugin environment: %s\n", osync_error_print(error));
		osync_error_unref(error);
	}

	if (!osync_plugin_env_load(plugin_env, pluginpath, error))
		goto error_free_pluginenv;

	if (osync_error_is_set(error)) {
		fprintf(stderr, "WARNING! Some plugins couldn't get loaded in "
				"plugin environment: %s\n", osync_error_print(error));
		osync_error_unref(error);
	}

	if (!(plugin = osync_plugin_env_find_plugin(plugin_env, pluginname))) {
		osync_error_set(error, OSYNC_ERROR_PLUGIN_NOT_FOUND, "Plugin not found: \"%s\"", pluginname);
		goto error_free_pluginenv;
	}

	if (!(plugin_info = osync_plugin_info_new(error)))
		goto error_free_pluginenv;

	config = osync_plugin_config_new(error);
	if (!config)
		goto error_free_plugininfo;

	if (osync_plugin_get_config_type(plugin) != OSYNC_PLUGIN_NO_CONFIGURATION && configfile) {
		OSyncList *r = NULL;
		if (!osync_plugin_config_file_load(config, configfile, error))
			goto error_free_pluginconfig;

		osync_plugin_info_set_config(plugin_info, config);

		/** Redudant(aka. stolen) code from opensync/client/opensync_client.c */
		/* Enable active sinks */

		if (config)
			r = osync_plugin_config_get_resources(config);

		for (; r; r = r->next) {
			OSyncPluginResource *res = r->data;
			OSyncObjTypeSink *sink;

			const char *objtype = osync_plugin_resource_get_objtype(res); 
			OSyncList *o = NULL;
			/* Check for ObjType sink */
			if (!(sink = osync_plugin_info_find_objtype(plugin_info, objtype))) {
				sink = osync_objtype_sink_new(objtype, error);
				if (!sink)
					goto error_free_pluginconfig;

				osync_plugin_info_add_objtype(plugin_info, sink);
			}
			OSyncList *objformats = osync_plugin_resource_get_objformat_sinks(res);
			for ( o = objformats; o; o = o->next) {
				OSyncObjFormatSink *format_sink = (OSyncObjFormatSink *) o->data; 
				osync_objtype_sink_add_objformat_sink(sink, format_sink);
			}
			osync_list_free(objformats);
		}

		osync_plugin_config_unref(config);

	}

	if (!configfile && osync_plugin_get_config_type(plugin) == OSYNC_PLUGIN_NEEDS_CONFIGURATION) {
		osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Plugin \"%s\" requires configuration!", pluginname); 
		goto error_free_pluginconfig;
	}

	assert(!ctx);
	ctx = g_main_context_new();

	osync_plugin_info_set_configdir(plugin_info, configdir);
	osync_plugin_info_set_loop(plugin_info, ctx);
	osync_plugin_info_set_format_env(plugin_info, format_env);
	osync_plugin_info_set_groupname(plugin_info, syncgroup);

	return TRUE;

	/*
		error_free_loop:
		g_main_context_unref(ctx);
	*/
 error_free_pluginconfig:
	osync_plugin_config_unref(config);
 error_free_plugininfo:
	osync_plugin_info_unref(plugin_info);
 error_free_formatenv:
	osync_format_env_unref(format_env);
	format_env = NULL;
 error_free_pluginenv:
	osync_plugin_env_unref(plugin_env);
	plugin_env = NULL;
 error:	
	return FALSE;
}