[libgdata] gd: Fix parsing and output of country codes in GDataGDPostalAddress
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] gd: Fix parsing and output of country codes in GDataGDPostalAddress
- Date: Thu, 30 Sep 2010 18:44:52 +0000 (UTC)
commit fc13dc995e8afc12e154f384554cbf613da76e48
Author: Philip Withnall <philip tecnocode co uk>
Date: Thu Sep 30 19:44:31 2010 +0100
gd: Fix parsing and output of country codes in GDataGDPostalAddress
gdata/gd/gdata-gd-postal-address.c | 46 +++++++++++++++++++++++------------
gdata/tests/general.c | 7 ++++-
2 files changed, 36 insertions(+), 17 deletions(-)
---
diff --git a/gdata/gd/gdata-gd-postal-address.c b/gdata/gd/gdata-gd-postal-address.c
index d8f22f5..3868976 100644
--- a/gdata/gd/gdata-gd-postal-address.c
+++ b/gdata/gd/gdata-gd-postal-address.c
@@ -594,22 +594,28 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
gboolean success;
GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (parsable)->priv;
- if (gdata_parser_is_namespace (node, "http://schemas.google.com/g/2005") == TRUE && (
- gdata_parser_string_from_element (node, "agent", P_NO_DUPES, &(priv->agent), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "housename", P_NO_DUPES, &(priv->house_name), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "pobox", P_NO_DUPES, &(priv->po_box), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "street", P_NO_DUPES, &(priv->street), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "neighborhood", P_NO_DUPES, &(priv->neighborhood), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "city", P_NO_DUPES, &(priv->city), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "subregion", P_NO_DUPES, &(priv->subregion), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "region", P_NO_DUPES, &(priv->region), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "postcode", P_NO_DUPES, &(priv->postcode), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "country", P_NO_DUPES, &(priv->country), &success, error) == TRUE ||
- gdata_parser_string_from_element (node, "formattedAddress", P_NO_DUPES, &(priv->formatted_address), &success, error) == TRUE)) {
- return success;
- } else {
- return GDATA_PARSABLE_CLASS (gdata_gd_postal_address_parent_class)->parse_xml (parsable, doc, node, user_data, error);
+ if (gdata_parser_is_namespace (node, "http://schemas.google.com/g/2005") == TRUE) {
+ if (gdata_parser_string_from_element (node, "agent", P_NO_DUPES, &(priv->agent), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "housename", P_NO_DUPES, &(priv->house_name), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "pobox", P_NO_DUPES, &(priv->po_box), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "street", P_NO_DUPES, &(priv->street), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "neighborhood", P_NO_DUPES, &(priv->neighborhood), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "city", P_NO_DUPES, &(priv->city), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "subregion", P_NO_DUPES, &(priv->subregion), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "region", P_NO_DUPES, &(priv->region), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "postcode", P_NO_DUPES, &(priv->postcode), &success, error) == TRUE ||
+ gdata_parser_string_from_element (node, "formattedAddress", P_NO_DUPES, &(priv->formatted_address), &success, error) == TRUE) {
+ return success;
+ } else if (xmlStrcmp (node->name, (xmlChar*) "country") == 0) {
+ /* gd:country */
+ priv->country_code = (gchar*) xmlGetProp (node, (xmlChar*) "code");
+ priv->country = (gchar*) xmlNodeListGetString (doc, node->children, TRUE);
+
+ return TRUE;
+ }
}
+
+ return GDATA_PARSABLE_CLASS (gdata_gd_postal_address_parent_class)->parse_xml (parsable, doc, node, user_data, error);
}
static void
@@ -650,7 +656,15 @@ get_xml (GDataParsable *parsable, GString *xml_string)
OUTPUT_STRING_ELEMENT ("subregion", subregion)
OUTPUT_STRING_ELEMENT ("region", region)
OUTPUT_STRING_ELEMENT ("postcode", postcode)
- OUTPUT_STRING_ELEMENT ("country", country)
+
+ if (priv->country != NULL) {
+ if (priv->country_code != NULL)
+ gdata_parser_string_append_escaped (xml_string, "<gd:country code='", priv->country_code, "'>");
+ else
+ g_string_append (xml_string, "<gd:country>");
+ gdata_parser_string_append_escaped (xml_string, NULL, priv->country, "</gd:country>");
+ }
+
OUTPUT_STRING_ELEMENT ("formattedAddress", formatted_address)
#undef OUTPUT_STRING_ELEMENT
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 1754be2..a478ba8 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -1882,6 +1882,7 @@ test_gd_postal_address (void)
"<gd:street>500 West 45th Street</gd:street>"
"<gd:city>New York</gd:city>"
"<gd:postcode>NY 10036</gd:postcode>"
+ "<gd:country code='US'>United States</gd:country>"
"</gd:structuredPostalAddress>", -1, &error));
g_assert_no_error (error);
g_assert (GDATA_IS_GD_POSTAL_ADDRESS (postal));
@@ -1893,6 +1894,8 @@ test_gd_postal_address (void)
g_assert_cmpstr (gdata_gd_postal_address_get_postcode (postal), ==, "NY 10036");
g_assert_cmpstr (gdata_gd_postal_address_get_relation_type (postal), ==, GDATA_GD_POSTAL_ADDRESS_HOME);
g_assert_cmpstr (gdata_gd_postal_address_get_label (postal), ==, "Home & Safe House");
+ g_assert_cmpstr (gdata_gd_postal_address_get_country (postal), ==, "United States");
+ g_assert_cmpstr (gdata_gd_postal_address_get_country_code (postal), ==, "US");
g_assert (gdata_gd_postal_address_is_primary (postal) == TRUE);
/* Compare it against another identical address */
@@ -1900,6 +1903,7 @@ test_gd_postal_address (void)
gdata_gd_postal_address_set_street (postal2, "500 West 45th Street");
gdata_gd_postal_address_set_city (postal2, "New York");
gdata_gd_postal_address_set_postcode (postal2, "NY 10036");
+ gdata_gd_postal_address_set_country (postal2, "United States", "US");
g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (postal), GDATA_COMPARABLE (postal2)), ==, 0);
/* â?¦and a different one */
@@ -1916,6 +1920,7 @@ test_gd_postal_address (void)
"<gd:street>500 West 45th Street</gd:street>"
"<gd:city>New York</gd:city>"
"<gd:postcode>NY 10036</gd:postcode>"
+ "<gd:country code='US'>United States</gd:country>"
"</gd:structuredPostalAddress>");
g_free (xml);
@@ -1986,7 +1991,7 @@ test_gd_postal_address_escaping (void)
"<gd:subregion>Subregion <5></gd:subregion>"
"<gd:region><region></gd:region>"
"<gd:postcode>Postcode & stuff</gd:postcode>"
- "<gd:country><foo></gd:country>"
+ "<gd:country code='<bar>'><foo></gd:country>"
"<gd:formattedAddress><address></gd:formattedAddress>"
"</gd:structuredPostalAddress>");
g_free (xml);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]