[geocode-glib] lib: Turn GeocodeLocation into a proper GObject
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] lib: Turn GeocodeLocation into a proper GObject
- Date: Wed, 3 Apr 2013 19:19:17 +0000 (UTC)
commit 5372f2f7ff97707dcc839bd3ed79ea9f289f7409
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Sun Mar 24 23:48:14 2013 +0200
lib: Turn GeocodeLocation into a proper GObject
While I made this change under the wrong impression that gjs is not very
happy about GeocodeLocation not being a gobject, this IMO is still a
good change and I put some time into it so I'm sending this patch.
I also took the liberty of changing all tabs to spaces in
geocode-location.[ch]. Looking at geocode-ipclient.c, this seem to be
the desired coding-style.
https://bugzilla.gnome.org/show_bug.cgi?id=696528
geocode-glib/geocode-forward.c | 2 +-
geocode-glib/geocode-glib.symbols | 6 +-
geocode-glib/geocode-location.c | 382 +++++++++++++++++++++++++++++-------
geocode-glib/geocode-location.h | 58 ++++--
geocode-glib/geocode-reverse.c | 7 +-
geocode-glib/test-gcglib.c | 51 +++---
geocode-glib/test-geoip.c | 23 ++-
7 files changed, 394 insertions(+), 135 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index 2ef7800..da1461a 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -651,7 +651,7 @@ make_location_list_from_tree (GNode *node,
* and set it to the description of the loc object */
loc = (GeocodeLocation *) node->data;
- name = loc->description;
+ name = geocode_location_get_description (loc);
/* To print the attributes in a meaningful manner
* reverse the s_array */
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index 901faba..64bbadb 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -1,8 +1,12 @@
geocode_location_get_type
geocode_location_new
geocode_location_new_with_description
-geocode_location_free
+geocode_location_get_accuracy
+geocode_location_get_description
geocode_location_get_distance_from
+geocode_location_get_latitude
+geocode_location_get_longitude
+geocode_location_get_timestamp
geocode_location_set_description
geocode_forward_get_type
geocode_forward_new_for_string
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c
index d2bc61c..082fcf4 100644
--- a/geocode-glib/geocode-location.c
+++ b/geocode-glib/geocode-location.c
@@ -30,38 +30,247 @@
* @short_description: Geocode location object
* @include: geocode-glib/geocode-glib.h
*
- * An object representing a location, with optional description.
+ * The #GeocodeLocation instance represents a location on earth, with an
+ * optional description.
**/
-static gpointer
-geocode_location_copy (gpointer boxed)
+
+struct _GeocodeLocationPrivate {
+ gdouble longitude;
+ gdouble latitude;
+ gdouble accuracy;
+ guint64 timestamp;
+ char *description;
+};
+
+enum {
+ PROP_0,
+
+ PROP_LATITUDE,
+ PROP_LONGITUDE,
+ PROP_ACCURACY,
+ PROP_DESCRIPTION,
+ PROP_TIMESTAMP
+};
+
+G_DEFINE_TYPE (GeocodeLocation, geocode_location, G_TYPE_OBJECT)
+
+static void
+geocode_location_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GeocodeLocation *from, *to;
+ GeocodeLocation *location = GEOCODE_LOCATION (object);
- from = (GeocodeLocation *) boxed;
- to = g_new (GeocodeLocation, 1);
- to->longitude = from->longitude;
- to->latitude = from->latitude;
- to->timestamp = from->timestamp;
- to->description = from->description;
- to->accuracy = from->accuracy;
+ switch (property_id) {
+ case PROP_DESCRIPTION:
+ g_value_set_string (value,
+ geocode_location_get_description (location));
+ break;
- return to;
+ case PROP_LATITUDE:
+ g_value_set_double (value,
+ geocode_location_get_latitude (location));
+ break;
+
+ case PROP_LONGITUDE:
+ g_value_set_double (value,
+ geocode_location_get_longitude (location));
+ break;
+
+ case PROP_ACCURACY:
+ g_value_set_double (value,
+ geocode_location_get_accuracy (location));
+ break;
+
+ case PROP_TIMESTAMP:
+ g_value_set_uint64 (value,
+ geocode_location_get_timestamp (location));
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
}
-/**
- * geocode_location_free:
- * @loc: a #GeocodeLocation object
- *
- * Frees a #GeocodeLocation object.
- **/
-void
-geocode_location_free (GeocodeLocation *loc)
+static void
+geocode_location_set_latitude (GeocodeLocation *loc,
+ gdouble latitude)
+{
+ g_return_if_fail (latitude >= -90.0 && latitude <= 90.0);
+
+ loc->priv->latitude = latitude;
+}
+
+static void
+geocode_location_set_longitude (GeocodeLocation *loc,
+ gdouble longitude)
+{
+ g_return_if_fail (longitude >= -180.0 && longitude <= 180.0);
+
+ loc->priv->longitude = longitude;
+}
+
+static void
+geocode_location_set_accuracy (GeocodeLocation *loc,
+ gdouble accuracy)
+{
+ g_return_if_fail (accuracy >= GEOCODE_LOCATION_ACCURACY_UNKNOWN);
+
+ loc->priv->accuracy = accuracy;
+}
+
+static void
+geocode_location_set_property(GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GeocodeLocation *location = GEOCODE_LOCATION (object);
+
+ switch (property_id) {
+ case PROP_DESCRIPTION:
+ geocode_location_set_description (location,
+ g_value_get_string (value));
+ break;
+
+ case PROP_LATITUDE:
+ geocode_location_set_latitude (location,
+ g_value_get_double (value));
+ break;
+
+ case PROP_LONGITUDE:
+ geocode_location_set_longitude (location,
+ g_value_get_double (value));
+ break;
+
+ case PROP_ACCURACY:
+ geocode_location_set_accuracy (location,
+ g_value_get_double (value));
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+geocode_location_finalize (GObject *glocation)
+{
+ GeocodeLocation *location = (GeocodeLocation *) glocation;
+
+ g_clear_pointer (&location->priv->description, g_free);
+
+ G_OBJECT_CLASS (geocode_location_parent_class)->finalize (glocation);
+}
+
+static void
+geocode_location_class_init (GeocodeLocationClass *klass)
{
- g_free (loc->description);
- g_free (loc);
+ GObjectClass *glocation_class = G_OBJECT_CLASS (klass);
+ GParamSpec *pspec;
+
+ glocation_class->finalize = geocode_location_finalize;
+ glocation_class->get_property = geocode_location_get_property;
+ glocation_class->set_property = geocode_location_set_property;
+
+ g_type_class_add_private (klass, sizeof (GeocodeLocationPrivate));
+
+ /**
+ * GeocodeLocation:description:
+ *
+ * The description of this location.
+ */
+ pspec = g_param_spec_string ("description",
+ "Description",
+ "Description of this location",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (glocation_class, PROP_DESCRIPTION, pspec);
+
+ /**
+ * GeocodeLocation:latitude:
+ *
+ * The latitude of this location in degrees.
+ */
+ pspec = g_param_spec_double ("latitude",
+ "Latitude",
+ "The latitude of this location in degrees",
+ -90.0,
+ 90.0,
+ 0.0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (glocation_class, PROP_LATITUDE, pspec);
+
+ /**
+ * GeocodeLocation:longitude:
+ *
+ * The longitude of this location in degrees.
+ */
+ pspec = g_param_spec_double ("longitude",
+ "Longitude",
+ "The longitude of this location in degrees",
+ -180.0,
+ 180.0,
+ 0.0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (glocation_class, PROP_LONGITUDE, pspec);
+
+ /**
+ * GeocodeLocation:accuracy:
+ *
+ * The accuracy of this location in meters.
+ */
+ pspec = g_param_spec_double ("accuracy",
+ "Accuracy",
+ "The accuracy of this location in meters",
+ GEOCODE_LOCATION_ACCURACY_UNKNOWN,
+ G_MAXDOUBLE,
+ GEOCODE_LOCATION_ACCURACY_UNKNOWN,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (glocation_class, PROP_ACCURACY, pspec);
+
+ /**
+ * GeocodeLocation:timestamp:
+ *
+ * A timestamp in seconds since
+ * <ulink url="http://en.wikipedia.org/wiki/Unix_epoch">Epoch</ulink>.
+ */
+ pspec = g_param_spec_uint64 ("timestamp",
+ "Timestamp",
+ "The timestamp of this location "
+ "in seconds since Epoch",
+ 0,
+ G_MAXINT64,
+ 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (glocation_class, PROP_TIMESTAMP, pspec);
}
-G_DEFINE_BOXED_TYPE(GeocodeLocation, geocode_location, geocode_location_copy, geocode_location_free)
+static void
+geocode_location_init (GeocodeLocation *location)
+{
+ GTimeVal tv;
+
+ location->priv = G_TYPE_INSTANCE_GET_PRIVATE ((location),
+ GEOCODE_TYPE_LOCATION,
+ GeocodeLocationPrivate);
+
+ g_get_current_time (&tv);
+ location->priv->timestamp = tv.tv_sec;
+}
/**
* geocode_location_new:
@@ -71,37 +280,18 @@ G_DEFINE_BOXED_TYPE(GeocodeLocation, geocode_location, geocode_location_copy, ge
*
* Creates a new #GeocodeLocation object.
*
- * Returns: a new #GeocodeLocation object. Use geocode_location_free() when done.
+ * Returns: a new #GeocodeLocation object. Use g_object_unref() when done.
**/
GeocodeLocation *
geocode_location_new (gdouble latitude,
gdouble longitude,
gdouble accuracy)
{
- GeocodeLocation *ret;
- GTimeVal tv;
-
- if (longitude < -180.0 || longitude > 180.0) {
- g_warning ("Invalid longitude %lf passed, using 0.0 instead", longitude);
- longitude = 0.0;
- }
- if (latitude < -90.0 || latitude > 90.0) {
- g_warning ("Invalid latitude %lf passed, using 0.0 instead", latitude);
- latitude = 0.0;
- }
- if (accuracy < GEOCODE_LOCATION_ACCURACY_UNKNOWN) {
- g_warning ("Invalid accuracy %lf passed, assuming its unknown", accuracy);
- accuracy = GEOCODE_LOCATION_ACCURACY_UNKNOWN;
- }
-
- ret = g_new0 (GeocodeLocation, 1);
- ret->longitude = longitude;
- ret->latitude = latitude;
- ret->accuracy = accuracy;
- g_get_current_time (&tv);
- ret->timestamp = tv.tv_sec;
-
- return ret;
+ return g_object_new (GEOCODE_TYPE_LOCATION,
+ "latitude", latitude,
+ "longitude", longitude,
+ "accuracy", accuracy,
+ NULL);
}
/**
@@ -113,7 +303,7 @@ geocode_location_new (gdouble latitude,
*
* Creates a new #GeocodeLocation object.
*
- * Returns: a new #GeocodeLocation object. Use geocode_location_free() when done.
+ * Returns: a new #GeocodeLocation object. Use g_object_unref() when done.
**/
GeocodeLocation *
geocode_location_new_with_description (gdouble latitude,
@@ -121,29 +311,70 @@ geocode_location_new_with_description (gdouble latitude,
gdouble accuracy,
const char *description)
{
- GeocodeLocation *ret;
-
- ret = geocode_location_new (latitude, longitude, accuracy);
- ret->description = g_strdup (description);
-
- return ret;
+ return g_object_new (GEOCODE_TYPE_LOCATION,
+ "latitude", latitude,
+ "longitude", longitude,
+ "accuracy", accuracy,
+ "description", description,
+ NULL);
}
/**
* geocode_location_set_description:
* @description: a description for the location
*
- * Sets the #GeocodeLocation object's @description to
- * the passed value.
+ * Sets the description of @loc to @description.
**/
void
geocode_location_set_description (GeocodeLocation *loc,
- const char *description)
+ const char *description)
+{
+ g_return_if_fail (GEOCODE_IS_LOCATION (loc));
+ g_return_if_fail (description != NULL);
+
+ g_free (loc->priv->description);
+ loc->priv->description = g_strdup (description);
+}
+
+const char *
+geocode_location_get_description (GeocodeLocation *loc)
+{
+ g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), NULL);
+
+ return loc->priv->description;
+}
+
+gdouble
+geocode_location_get_latitude (GeocodeLocation *loc)
+{
+ g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), 0.0);
+
+ return loc->priv->latitude;
+}
+
+gdouble
+geocode_location_get_longitude (GeocodeLocation *loc)
+{
+ g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), 0.0);
+
+ return loc->priv->longitude;
+}
+
+gdouble
+geocode_location_get_accuracy (GeocodeLocation *loc)
+{
+ g_return_val_if_fail (GEOCODE_IS_LOCATION (loc),
+ GEOCODE_LOCATION_ACCURACY_UNKNOWN);
+
+ return loc->priv->accuracy;
+}
+
+guint64
+geocode_location_get_timestamp (GeocodeLocation *loc)
{
- g_return_if_fail (loc != NULL);
+ g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), -1);
- g_free (loc->description);
- loc->description = g_strdup (description);
+ return loc->priv->timestamp;
}
/**
@@ -159,23 +390,24 @@ geocode_location_set_description (GeocodeLocation *loc,
**/
double
geocode_location_get_distance_from (GeocodeLocation *loca,
- GeocodeLocation *locb)
+ GeocodeLocation *locb)
{
- gdouble dlat, dlon, lat1, lat2;
- gdouble a, c;
+ gdouble dlat, dlon, lat1, lat2;
+ gdouble a, c;
- g_return_val_if_fail (loca != NULL || locb != NULL, 0.0);
+ g_return_val_if_fail (GEOCODE_IS_LOCATION (loca), 0.0);
+ g_return_val_if_fail (GEOCODE_IS_LOCATION (locb), 0.0);
- /* Algorithm from:
- * http://www.movable-type.co.uk/scripts/latlong.html */
+ /* Algorithm from:
+ * http://www.movable-type.co.uk/scripts/latlong.html */
- dlat = (locb->latitude - loca->latitude) * M_PI / 180.0;
- dlon = (locb->longitude - loca->longitude) * M_PI / 180.0;
- lat1 = loca->latitude * M_PI / 180.0;
- lat2 = locb->latitude * M_PI / 180.0;
+ dlat = (locb->priv->latitude - loca->priv->latitude) * M_PI / 180.0;
+ dlon = (locb->priv->longitude - loca->priv->longitude) * M_PI / 180.0;
+ lat1 = loca->priv->latitude * M_PI / 180.0;
+ lat2 = locb->priv->latitude * M_PI / 180.0;
- a = sin (dlat / 2) * sin (dlat / 2) +
- sin (dlon / 2) * sin (dlon / 2) * cos (lat1) * cos (lat2);
- c = 2 * atan2 (sqrt (a), sqrt (1-a));
- return EARTH_RADIUS_KM * c;
+ a = sin (dlat / 2) * sin (dlat / 2) +
+ sin (dlon / 2) * sin (dlon / 2) * cos (lat1) * cos (lat2);
+ c = 2 * atan2 (sqrt (a), sqrt (1-a));
+ return EARTH_RADIUS_KM * c;
}
diff --git a/geocode-glib/geocode-location.h b/geocode-glib/geocode-location.h
index 51242b4..e59d5fb 100644
--- a/geocode-glib/geocode-location.h
+++ b/geocode-glib/geocode-location.h
@@ -27,25 +27,38 @@
G_BEGIN_DECLS
-typedef struct _GeocodeLocation GeocodeLocation;
+GType geocode_location_get_type (void) G_GNUC_CONST;
+
+#define GEOCODE_TYPE_LOCATION (geocode_location_get_type ())
+#define GEOCODE_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCODE_TYPE_LOCATION,
GeocodeLocation))
+#define GEOCODE_IS_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOCODE_TYPE_LOCATION))
+#define GEOCODE_LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEOCODE_TYPE_LOCATION,
GeocodeLocationClass))
+#define GEOCODE_IS_LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEOCODE_TYPE_LOCATION))
+#define GEOCODE_LOCATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEOCODE_TYPE_LOCATION,
GeocodeLocationClass))
+
+typedef struct _GeocodeLocation GeocodeLocation;
+typedef struct _GeocodeLocationClass GeocodeLocationClass;
+typedef struct _GeocodeLocationPrivate GeocodeLocationPrivate;
/**
* GeocodeLocation:
- * @longitude: a longitude, in degrees
- * @latitude: a latitude, in degrees
- * @accuracy: accuracy of location, in meters
- * @timestamp: a timestamp in seconds since <ulink
url="http://en.wikipedia.org/wiki/Unix_epoch">Epoch</ulink>.
- * @description: a description for display
*
- * The #GeocodeLocation structure represents a location
- * on earth, with an optional description.
- **/
+ * All the fields in the #GeocodeLocation structure are private and should never be accessed directly.
+**/
struct _GeocodeLocation {
- gdouble longitude;
- gdouble latitude;
- gdouble accuracy;
- gint64 timestamp;
- char *description;
+ /* <private> */
+ GObject parent_instance;
+ GeocodeLocationPrivate *priv;
+};
+
+/**
+ * GeocodeLocationClass:
+ *
+ * All the fields in the #GeocodeLocationClass structure are private and should never be accessed directly.
+**/
+struct _GeocodeLocationClass {
+ /* <private> */
+ GObjectClass parent_class;
};
#define GEOCODE_LOCATION_ACCURACY_UNKNOWN -1
@@ -57,8 +70,6 @@ struct _GeocodeLocation {
#define GEOCODE_TYPE_LOCATION (geocode_location_get_type ())
-GType geocode_location_get_type (void) G_GNUC_CONST;
-
GeocodeLocation *geocode_location_new (gdouble latitude,
gdouble longitude,
gdouble accuracy);
@@ -68,13 +79,18 @@ GeocodeLocation *geocode_location_new_with_description (gdouble latitude,
gdouble accuracy,
const char *description);
-double geocode_location_get_distance_from (GeocodeLocation *loca,
- GeocodeLocation *locb);
+double geocode_location_get_distance_from (GeocodeLocation *loca,
+ GeocodeLocation *locb);
+
+void geocode_location_set_description (GeocodeLocation *loc,
+ const char *description);
-void geocode_location_set_description (GeocodeLocation *loc,
- const char *description);
+const char *geocode_location_get_description (GeocodeLocation *loc);
-void geocode_location_free (GeocodeLocation *loc);
+gdouble geocode_location_get_latitude (GeocodeLocation *loc);
+gdouble geocode_location_get_longitude (GeocodeLocation *loc);
+gdouble geocode_location_get_accuracy (GeocodeLocation *loc);
+guint64 geocode_location_get_timestamp (GeocodeLocation *loc);
G_END_DECLS
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 89470db..c587791 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -92,11 +92,12 @@ geocode_reverse_new_for_location (GeocodeLocation *location)
object = g_object_new (GEOCODE_TYPE_REVERSE, NULL);
+ g_ascii_formatd (buf, sizeof (buf), "%g", geocode_location_get_latitude (location));
+ g_ascii_formatd (buf2, sizeof (buf2), "%g", geocode_location_get_longitude (location));
+
g_hash_table_insert (object->priv->ht,
g_strdup ("location"),
- g_strdup_printf ("%s, %s",
- g_ascii_formatd (buf, sizeof (buf), "%g", location->latitude),
- g_ascii_formatd (buf2, sizeof (buf2), "%g",
location->longitude)));
+ g_strdup_printf ("%s, %s", buf, buf2));
return object;
}
diff --git a/geocode-glib/test-gcglib.c b/geocode-glib/test-gcglib.c
index 70a9258..6251ebc 100644
--- a/geocode-glib/test-gcglib.c
+++ b/geocode-glib/test-gcglib.c
@@ -15,7 +15,10 @@ static char **params = NULL;
static void
print_loc (GeocodeLocation *loc)
{
- g_print ("\t%s @ %lf, %lf\n", loc->description, loc->latitude, loc->longitude);
+ g_print ("\t%s @ %lf, %lf\n",
+ geocode_location_get_description (loc),
+ geocode_location_get_latitude (loc),
+ geocode_location_get_longitude (loc));
}
static void
@@ -72,7 +75,7 @@ got_geocode_search_cb (GObject *source_object,
g_print ("Got geocode search answer:\n");
print_loc (loc);
- geocode_location_free (loc);
+ g_object_unref (loc);
}
g_list_free (results);
@@ -91,7 +94,7 @@ test_rev (void)
loc = geocode_location_new (51.237070, -0.589669, GEOCODE_LOCATION_ACCURACY_UNKNOWN);
rev = geocode_reverse_new_for_location (loc);
- geocode_location_free (loc);
+ g_object_unref (loc);
ht = geocode_reverse_resolve (rev, &error);
if (ht == NULL) {
@@ -153,10 +156,10 @@ test_xep (void)
g_object_unref (object);
loc = res->data;
- g_assert_cmpfloat (loc->latitude, ==, -0.589669);
- g_assert_cmpfloat (loc->longitude, ==, 51.237070);
+ g_assert_cmpfloat (geocode_location_get_latitude (loc), ==, -0.589669);
+ g_assert_cmpfloat (geocode_location_get_longitude (loc), ==, 51.237070);
- geocode_location_free (loc);
+ g_object_unref (loc);
g_list_free (res);
}
@@ -182,10 +185,10 @@ test_pub (void)
g_assert_cmpint (g_list_length (res), ==, 1);
loc = res->data;
- g_assert_cmpfloat (loc->latitude, ==, -0.589669);
- g_assert_cmpfloat (loc->longitude, ==, 51.237070);
+ g_assert_cmpfloat (geocode_location_get_latitude (loc), ==, -0.589669);
+ g_assert_cmpfloat (geocode_location_get_longitude (loc), ==, 51.237070);
- geocode_location_free (loc);
+ g_object_unref (loc);
g_list_free (res);
}
@@ -220,12 +223,12 @@ test_search (void)
for (l = results; l != NULL; l = l->next) {
GeocodeLocation *loc = l->data;
- if (g_strcmp0 (loc->description, "Paris, France") == 0)
+ if (g_strcmp0 (geocode_location_get_description (loc), "Paris, France") == 0)
got_france = TRUE;
- else if (g_strcmp0 (loc->description, "Paris, Texas, United States") == 0)
+ else if (g_strcmp0 (geocode_location_get_description (loc), "Paris, Texas, United States") ==
0)
got_texas = TRUE;
- geocode_location_free (loc);
+ g_object_unref (loc);
if (got_france && got_texas)
break;
@@ -257,10 +260,10 @@ test_search_lat_long (void)
g_object_unref (object);
loc = res->data;
- g_assert_cmpfloat (loc->latitude - 21.800699, <, 0.000001);
- g_assert_cmpfloat (loc->longitude - -100.735626, <, 0.000001);
+ g_assert_cmpfloat (geocode_location_get_latitude (loc) - 21.800699, <, 0.000001);
+ g_assert_cmpfloat (geocode_location_get_longitude (loc) - -100.735626, <, 0.000001);
- g_list_free_full (res, (GDestroyNotify) geocode_location_free);
+ g_list_free_full (res, (GDestroyNotify) g_object_unref);
}
/* Test case from:
@@ -301,12 +304,12 @@ test_locale (void)
g_object_unref (object);
loc = res->data;
- g_assert_cmpstr (loc->description, ==, "Moskva, Rusko");
- g_assert_cmpfloat (loc->latitude - 55.756950, <, 0.000001);
- g_assert_cmpfloat (loc->longitude - 37.614971, <, 0.000001);
+ g_assert_cmpstr (geocode_location_get_description (loc), ==, "Moskva, Rusko");
+ g_assert_cmpfloat (geocode_location_get_latitude (loc) - 55.756950, <, 0.000001);
+ g_assert_cmpfloat (geocode_location_get_longitude (loc) - 37.614971, <, 0.000001);
print_loc (loc);
- g_list_free_full (res, (GDestroyNotify) geocode_location_free);
+ g_list_free_full (res, (GDestroyNotify) g_object_unref);
/* Check Bonneville's region in French */
setlocale (LC_MESSAGES, "fr_FR.UTF-8");
@@ -320,10 +323,10 @@ test_locale (void)
g_object_unref (object);
loc = res->data;
- g_assert_cmpstr (loc->description, ==, "Bonneville, Rhône-Alpes, France");
+ g_assert_cmpstr (geocode_location_get_description (loc), ==, "Bonneville, Rhône-Alpes, France");
print_loc (loc);
- g_list_free_full (res, (GDestroyNotify) geocode_location_free);
+ g_list_free_full (res, (GDestroyNotify) g_object_unref);
/* And reset the locale */
setlocale (LC_MESSAGES, old_locale);
@@ -398,9 +401,9 @@ test_search_json (void)
g_assert_cmpint (g_list_length (list), ==, 10);
loc = list->data;
- g_assert_cmpstr (loc->description, ==, "Rio de Janeiro, Brazil");
+ g_assert_cmpstr (geocode_location_get_description (loc), ==, "Rio de Janeiro, Brazil");
- g_list_free_full (list, (GDestroyNotify) geocode_location_free);
+ g_list_free_full (list, (GDestroyNotify) g_object_unref);
}
static GeocodeLocation *
@@ -477,7 +480,7 @@ int main (int argc, char **argv)
}
print_loc (loc);
reverse = geocode_reverse_new_for_location (loc);
- geocode_location_free (loc);
+ g_object_unref (loc);
geocode_reverse_resolve_async (reverse, NULL, got_geocode_cb, NULL);
}
diff --git a/geocode-glib/test-geoip.c b/geocode-glib/test-geoip.c
index 008fcd0..a2a68f5 100644
--- a/geocode-glib/test-geoip.c
+++ b/geocode-glib/test-geoip.c
@@ -43,7 +43,7 @@ test_parse_json (gconstpointer data)
}
g_free (contents);
g_free (path);
- geocode_location_free (location);
+ g_object_unref (location);
}
@@ -54,7 +54,6 @@ test_search (gconstpointer data)
GError *error = NULL;
GeocodeLocation *location;
TestData *test_data = (TestData *) data;
- gdouble accuracy = GEOCODE_LOCATION_ACCURACY_UNKNOWN;
if (test_data->ip)
ipclient = geocode_ipclient_new_for_ip (test_data->ip);
@@ -67,12 +66,13 @@ test_search (gconstpointer data)
g_error_free (error);
}
g_assert (location != NULL);
- g_assert (location->latitude == test_data->expected_latitude);
- g_assert (location->longitude == test_data->expected_longitude);
- g_assert (location->description != NULL &&
- strcmp(location->description, test_data->expected_description) == 0);
- g_assert (accuracy != GEOCODE_LOCATION_ACCURACY_UNKNOWN);
- geocode_location_free (location);
+ g_assert (geocode_location_get_latitude (location) == test_data->expected_latitude);
+ g_assert (geocode_location_get_longitude (location) == test_data->expected_longitude);
+ g_assert (geocode_location_get_description (location) != NULL);
+ g_assert (strcmp (geocode_location_get_description (location),
+ test_data->expected_description) == 0);
+ g_assert (geocode_location_get_accuracy (location) != GEOCODE_LOCATION_ACCURACY_UNKNOWN);
+ g_object_unref (location);
g_object_unref (ipclient);
}
@@ -91,9 +91,12 @@ print_geolocation_info_cb (GObject *source_object,
g_error_free (error);
exit (1);
}
- g_print ("Location: %s (%f,%f)\n", location->description, location->latitude, location->longitude);
+ g_print ("Location: %s (%f,%f)\n",
+ geocode_location_get_description (location),
+ geocode_location_get_latitude (location),
+ geocode_location_get_longitude (location));
- geocode_location_free (location);
+ g_object_unref (location);
g_object_unref (object);
exit (0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]