From: <svn...@op...> - 2009-07-31 11:32:36
|
Author: bellmich Date: Fri Jul 31 13:32:17 2009 New Revision: 1223 URL: http://libsyncml.opensync.org/changeset/1223 Log: added SmlDataSyncMapItem object incl. tests The object is not integrated into the interfaces today. Added: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h trunk/tests/check_data_sync_api_map_item.c Modified: trunk/libsyncml/CMakeLists.txt trunk/tests/CMakeLists.txt trunk/tests/check_data_sync_api_location.c Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Mon Jul 20 13:10:53 2009 (r1222) +++ trunk/libsyncml/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) @@ -24,6 +24,7 @@ data_sync_api/data_sync_client.c data_sync_api/data_sync_server.c data_sync_api/sml_location.c + data_sync_api/sml_data_sync_map_item.c data_sync_api/transport_http_client.c data_sync_api/transport_http_server.c data_sync_api/transport_obex_client.c @@ -78,6 +79,7 @@ INSTALL( FILES data_sync_api/sml_location.h + data_sync_api/sml_data_sync_map_item.h data_sync_api/defines.h data_sync_api/standard.h data_sync_api/callbacks.h Added: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c Fri Jul 31 13:32:17 2009 (r1223) @@ -0,0 +1,270 @@ +/* sml_data_sync_map_item.c + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "sml_data_sync_map_item.h" +#include "../sml_error_internals.h" +#include <string.h> + +G_DEFINE_TYPE (SmlDataSyncMapItem, sml_data_sync_map_item, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_REMOTE, + PROP_LOCAL +}; + +struct _SmlDataSyncMapItemPrivate +{ + SmlLocation* remote; + SmlLocation* local; +}; + +static void +sml_data_sync_map_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + g_value_set_object (value, SML_DATA_SYNC_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + g_value_set_object (value, SML_DATA_SYNC_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_data_sync_map_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + if (SML_DATA_SYNC_MAP_ITEM (object)->priv->remote) + g_object_unref (SML_DATA_SYNC_MAP_ITEM (object)->priv->remote); + SML_DATA_SYNC_MAP_ITEM (object)->priv->remote = SML_LOCATION (value); + g_object_ref(SML_DATA_SYNC_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + if (SML_DATA_SYNC_MAP_ITEM (object)->priv->local) + g_object_unref (SML_DATA_SYNC_MAP_ITEM (object)->priv->local); + SML_DATA_SYNC_MAP_ITEM (object)->priv->local = SML_LOCATION (value); + g_object_ref(SML_DATA_SYNC_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_data_sync_map_item_finalize (GObject *object) +{ + SmlDataSyncMapItem *self = (SmlDataSyncMapItem *) object; + g_object_unref(self->priv->remote); + g_object_unref(self->priv->local); + /* all pointers must be NULL */ + self->priv->remote = NULL; + self->priv->local = NULL; + G_OBJECT_CLASS (sml_data_sync_map_item_parent_class)->finalize (object); +} + +static void +sml_data_sync_map_item_class_init (SmlDataSyncMapItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlDataSyncMapItemPrivate)); + + object_class->get_property = sml_data_sync_map_item_get_property; + object_class->set_property = sml_data_sync_map_item_set_property; + object_class->finalize = sml_data_sync_map_item_finalize; + + /** + * SmlDataSyncMapItem:remote: + * + * The remote property. + */ + g_object_class_install_property (object_class, + PROP_REMOTE, + g_param_spec_object ("remote", + "remote", + "remote", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + /** + * SmlDataSyncMapItem:local: + * + * The local property. + */ + g_object_class_install_property (object_class, + PROP_LOCAL, + g_param_spec_object ("local", + "local", + "local", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + +} + +static void +sml_data_sync_map_item_init (SmlDataSyncMapItem *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_DATA_SYNC_MAP_ITEM, + SmlDataSyncMapItemPrivate); +} + +/** + * sml_data_sync_map_item_new: + * + * Creates a new instance of #SmlDataSyncMapItem. + * + * Return value: the newly created #SmlDataSyncMapItem instance + */ +SmlDataSyncMapItem* +sml_data_sync_map_item_new (void) +{ + return g_object_new (SML_TYPE_DATA_SYNC_MAP_ITEM, NULL); +} + +/** + * sml_data_sync_map_item_get_remote_uri: + * @self: A #SmlDataSyncMapItem + * + * Gets the remote property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_data_sync_map_item_get_remote_uri (SmlDataSyncMapItem *self) +{ + g_return_val_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), NULL); + if (!self->priv->remote) + return NULL; + return sml_location_get_uri(self->priv->remote); +} + +/** + * sml_data_sync_map_item_set_remote: + * @self: A #SmlDataSyncMapItem + * @remote: + * + * Sets the remote property. + */ +gboolean +sml_data_sync_map_item_set_remote (SmlDataSyncMapItem *self, + SmlLocation* remote, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDataSyncMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + if (self->priv->remote) + g_object_unref (self->priv->remote); + self->priv->remote = remote; + g_object_ref (remote); + return TRUE; +} + +/** + * sml_data_sync_map_item_get_local_uri: + * @self: A #SmlDataSyncMapItem + * + * Gets the local property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_data_sync_map_item_get_local_uri (SmlDataSyncMapItem *self) +{ + g_return_val_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), NULL); + if (!self->priv->local) + return NULL; + return sml_location_get_uri(self->priv->local); +} + +/** + * sml_data_sync_map_item_set_local: + * @self: A #SmlDataSyncMapItem + * @local: + * + * Sets the local property. + */ +gboolean +sml_data_sync_map_item_set_local (SmlDataSyncMapItem *self, + SmlLocation* local, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDataSyncMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + if (self->priv->local) + g_object_unref (self->priv->local); + self->priv->local = local; + g_object_ref (local); + return TRUE; +} + +/** + * sml_data_sync_map_item_is_compliant: + * @self: A #SmlDataSyncMapItem + * + * Checks the compliance with the OMA specifications for mappings. + */ +gboolean +sml_data_sync_map_item_is_compliant (SmlDataSyncMapItem *self, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDataSyncMapItem object."); + + SmlLocation *remote = self->priv->remote; + sml_return_val_error_if_fail (remote, FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + SmlLocation *local = self->priv->local; + sml_return_val_error_if_fail (local, FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + return TRUE; +} Added: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h Fri Jul 31 13:32:17 2009 (r1223) @@ -0,0 +1,64 @@ +/* sml_data_sync_map_item.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_DATA_SYNC_MAP_ITEM_H__ +#define __SML_DATA_SYNC_MAP_ITEM_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_location.h> + +G_BEGIN_DECLS + +#define SML_TYPE_DATA_SYNC_MAP_ITEM (sml_data_sync_map_item_get_type()) +#define SML_DATA_SYNC_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_DATA_SYNC_MAP_ITEM, SmlDataSyncMapItem)) +#define SML_DATA_SYNC_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_DATA_SYNC_MAP_ITEM, SmlDataSyncMapItemClass)) +#define SML_IS_DATA_SYNC_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_DATA_SYNC_MAP_ITEM)) +#define SML_IS_DATA_SYNC_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_DATA_SYNC_MAP_ITEM)) +#define SML_DATA_SYNC_MAP_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_DATA_SYNC_MAP_ITEM, SmlDataSyncMapItemClass)) + +typedef struct _SmlDataSyncMapItem SmlDataSyncMapItem; +typedef struct _SmlDataSyncMapItemClass SmlDataSyncMapItemClass; +typedef struct _SmlDataSyncMapItemPrivate SmlDataSyncMapItemPrivate; + +struct _SmlDataSyncMapItem +{ + GObject parent; + + /*< private >*/ + SmlDataSyncMapItemPrivate *priv; +}; + +struct _SmlDataSyncMapItemClass +{ + GObjectClass parent_class; + +}; + +GType sml_data_sync_map_item_get_type (void); +SmlDataSyncMapItem* sml_data_sync_map_item_new (void); +G_CONST_RETURN gchar* sml_data_sync_map_item_get_local_uri (SmlDataSyncMapItem *self); +gboolean sml_data_sync_map_item_set_local (SmlDataSyncMapItem *self, SmlLocation* local, GError **error); +G_CONST_RETURN gchar* sml_data_sync_map_item_get_remote_uri (SmlDataSyncMapItem *self); +gboolean sml_data_sync_map_item_set_remote (SmlDataSyncMapItem *self, SmlLocation* remote, GError **error); +gboolean sml_data_sync_map_item_is_compliant (SmlDataSyncMapItem *self, GError **error); + +G_END_DECLS + +#endif /* __SML_DATA_SYNC_MAP_ITEM_H__ */ Modified: trunk/tests/CMakeLists.txt ============================================================================== --- trunk/tests/CMakeLists.txt Mon Jul 20 13:10:53 2009 (r1222) +++ trunk/tests/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) @@ -86,6 +86,29 @@ SML_ADD_TESTCASE( location_compare_different_full_uri_wrong_parent ) SML_ADD_TESTCASE( location_compare_different_full_uri_wrong_uri ) SML_ADD_TESTCASE( location_compare_equal_full_uri_root ) + SML_ADD_TESTCASE( location_references ) + SML_END_TEST() + + SML_START_TEST( "data_sync_map_item" data_sync_api_map_item check_data_sync_api_map_item.c ${TEST_TARGET_LIBRARIES} ) + SML_ADD_TESTCASE( data_sync_map_item_new ) + SML_ADD_TESTCASE( data_sync_map_item_set_local ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_not_null ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_no_name ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_no_parent ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_missing_uri ) + SML_ADD_TESTCASE( data_sync_map_item_get_local ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_not_null ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_name ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_parent ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_missing_uri ) + SML_ADD_TESTCASE( data_sync_map_item_get_remote ) + SML_ADD_TESTCASE( data_sync_map_item_compliance ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_local ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_remote ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_local ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_remote ) + SML_ADD_TESTCASE( data_sync_map_item_references ) SML_END_TEST() SML_START_TEST( "XML fix broken Item Data" xml-fix-broken-item-data check_xml_fix_broken_item_data.c ${TEST_TARGET_LIBRARIES} ) Modified: trunk/tests/check_data_sync_api_location.c ============================================================================== --- trunk/tests/check_data_sync_api_location.c Mon Jul 20 13:10:53 2009 (r1222) +++ trunk/tests/check_data_sync_api_location.c Fri Jul 31 13:32:17 2009 (r1223) @@ -1,6 +1,7 @@ /* * libsyncml - A syncml protocol implementation * Copyright (C) 2005 Armin Bauer <arm...@op...> + * Copyright (C) 2009 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,7 +20,8 @@ */ #include "tests/support.h" -#include <fnmatch.h> + +#include <libsyncml/data_sync_api/sml_location.h> START_TEST (location_new) { @@ -445,5 +447,27 @@ } END_TEST +START_TEST (location_references) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *loc = sml_location_new(); + sml_fail_unless(loc != NULL, NULL); + + sml_fail_unless(sml_location_set_uri(loc, "test", &error), "%s", error?error->message:"No GError set."); + + g_object_ref(loc); + + sml_fail_unless(sml_location_get_uri(loc) != NULL, "The location URI was not set."); + + g_object_unref(loc); + + sml_fail_unless(sml_location_get_uri(loc) != NULL, "The location URI is already cleaned up."); + + g_object_unref(loc); +} +END_TEST + @SML_TESTCASE_CODE@ Added: trunk/tests/check_data_sync_api_map_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tests/check_data_sync_api_map_item.c Fri Jul 31 13:32:17 2009 (r1223) @@ -0,0 +1,487 @@ +/* + * libsyncml - A syncml protocol implementation + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "tests/support.h" + +#include <libsyncml/data_sync_api/sml_data_sync_map_item.h> + +START_TEST (data_sync_map_item_new) +{ + setup_testbed(NULL); + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_not_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, NULL, &error), "The local URI must be enforced."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_no_name) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a name."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_no_parent) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_parent_uri(location, "56", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a parent URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_missing_uri) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must have an URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_get_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) == NULL, "The local URI is not set until now."); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI must be set now."); + sml_fail_unless(strcmp(sml_data_sync_map_item_get_local_uri(item), "1234") == 0, "The local URI must be 1234."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_not_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, NULL, &error), "The remote URI must be enforced."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_no_name) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The location must not have a name."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_no_parent) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_parent_uri(location, "56", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The location must not have a parent URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_missing_uri) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The location must have an URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_get_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_remote_uri(item) == NULL, "The remote URI is not set until now."); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_remote_uri(item) != NULL, "The remote URI must be set now."); + sml_fail_unless(strcmp(sml_data_sync_map_item_get_remote_uri(item), "1234") == 0, "The remote URI must be 1234."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, NULL), "The item is compliant."); + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_missing_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_missing_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_wrong_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *local = sml_location_new(); + sml_fail_unless(local != NULL, NULL); + sml_fail_unless(sml_location_set_uri(local, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + SmlLocation *remote = sml_location_new(); + sml_fail_unless(remote != NULL, NULL); + sml_fail_unless(sml_location_set_uri(remote, "5678", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, remote, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_data_sync_map_item_set_local(item, local, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, NULL), "The item is compliant."); + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* add name */ + sml_fail_unless(sml_location_set_name(local, "my 1234", &error), "%s", error?error->message:"No GError set."); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(local); + g_object_unref(remote); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_wrong_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *local = sml_location_new(); + sml_fail_unless(local != NULL, NULL); + sml_fail_unless(sml_location_set_uri(local, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + SmlLocation *remote = sml_location_new(); + sml_fail_unless(remote != NULL, NULL); + sml_fail_unless(sml_location_set_uri(remote, "5678", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, remote, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_data_sync_map_item_set_local(item, local, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, NULL), "The item is compliant."); + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* add parent */ + sml_fail_unless(sml_location_set_parent_uri(remote, "56", &error), "%s", error?error->message:"No GError set."); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(local); + g_object_unref(remote); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_references) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_ref(item); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI was not set."); + + g_object_unref(item); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI is already cleaned up."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +@SML_TESTCASE_CODE@ + |