/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ /* * GData Client * Copyright (C) Philip Withnall 2008–2010 * * GData Client 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. * * GData Client 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 GData Client. If not, see . */ #include #include #include "gdata.h" #include "common.h" static void test_xml_comparison (void) { GDataAccessRule *rule; /* Since we've written the XML comparison function used across all the test suites, it's necessary to test that it actually works before we * blindly assert that its results are correct. */ rule = gdata_access_rule_new ("an-id"); gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE); gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "foo@example.com"); /* Check a valid comparison */ gdata_test_assert_xml (rule, "" "" "none" "an-id" "" "" "" ""); /* Check a valid comparison with namespaces swapped */ gdata_test_assert_xml (rule, "" "" "none" "an-id" "" "" "" ""); /* Check a valid comparison with elements swapped */ gdata_test_assert_xml (rule, "" "" "an-id" "none" "" "" "" ""); /* Missing namespace (still valid XML, just not what's expected) */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "an-id" "" "" "" "", FALSE) == FALSE); /* Extra namespace */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "an-id" "" "" "" "", FALSE) == FALSE); /* Missing element */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "an-id" "" "" "" "", FALSE) == FALSE); /* Extra element */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "bar" "an-id" "" "" "" "", FALSE) == FALSE); /* Incorrect namespace on element */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "an-id" "" "" "" "", FALSE) == FALSE); /* Mis-valued content */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "an-other-id" "" "" "" "", FALSE) == FALSE); /* Missing attribute */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "an-id" "" "" "" "", FALSE) == FALSE); /* Extra attribute */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "an-id" "" "" "" "", FALSE) == FALSE); /* Mis-valued attribute */ g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule), "" "" "none" "an-id" "" "" "" "", FALSE) == FALSE); g_object_unref (rule); } static void test_entry_get_xml (void) { gint64 updated, published, updated2, published2, updated3, published3; GDataEntry *entry, *entry2; GDataCategory *category; GDataLink *_link; /* stupid unistd.h */ GDataAuthor *author; gchar *xml, *title, *summary, *id, *etag, *content, *content_uri, *rights; gboolean is_inserted; GList *list; GError *error = NULL; entry = gdata_entry_new (NULL); /* Test setting properties directly */ g_object_set (G_OBJECT (entry), "title", "First testing title & escaping", "summary", "Test summary & escaping.", "content", "Test & escaping.", "rights", "Philip Withnall ", NULL); g_assert_cmpstr (gdata_entry_get_title (entry), ==, "First testing title & escaping"); g_assert_cmpstr (gdata_entry_get_summary (entry), ==, "Test summary & escaping."); g_assert_cmpstr (gdata_entry_get_content (entry), ==, "Test & escaping."); g_assert (gdata_entry_get_content_uri (entry) == NULL); g_assert_cmpstr (gdata_entry_get_rights (entry), ==, "Philip Withnall "); /* Set the properties more conventionally */ gdata_entry_set_title (entry, "Testing title & escaping"); gdata_entry_set_summary (entry, NULL); gdata_entry_set_content (entry, "This is some sample content testing, amongst other things, & odd characters‽"); gdata_entry_set_rights (entry, NULL); /* Content URI */ g_object_set (G_OBJECT (entry), "content-uri", "http://foo.com/", NULL); g_assert (gdata_entry_get_content (entry) == NULL); g_assert_cmpstr (gdata_entry_get_content_uri (entry), ==, "http://foo.com/"); gdata_entry_set_content_uri (entry, "http://bar.com/"); /* Check the generated XML's OK */ gdata_test_assert_xml (entry, "" "" "Testing title & escaping" "" ""); /* Reset the content */ gdata_entry_set_content (entry, "This is some sample content testing, amongst other things, & odd characters‽"); /* Categories */ category = gdata_category_new ("test", NULL, NULL); gdata_entry_add_category (entry, category); g_object_unref (category); category = gdata_category_new ("example", NULL, "Example stuff"); gdata_entry_add_category (entry, category); g_object_unref (category); category = gdata_category_new ("Film", "http://gdata.youtube.com/schemas/2007/categories.cat", "Film & Animation"); gdata_entry_add_category (entry, category); g_object_unref (category); /* Links */ _link = gdata_link_new ("http://test.com/", GDATA_LINK_SELF); gdata_link_set_content_type (_link, "application/atom+xml"); gdata_entry_add_link (entry, _link); g_object_unref (_link); _link = gdata_link_new ("http://example.com/", NULL); gdata_entry_add_link (entry, _link); g_object_unref (_link); _link = gdata_link_new ("http://test.mn/", GDATA_LINK_RELATED); gdata_link_set_content_type (_link, "text/html"); gdata_link_set_language (_link, "mn"); gdata_link_set_title (_link, "A treatise on Mongolian test websites & other stuff."); gdata_link_set_length (_link, 5010); gdata_entry_add_link (entry, _link); g_object_unref (_link); _link = gdata_link_new ("http://example.com/", "http://foobar.link"); gdata_entry_add_link (entry, _link); g_object_unref (_link); _link = gdata_link_new ("http://example2.com/", "http://foobar.link"); gdata_entry_add_link (entry, _link); g_object_unref (_link); /* Authors */ author = gdata_author_new ("Joe Bloggs", "http://example.com/", "joe@example.com"); gdata_entry_add_author (entry, author); g_object_unref (author); author = gdata_author_new ("John Smith", NULL, "smith.john@example.com"); gdata_entry_add_author (entry, author); g_object_unref (author); author = gdata_author_new ("F. Barr؟", NULL, NULL); gdata_entry_add_author (entry, author); g_object_unref (author); /* Check the generated XML's OK */ gdata_test_assert_xml (entry, "" "" "Testing title & escaping" "This is some sample content testing, amongst other things, <markup> & odd characters\342\200\275" "" "" "" "" "" "" "" "" "F. Barr\330\237" "John Smithsmith.john@example.com" "Joe Bloggshttp://example.com/joe@example.com" ""); /* Check again by re-parsing the XML to a GDataEntry */ xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry)); entry2 = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, xml, -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry2)); g_clear_error (&error); g_free (xml); g_assert_cmpstr (gdata_entry_get_title (entry), ==, gdata_entry_get_title (entry2)); g_assert_cmpstr (gdata_entry_get_id (entry), ==, gdata_entry_get_id (entry2)); /* should both be NULL */ g_assert_cmpstr (gdata_entry_get_content (entry), ==, gdata_entry_get_content (entry2)); g_assert_cmpstr (gdata_entry_get_content_uri (entry), ==, gdata_entry_get_content_uri (entry2)); /* should both be NULL */ updated = gdata_entry_get_updated (entry); updated2 = gdata_entry_get_updated (entry2); g_assert_cmpuint (updated, ==, updated2); published = gdata_entry_get_published (entry); published2 = gdata_entry_get_published (entry2); g_assert_cmpuint (published, ==, published2); /* Check links */ _link = gdata_entry_look_up_link (entry, GDATA_LINK_SELF); g_assert (_link != NULL); g_assert_cmpstr (gdata_link_get_uri (_link), ==, "http://test.com/"); g_assert_cmpstr (gdata_link_get_relation_type (_link), ==, GDATA_LINK_SELF); g_assert_cmpstr (gdata_link_get_content_type (_link), ==, "application/atom+xml"); _link = gdata_entry_look_up_link (entry, "http://link.not.exist"); g_assert (_link == NULL); list = gdata_entry_look_up_links (entry, "http://foobar.link"); g_assert (list != NULL); g_assert_cmpint (g_list_length (list), ==, 2); _link = GDATA_LINK (list->data); g_assert (_link != NULL); g_assert_cmpstr (gdata_link_get_uri (_link), ==, "http://example2.com/"); g_assert_cmpstr (gdata_link_get_relation_type (_link), ==, "http://foobar.link"); _link = GDATA_LINK (list->next->data); g_assert (_link != NULL); g_assert_cmpstr (gdata_link_get_uri (_link), ==, "http://example.com/"); g_assert_cmpstr (gdata_link_get_relation_type (_link), ==, "http://foobar.link"); g_list_free (list); /* Check authors */ list = gdata_entry_get_authors (entry); g_assert_cmpuint (g_list_length (list), ==, 3); author = GDATA_AUTHOR (list->data); g_assert (author != NULL); g_assert_cmpstr (gdata_author_get_name (author), ==, "F. Barr؟"); g_assert (gdata_author_get_uri (author) == NULL); g_assert (gdata_author_get_email_address (author) == NULL); author = GDATA_AUTHOR (list->next->data); g_assert (author != NULL); g_assert_cmpstr (gdata_author_get_name (author), ==, "John Smith"); g_assert (gdata_author_get_uri (author) == NULL); g_assert_cmpstr (gdata_author_get_email_address (author), ==, "smith.john@example.com"); author = GDATA_AUTHOR (list->next->next->data); g_assert (author != NULL); g_assert_cmpstr (gdata_author_get_name (author), ==, "Joe Bloggs"); g_assert_cmpstr (gdata_author_get_uri (author), ==, "http://example.com/"); g_assert_cmpstr (gdata_author_get_email_address (author), ==, "joe@example.com"); /* Check categories */ list = gdata_entry_get_categories (entry); g_assert (list != NULL); g_assert_cmpint (g_list_length (list), ==, 3); category = GDATA_CATEGORY (list->data); g_assert (category != NULL); g_assert_cmpstr (gdata_category_get_term (category), ==, "Film"); g_assert_cmpstr (gdata_category_get_scheme (category), ==, "http://gdata.youtube.com/schemas/2007/categories.cat"); g_assert_cmpstr (gdata_category_get_label (category), ==, "Film & Animation"); category = GDATA_CATEGORY (list->next->data); g_assert (category != NULL); g_assert_cmpstr (gdata_category_get_term (category), ==, "example"); g_assert (gdata_category_get_scheme (category) == NULL); g_assert_cmpstr (gdata_category_get_label (category), ==, "Example stuff"); category = GDATA_CATEGORY (list->next->next->data); g_assert (category != NULL); g_assert_cmpstr (gdata_category_get_term (category), ==, "test"); g_assert (gdata_category_get_scheme (category) == NULL); g_assert (gdata_category_get_label (category) == NULL); /* TODO: Check authors */ /* Check properties a different way */ g_object_get (G_OBJECT (entry2), "title", &title, "summary", &summary, "id", &id, "etag", &etag, "updated", &updated3, "published", &published3, "content", &content, "content-uri", &content_uri, "is-inserted", &is_inserted, "rights", &rights, NULL); g_assert_cmpstr (title, ==, gdata_entry_get_title (entry)); g_assert_cmpstr (summary, ==, gdata_entry_get_summary (entry)); g_assert_cmpstr (id, ==, gdata_entry_get_id (entry)); g_assert_cmpstr (etag, ==, gdata_entry_get_etag (entry)); g_assert_cmpint (updated3, ==, updated); g_assert_cmpint (published3, ==, published); g_assert_cmpstr (content, ==, gdata_entry_get_content (entry)); g_assert_cmpstr (content_uri, ==, gdata_entry_get_content_uri (entry)); g_assert (is_inserted == FALSE); g_assert_cmpstr (rights, ==, gdata_entry_get_rights (entry)); g_free (title); g_free (summary); g_free (id); g_free (etag); g_free (content); g_free (content_uri); g_free (rights); /* Set the content URI and check that */ gdata_entry_set_content_uri (entry, "http://baz.net/"); g_object_get (G_OBJECT (entry), "content", &content, "content-uri", &content_uri, NULL); g_assert_cmpstr (content, ==, gdata_entry_get_content (entry)); g_assert_cmpstr (content_uri, ==, gdata_entry_get_content_uri (entry)); g_free (content); g_free (content_uri); g_object_unref (entry); g_object_unref (entry2); } static void test_entry_get_json (void) { gint64 updated, published, updated2, published2; GDataEntry *entry, *entry2; gchar *json; GError *error = NULL; entry = gdata_entry_new (NULL); /* Set the properties more conventionally */ gdata_entry_set_title (entry, "Testing title & \"escaping\""); gdata_entry_set_summary (entry, NULL); gdata_entry_set_content (entry, NULL); gdata_entry_set_rights (entry, NULL); /* Check the generated JSON's OK */ gdata_test_assert_json (entry, "{" "\"title\":\"Testing title & \\\"escaping\\\"\"" "}"); /* Check again by re-parsing the JSON to a GDataEntry. */ json = gdata_parsable_get_json (GDATA_PARSABLE (entry)); entry2 = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY, json, -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry2)); g_clear_error (&error); g_free (json); g_assert_cmpstr (gdata_entry_get_title (entry), ==, gdata_entry_get_title (entry2)); g_assert_cmpstr (gdata_entry_get_id (entry), ==, gdata_entry_get_id (entry2)); /* should both be NULL */ g_assert_cmpstr (gdata_entry_get_content (entry), ==, gdata_entry_get_content (entry2)); g_assert_cmpstr (gdata_entry_get_content_uri (entry), ==, gdata_entry_get_content_uri (entry2)); /* should both be NULL */ updated = gdata_entry_get_updated (entry); updated2 = gdata_entry_get_updated (entry2); g_assert_cmpuint (updated, ==, updated2); published = gdata_entry_get_published (entry); published2 = gdata_entry_get_published (entry2); g_assert_cmpuint (published, ==, published2); g_object_unref (entry); g_object_unref (entry2); } static void test_entry_parse_xml (void) { GDataEntry *entry; GError *error = NULL; /* Create an entry from XML with unhandled elements */ entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, "" "Testing unhandled XML" "2009-01-25T14:07:37Z" "2009-01-23T14:06:37Z" "Here we test unhandled XML elements." "Test!" "" "How about some characters‽" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry)); g_clear_error (&error); /* Now check the outputted XML from the entry still has the unhandled elements */ gdata_test_assert_xml (entry, "" "" "Testing unhandled XML" "2009-01-25T14:07:37.000001+00:00" "2009-01-23T14:06:37.000001+00:00" "Here we test unhandled XML elements." "Test!" "" "How about some characters‽" ""); g_object_unref (entry); } static void test_entry_parse_xml_kind_category (void) { GDataEntry *entry; GError *error = NULL; g_test_bug ("707477"); /* Create an entry from XML with a ‘kind’ category with extra attributes. */ entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, "" "Testing kind categories" "2009-01-25T14:07:37Z" "2009-01-23T14:06:37Z" "Here we test kind categories." "" "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry)); g_clear_error (&error); /* Now check the outputted XML from the entry still has the extra attributes */ gdata_test_assert_xml (entry, "" "" "Testing kind categories" "2009-01-25T14:07:37.000001+00:00" "2009-01-23T14:06:37.000001+00:00" "Here we test kind categories." "" "" ""); g_object_unref (entry); } static void test_entry_parse_json (void) { GDataEntry *entry; GError *error = NULL; /* Create an entry from JSON with unhandled nodes. */ entry = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY, "{" "\"title\":\"A title\"," "\"updated\":\"2009-01-25T14:07:37Z\"," "\"selfLink\":\"http://example.com/\"," "\"etag\":\"some-etag\"," "\"id\":\"some-id\"," "\"kind\":\"kind#kind\"," "\"unhandled-boolean\":false," "\"unhandled-string\":\"this-is-a-string---sometimes\"," "\"unhandled-int\":15," "\"unhandled-double\":42.42," "\"unhandled-object\":{" "\"a\":true," "\"b\":true" "}," "\"unhandled-array\":[" "1," "2," "3" "]," "\"unhandled-null\":null" "}", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry)); /* Now check the outputted JSON from the entry still has the unhandled nodes. */ gdata_test_assert_json (entry, "{" "\"title\":\"A title\"," "\"id\":\"some-id\"," "\"updated\":\"2009-01-25T14:07:37.000001+00:00\"," "\"etag\":\"some-etag\"," "\"selfLink\":\"http://example.com/\"," "\"kind\":\"kind#kind\"," "\"unhandled-boolean\":false," "\"unhandled-string\":\"this-is-a-string---sometimes\"," "\"unhandled-int\":15," "\"unhandled-double\":42.42," "\"unhandled-object\":{" "\"a\":true," "\"b\":true" "}," "\"unhandled-array\":[" "1," "2," "3" "]," "\"unhandled-null\":null" "}"); g_object_unref (entry); /* Test parsing of empty titles. */ entry = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY, "{" "\"title\":\"\"" "}", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry)); g_object_unref (entry); } static void test_entry_error_handling_xml (void) { GDataEntry *entry; GError *error = NULL; #define TEST_XML_ERROR_HANDLING(x) entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY,\ ""\ x\ "", -1, &error));\ g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);\ g_assert (entry == NULL);\ g_clear_error (&error) /* updated */ TEST_XML_ERROR_HANDLING ("not a date"); /* invalid date */ /* published */ TEST_XML_ERROR_HANDLING ("also not a date"); /* invalid date */ /* category */ TEST_XML_ERROR_HANDLING (""); /* invalid category */ /* link */ TEST_XML_ERROR_HANDLING (""); /* invalid link */ /* author */ TEST_XML_ERROR_HANDLING (""); /* invalid author */ #undef TEST_XML_ERROR_HANDLING } static void test_entry_error_handling_json (void) { GDataEntry *entry; GError *error = NULL; #define TEST_JSON_ERROR_HANDLING(x) \ entry = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY,x, -1, &error));\ g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);\ g_assert (entry == NULL);\ g_clear_error (&error) #define TEST_JSON_ERROR_HANDLING_PARSER(x) \ entry = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY,x, -1, &error));\ g_assert_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING);\ g_assert (entry == NULL);\ g_clear_error (&error) /* General structure. */ TEST_JSON_ERROR_HANDLING_PARSER ("[true,false,true]"); /* root node is not an object */ TEST_JSON_ERROR_HANDLING_PARSER ("false"); /* root node is not an object */ TEST_JSON_ERROR_HANDLING_PARSER ("invalid json"); /* totally invalid JSON */ /* id */ TEST_JSON_ERROR_HANDLING ("{\"id\":\"\"}"); /* empty */ TEST_JSON_ERROR_HANDLING ("{\"id\":null}"); /* invalid type */ /* updated */ TEST_JSON_ERROR_HANDLING ("{\"updated\":\"not correct\"}"); /* incorrect format */ TEST_JSON_ERROR_HANDLING ("{\"updated\":false}"); /* invalid type */ TEST_JSON_ERROR_HANDLING ("{\"updated\":\"\"}"); /* empty */ /* title */ TEST_JSON_ERROR_HANDLING ("{\"title\":false}"); /* invalid type */ /* etag */ TEST_JSON_ERROR_HANDLING ("{\"etag\":\"\"}"); /* empty */ TEST_JSON_ERROR_HANDLING ("{\"etag\":false}"); /* invalid type */ /* selfLink */ TEST_JSON_ERROR_HANDLING ("{\"selfLink\":\"\"}"); /* empty */ TEST_JSON_ERROR_HANDLING ("{\"selfLink\":false}"); /* invalid type */ /* kind */ TEST_JSON_ERROR_HANDLING ("{\"kind\":\"\"}"); /* empty */ TEST_JSON_ERROR_HANDLING ("{\"kind\":false}"); /* invalid type */ #undef TEST_JSON_ERROR_HANDLING_PARSER #undef TEST_JSON_ERROR_HANDLING } static void test_entry_escaping (void) { GDataEntry *entry; GError *error = NULL; /* Since we can't construct a GDataEntry directly, we need to parse it from XML */ entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, "" "" "Escaped content & stuff" "http://foo.com/?foo&bar" "2010-12-10T17:21:24Z" "2010-12-10T17:21:24Z" "Summary & stuff" "Free & open source" "Content & things." "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry)); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (entry, "" "" "Escaped content & stuff" "http://foo.com/?foo&bar" "2010-12-10T17:21:24.000001+00:00" "2010-12-10T17:21:24.000001+00:00" "Summary & stuff" "Free & open source" "Content & things." ""); g_object_unref (entry); /* Repeat with content given by a URI */ entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, "" "" "Escaped content & stuff" "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry)); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (entry, "" "" "Escaped content & stuff" "" ""); g_object_unref (entry); } static void test_entry_links_remove (void) { GDataEntry *entry; GDataLink *link_, *link2_; GError *error = NULL; /* Since we can't construct a GDataEntry directly, we need to parse it from XML. */ entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, "" "" "Escaped content & stuff" "http://foo.com/?foo&bar" "2010-12-10T17:21:24Z" "2010-12-10T17:21:24Z" "Summary & stuff" "Free & open source" "Content & things." "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ENTRY (entry)); link_ = gdata_link_new ("http://example.com/", GDATA_LINK_RELATED); /* Add a link. */ gdata_entry_add_link (entry, link_); g_assert (gdata_entry_look_up_link (entry, GDATA_LINK_RELATED) == link_); /* Remove the link. */ g_assert (gdata_entry_remove_link (entry, link_) == TRUE); g_assert (gdata_entry_look_up_link (entry, GDATA_LINK_RELATED) == NULL); /* Attempt to remove a non-existent link. */ link2_ = gdata_link_new ("http://foobar.com/", GDATA_LINK_SELF); g_assert (gdata_entry_remove_link (entry, link2_) == FALSE); g_object_unref (link2_); g_object_unref (link_); g_object_unref (entry); } static void test_feed_parse_xml (void) { GDataFeed *feed; GDataEntry *entry; GDataLink *_link; /* stupid unistd.h */ GList *list; gchar *title, *subtitle, *id, *etag, *logo, *icon, *rights; gint64 updated, updated2; GDataGenerator *generator; guint items_per_page, start_index, total_results; GError *error = NULL; feed = GDATA_FEED (gdata_parsable_new_from_xml (GDATA_TYPE_FEED, "" "http://example.com/id" "2009-02-25T14:07:37.880860Z" "Test feed" "Test subtitle" "http://example.com/logo.png" "http://example.com/icon.png" "" "" "" "" "" "public" "" "Joe Smith" "j.smith@example.com" "" "Example Generator" "2" "1" "50" "" "entry1" "Testing unhandled XML" "2009-01-25T14:07:37.880860Z" "2009-01-23T14:06:37.880860Z" "Here we test unhandled XML elements." "" "" "entry2" "Testing unhandled XML 2" "2009-02-25T14:07:37.880860Z" "2009-02-23T14:06:37.880860Z" "Here we test unhandled XML elements again." "" "Test unhandled elements!" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_FEED (feed)); g_clear_error (&error); /* Check the feed's properties */ g_object_get (G_OBJECT (feed), "title", &title, "subtitle", &subtitle, "id", &id, "etag", &etag, "updated", &updated, "logo", &logo, "icon", &icon, "generator", &generator, "rights", &rights, "items-per-page", &items_per_page, "start-index", &start_index, "total-results", &total_results, NULL); g_assert_cmpstr (title, ==, "Test feed"); g_assert_cmpstr (subtitle, ==, "Test subtitle"); g_assert_cmpstr (id, ==, "http://example.com/id"); g_assert_cmpstr (etag, ==, "W/\"D08FQn8-eil7ImA9WxZbFEw.\""); g_assert_cmpint (updated, ==, 1235570857); g_assert_cmpstr (logo, ==, "http://example.com/logo.png"); g_assert_cmpstr (icon, ==, "http://example.com/icon.png"); g_assert_cmpstr (rights, ==, "public"); g_assert (GDATA_IS_GENERATOR (generator)); g_assert_cmpstr (gdata_generator_get_name (generator), ==, "Example Generator"); g_assert_cmpstr (gdata_generator_get_uri (generator), ==, "http://example.com/"); g_assert_cmpstr (gdata_generator_get_version (generator), ==, "0.6"); g_assert_cmpuint (items_per_page, ==, 50); g_assert_cmpuint (start_index, ==, 1); g_assert_cmpuint (total_results, ==, 2); g_free (title); g_free (subtitle); g_free (id); g_free (etag); g_free (logo); g_free (icon); g_free (rights); g_object_unref (generator); /* Check the entries */ entry = gdata_feed_look_up_entry (feed, "entry1"); g_assert (GDATA_IS_ENTRY (entry)); entry = gdata_feed_look_up_entry (feed, "this doesn't exist"); g_assert (entry == NULL); entry = gdata_feed_look_up_entry (feed, "entry2"); g_assert (GDATA_IS_ENTRY (entry)); /* Check the categories */ list = gdata_feed_get_categories (feed); g_assert (list != NULL); g_assert_cmpint (g_list_length (list), ==, 1); g_assert (GDATA_IS_CATEGORY (list->data)); /* Check the links */ list = gdata_feed_get_links (feed); g_assert (list != NULL); g_assert_cmpint (g_list_length (list), ==, 4); g_assert (GDATA_IS_LINK (list->data)); g_assert (GDATA_IS_LINK (list->next->data)); g_assert (GDATA_IS_LINK (list->next->next->data)); g_assert (GDATA_IS_LINK (list->next->next->next->data)); _link = gdata_feed_look_up_link (feed, GDATA_LINK_ALTERNATE); g_assert (GDATA_IS_LINK (_link)); _link = gdata_feed_look_up_link (feed, "this doesn't exist"); g_assert (_link == NULL); _link = gdata_feed_look_up_link (feed, "http://schemas.google.com/g/2005#feed"); g_assert (GDATA_IS_LINK (_link)); _link = gdata_feed_look_up_link (feed, "http://schemas.google.com/g/2005#post"); g_assert (GDATA_IS_LINK (_link)); _link = gdata_feed_look_up_link (feed, GDATA_LINK_SELF); g_assert (GDATA_IS_LINK (_link)); /* Check the authors */ list = gdata_feed_get_authors (feed); g_assert (list != NULL); g_assert_cmpint (g_list_length (list), ==, 1); g_assert (GDATA_IS_AUTHOR (list->data)); /* Check the other properties again, the more normal way this time */ g_assert_cmpstr (gdata_feed_get_title (feed), ==, "Test feed"); g_assert_cmpstr (gdata_feed_get_subtitle (feed), ==, "Test subtitle"); g_assert_cmpstr (gdata_feed_get_id (feed), ==, "http://example.com/id"); g_assert_cmpstr (gdata_feed_get_etag (feed), ==, "W/\"D08FQn8-eil7ImA9WxZbFEw.\""); updated2 = gdata_feed_get_updated (feed); g_assert_cmpint (updated2, ==, 1235570857); g_assert_cmpstr (gdata_feed_get_logo (feed), ==, "http://example.com/logo.png"); g_assert_cmpstr (gdata_feed_get_icon (feed), ==, "http://example.com/icon.png"); g_assert_cmpstr (gdata_feed_get_rights (feed), ==, "public"); generator = gdata_feed_get_generator (feed); g_assert (GDATA_IS_GENERATOR (generator)); g_assert_cmpstr (gdata_generator_get_name (generator), ==, "Example Generator"); g_assert_cmpstr (gdata_generator_get_uri (generator), ==, "http://example.com/"); g_assert_cmpstr (gdata_generator_get_version (generator), ==, "0.6"); g_assert_cmpuint (gdata_feed_get_items_per_page (feed), ==, 50); g_assert_cmpuint (gdata_feed_get_start_index (feed), ==, 1); g_assert_cmpuint (gdata_feed_get_total_results (feed), ==, 2); g_object_unref (feed); } static void test_feed_error_handling (void) { GDataFeed *feed; GError *error = NULL; #define TEST_XML_ERROR_HANDLING(x) feed = GDATA_FEED (gdata_parsable_new_from_xml (GDATA_TYPE_FEED, \ ""\ x\ "", -1, &error));\ g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);\ g_assert (feed == NULL);\ g_clear_error (&error) /* entry */ TEST_XML_ERROR_HANDLING ("this isn't a date"); /* invalid entry */ /* title */ TEST_XML_ERROR_HANDLING ("First titleSecond title"); /* duplicate title */ #if 0 /* FIXME: Removed due to the YouTube comments feed not being a valid Atom feed. * See: https://code.google.com/p/gdata-issues/issues/detail?id=2908 * and: https://bugzilla.gnome.org/show_bug.cgi?id=679072 */ TEST_XML_ERROR_HANDLING ("ID2009-01-25T14:07:37.880860Z"); /* missing title */ #endif /* subtitle */ TEST_XML_ERROR_HANDLING ("First subtitleSecond subtitle"); /* duplicate subtitle */ /* id */ TEST_XML_ERROR_HANDLING ("First IDSecond ID"); /* duplicate ID */ TEST_XML_ERROR_HANDLING ("Title2009-01-25T14:07:37.880860Z"); /* missing ID */ /* updated */ TEST_XML_ERROR_HANDLING ("2009-01-25T14:07:37.880860Z" "2009-01-25T14:07:37.880860Z"); /* duplicate updated */ TEST_XML_ERROR_HANDLING ("not a date"); /* invalid date */ TEST_XML_ERROR_HANDLING ("TitleID"); /* missing updated */ /* category */ TEST_XML_ERROR_HANDLING (""); /* invalid category */ /* logo */ TEST_XML_ERROR_HANDLING ("First logoSecond logo"); /* duplicate logo */ /* icon */ TEST_XML_ERROR_HANDLING ("First iconSecond icon"); /* duplicate icon */ /* link */ TEST_XML_ERROR_HANDLING (""); /* invalid link */ /* author */ TEST_XML_ERROR_HANDLING (""); /* invalid author */ /* generator */ TEST_XML_ERROR_HANDLING ("First generatorSecond generator"); /* duplicate generator */ TEST_XML_ERROR_HANDLING (""); /* invalid generator */ /* openSearch:totalResults */ TEST_XML_ERROR_HANDLING ("5" "3"); /* duplicate totalResults */ TEST_XML_ERROR_HANDLING (""); /* missing content */ TEST_XML_ERROR_HANDLING ("this isn't a number!"); /* invalid number */ /* openSearch:startIndex */ TEST_XML_ERROR_HANDLING ("5" "3"); /* duplicate startIndex */ TEST_XML_ERROR_HANDLING (""); /* missing content */ TEST_XML_ERROR_HANDLING ("this isn't a number!"); /* invalid number */ /* openSearch:itemsPerPage */ TEST_XML_ERROR_HANDLING ("5" "3"); /* duplicate itemsPerPage */ TEST_XML_ERROR_HANDLING (""); /* missing content */ TEST_XML_ERROR_HANDLING ("this isn't a number!"); /* invalid number */ #undef TEST_XML_ERROR_HANDLING } static void test_feed_escaping (void) { GDataFeed *feed; GError *error = NULL; /* Since we can't construct a GDataEntry directly, we need to parse it from XML */ feed = GDATA_FEED (gdata_parsable_new_from_xml (GDATA_TYPE_FEED, "" "" "http://foo.com?foo&bar" "2010-12-10T17:49:15Z" "Test feed & stuff." "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_FEED (feed)); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (feed, "" "" "Test feed & stuff." "http://foo.com?foo&bar" "2010-12-10T17:49:15.000001+00:00" ""); g_object_unref (feed); } static void test_query_categories (void) { GDataQuery *query; gchar *query_uri; query = gdata_query_new ("foobar"); /* AND */ gdata_query_set_categories (query, "Fritz/Laurie"); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com/-/Fritz/Laurie?q=foobar"); g_free (query_uri); /* OR */ gdata_query_set_categories (query, "Fritz|Laurie"); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com/-/Fritz%7CLaurie?q=foobar"); g_free (query_uri); /* Combination */ gdata_query_set_categories (query, "A|-{urn:google.com}B/-C"); query_uri = gdata_query_get_query_uri (query, "http://example.com/gdata_test"); g_assert_cmpstr (query_uri, ==, "http://example.com/gdata_test/-/A%7C-%7Burn%3Agoogle.com%7DB/-C?q=foobar"); g_free (query_uri); /* Same combination without q param */ gdata_query_set_q (query, NULL); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com/-/A%7C-%7Burn%3Agoogle.com%7DB/-C"); g_free (query_uri); g_object_unref (query); } static void test_query_dates (void) { GDataQuery *query; gchar *query_uri; query = gdata_query_new ("baz"); /* updated-min */ gdata_query_set_updated_min (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-min=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_updated_min (query, -1); /* updated-max */ gdata_query_set_updated_max (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-max=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_updated_max (query, -1); /* published-min */ gdata_query_set_published_min (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-min=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_published_min (query, -1); /* published-max */ gdata_query_set_published_max (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-max=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_published_max (query, -1); g_object_unref (query); } static void test_query_strict (void) { GDataQuery *query; gchar *query_uri; query = gdata_query_new ("bar"); gdata_query_set_is_strict (query, TRUE); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com?q=bar&strict=true"); g_free (query_uri); gdata_query_set_is_strict (query, FALSE); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com?q=bar"); g_free (query_uri); g_object_unref (query); } static void test_query_pagination (void) { GDataQuery *query; gchar *query_uri; query = gdata_query_new ("test"); gdata_query_set_max_results (query, 15); gdata_query_set_etag (query, "etag"); /* this should be cleared by pagination */ query_uri = gdata_query_get_query_uri (query, "http://example.com/"); g_assert_cmpstr (query_uri, ==, "http://example.com/?q=test&max-results=15"); g_free (query_uri); /* Try the next and previous pages. */ gdata_query_next_page (query); g_assert (gdata_query_get_etag (query) == NULL); query_uri = gdata_query_get_query_uri (query, "http://example.com/"); g_assert_cmpstr (query_uri, ==, "http://example.com/?q=test&start-index=16&max-results=15"); g_free (query_uri); gdata_query_set_etag (query, "etag"); g_assert (gdata_query_previous_page (query) == TRUE); g_assert (gdata_query_get_etag (query) == NULL); query_uri = gdata_query_get_query_uri (query, "http://example.com/"); g_assert_cmpstr (query_uri, ==, "http://example.com/?q=test&max-results=15"); g_free (query_uri); /* Try another previous page. This should fail, and the ETag should be untouched. */ gdata_query_set_etag (query, "etag"); g_assert (gdata_query_previous_page (query) == FALSE); g_assert_cmpstr (gdata_query_get_etag (query), ==, "etag"); g_object_unref (query); /* Try the alternate constructor. */ query = gdata_query_new_with_limits ("test", 40, 10); query_uri = gdata_query_get_query_uri (query, "http://example.com/"); g_assert_cmpstr (query_uri, ==, "http://example.com/?q=test&start-index=40&max-results=10"); g_free (query_uri); /* Try the next and previous pages again. */ gdata_query_next_page (query); query_uri = gdata_query_get_query_uri (query, "http://example.com/"); g_assert_cmpstr (query_uri, ==, "http://example.com/?q=test&start-index=50&max-results=10"); g_free (query_uri); g_assert (gdata_query_previous_page (query) == TRUE); query_uri = gdata_query_get_query_uri (query, "http://example.com/"); g_assert_cmpstr (query_uri, ==, "http://example.com/?q=test&start-index=40&max-results=10"); g_free (query_uri); g_assert (gdata_query_previous_page (query) == TRUE); query_uri = gdata_query_get_query_uri (query, "http://example.com/"); g_assert_cmpstr (query_uri, ==, "http://example.com/?q=test&start-index=30&max-results=10"); g_free (query_uri); g_object_unref (query); } static void notify_cb (GObject *obj, GParamSpec *pspec, gpointer user_data) { gboolean *notification_received = user_data; g_assert (*notification_received == FALSE); *notification_received = TRUE; } static void test_query_properties (void) { GDataQuery *query; gboolean notification_received = FALSE; gulong handler_id; query = gdata_query_new ("default"); #define CHECK_PROPERTY(cmptype, name_hyphens, name_underscores, default_val, new_val, new_val2, val_type, free_val) \ { \ val_type val; \ \ handler_id = g_signal_connect (query, "notify::" name_hyphens, (GCallback) notify_cb, ¬ification_received); \ \ g_assert_##cmptype (gdata_query_get_##name_underscores (query), ==, default_val); \ g_object_get (query, name_hyphens, &val, NULL); \ g_assert_##cmptype (val, ==, default_val); \ if (free_val == TRUE) { \ g_free ((gpointer) ((guintptr) val)); \ } \ \ notification_received = FALSE; \ gdata_query_set_##name_underscores (query, new_val); \ g_assert (notification_received == TRUE); \ \ g_assert_##cmptype (gdata_query_get_##name_underscores (query), ==, new_val); \ \ notification_received = FALSE; \ g_object_set (query, name_hyphens, (val_type) new_val2, NULL); \ g_assert (notification_received == TRUE); \ \ g_assert_##cmptype (gdata_query_get_##name_underscores (query), ==, new_val2); \ \ g_signal_handler_disconnect (query, handler_id); \ } #define CHECK_PROPERTY_STR(name_hyphens, name_underscores, default_val) \ CHECK_PROPERTY (cmpstr, name_hyphens, name_underscores, default_val, "new", "new2", gchar*, TRUE) #define CHECK_PROPERTY_INT64(name_hyphens, name_underscores, default_val) \ CHECK_PROPERTY (cmpint, name_hyphens, name_underscores, default_val, 123, 5134132, gint64, FALSE) #define CHECK_PROPERTY_UINT(name_hyphens, name_underscores, default_val) \ CHECK_PROPERTY (cmpuint, name_hyphens, name_underscores, default_val, 535, 123, guint, FALSE) #define CHECK_PROPERTY_BOOLEAN(name_hyphens, name_underscores, default_val) \ CHECK_PROPERTY (cmpuint, name_hyphens, name_underscores, default_val, TRUE, FALSE, gboolean, FALSE) CHECK_PROPERTY_STR ("q", q, "default"); CHECK_PROPERTY_STR ("categories", categories, NULL); CHECK_PROPERTY_STR ("author", author, NULL); CHECK_PROPERTY_INT64 ("updated-min", updated_min, -1); CHECK_PROPERTY_INT64 ("updated-max", updated_max, -1); CHECK_PROPERTY_INT64 ("published-min", published_min, -1); CHECK_PROPERTY_INT64 ("published-max", published_max, -1); CHECK_PROPERTY_UINT ("start-index", start_index, 0); #define gdata_query_get_is_strict gdata_query_is_strict CHECK_PROPERTY_BOOLEAN ("is-strict", is_strict, FALSE); #undef gdata_query_get_is_strict CHECK_PROPERTY_UINT ("max-results", max_results, 0); CHECK_PROPERTY_STR ("etag", etag, NULL); #undef CHECK_PROPERTY_BOOLEAN #undef CHECK_PROPERTY_UINT #undef CHECK_PROPERTY_INT64 #undef CHECK_PROPERTY_STR #undef CHECK_PROPERTY g_object_unref (query); } static void test_query_unicode (void) { GDataQuery *query; gchar *query_uri; g_test_bug ("602497"); /* Simple query */ query = gdata_query_new ("fööbar‽"); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com?q=f%C3%B6%C3%B6bar%E2%80%BD"); g_free (query_uri); /* Categories */ gdata_query_set_categories (query, "Ümlauts|¿Questions‽"); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com/-/%C3%9Cmlauts%7C%C2%BFQuestions%E2%80%BD?q=f%C3%B6%C3%B6bar%E2%80%BD"); g_free (query_uri); /* Author */ gdata_query_set_author (query, "Lørd Brïan Bleßêd"); query_uri = gdata_query_get_query_uri (query, "http://example.com"); g_assert_cmpstr (query_uri, ==, "http://example.com/-/%C3%9Cmlauts%7C%C2%BFQuestions%E2%80%BD?q=f%C3%B6%C3%B6bar%E2%80%BD&author=L%C3%B8rd%20Br%C3%AFan%20Ble%C3%9F%C3%AAd"); g_free (query_uri); g_object_unref (query); } static void test_query_etag (void) { GDataQuery *query = gdata_query_new (NULL); /* Test that setting any property will unset the ETag */ g_test_bug ("613529"); /* Also check that setting the ETag doesn't unset the ETag! */ gdata_query_set_etag (query, "foobar"); g_assert_cmpstr (gdata_query_get_etag (query), ==, "foobar"); #define CHECK_ETAG(C) \ gdata_query_set_etag (query, "foobar"); \ C; \ g_assert (gdata_query_get_etag (query) == NULL); CHECK_ETAG (gdata_query_set_q (query, "q")) CHECK_ETAG (gdata_query_set_categories (query, "shizzle,foobar")) CHECK_ETAG (gdata_query_set_author (query, "John Smith")) CHECK_ETAG (gdata_query_set_updated_min (query, -1)) CHECK_ETAG (gdata_query_set_updated_max (query, -1)) CHECK_ETAG (gdata_query_set_published_min (query, -1)) CHECK_ETAG (gdata_query_set_published_max (query, -1)) CHECK_ETAG (gdata_query_set_start_index (query, 5)) CHECK_ETAG (gdata_query_set_is_strict (query, TRUE)) CHECK_ETAG (gdata_query_set_max_results (query, 1000)) CHECK_ETAG (gdata_query_next_page (query)) CHECK_ETAG (g_assert (gdata_query_previous_page (query))) #undef CHECK_ETAG g_object_unref (query); } static void test_service_network_error (void) { GDataService *service; #if 0 SoupURI *proxy_uri; #endif GError *error = NULL; /* This is a little hacky, but it should work */ service = g_object_new (GDATA_TYPE_SERVICE, NULL); /* Try a query which should always fail due to errors resolving the hostname */ g_assert (gdata_service_query (service, NULL, "https://thisshouldnotexist.invalid", NULL, GDATA_TYPE_ENTRY, NULL, NULL, NULL, &error) == NULL); g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_NETWORK_ERROR); g_clear_error (&error); /* TODO: We have to disable this test, as libsoup 2.30.2 < x <= 2.32.0 doesn't return SOUP_STATUS_CANT_RESOLVE_PROXY properly any more. * Filed as bgo#632354. */ #if 0 /* Try one with a bad proxy set */ proxy_uri = soup_uri_new ("https://thisshouldalsonotexist.invalid/proxy"); gdata_service_set_proxy_uri (service, proxy_uri); soup_uri_free (proxy_uri); g_assert (gdata_service_query (service, "https://google.com", NULL, GDATA_TYPE_ENTRY, NULL, NULL, NULL, &error) == NULL); g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROXY_ERROR); g_clear_error (&error); #endif g_object_unref (service); } static void test_service_locale (void) { GDataService *service; gchar *locale; /* This is a little hacky, but it should work */ service = g_object_new (GDATA_TYPE_SERVICE, NULL); /* Just test setting and getting the locale */ g_assert (gdata_service_get_locale (service) == NULL); gdata_service_set_locale (service, "en_GB"); g_assert_cmpstr (gdata_service_get_locale (service), ==, "en_GB"); g_object_get (service, "locale", &locale, NULL); g_assert_cmpstr (locale, ==, "en_GB"); g_free (locale); g_object_unref (service); } static void test_access_rule_get_xml (void) { GDataAccessRule *rule, *rule2; const gchar *content_type; gchar *xml, *role, *scope_type3, *scope_value3, *key; gint64 edited, edited2; const gchar *scope_type, *scope_value, *scope_type2, *scope_value2; GError *error = NULL; rule = gdata_access_rule_new ("an-id"); /* Test setting properties directly */ g_object_set (G_OBJECT (rule), "role", "A role", "scope-type", "A scope type", "scope-value", "A scope value", NULL); g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, "A role"); gdata_access_rule_get_scope (rule, &scope_type, &scope_value); g_assert_cmpstr (scope_type, ==, "A scope type"); g_assert_cmpstr (scope_value, ==, "A scope value"); edited = gdata_access_rule_get_edited (rule); g_assert_cmpuint (edited, >, 0); /* current time */ g_assert_cmpstr (gdata_access_rule_get_key (rule), ==, NULL); /* Set the properties more conventionally */ gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE); gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "foo@example.com"); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (rule)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the generated XML's OK */ gdata_test_assert_xml (rule, "" "" "none" "an-id" "" "" "" ""); /* Check again by re-parsing the XML to a GDataAccessRule */ xml = gdata_parsable_get_xml (GDATA_PARSABLE (rule)); rule2 = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (GDATA_TYPE_ACCESS_RULE, xml, -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ACCESS_RULE (rule2)); g_clear_error (&error); g_free (xml); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (rule2)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, gdata_access_rule_get_role (rule2)); gdata_access_rule_get_scope (rule, &scope_type, &scope_value); gdata_access_rule_get_scope (rule2, &scope_type2, &scope_value2); g_assert_cmpstr (scope_type, ==, scope_type2); g_assert_cmpstr (scope_value, ==, scope_value2); edited = gdata_access_rule_get_edited (rule2); g_assert_cmpuint (edited, ==, -1); /* unspecified in XML */ g_assert_cmpstr (gdata_access_rule_get_key (rule), ==, gdata_access_rule_get_key (rule2)); /* Check properties a different way */ g_object_get (G_OBJECT (rule2), "role", &role, "scope-type", &scope_type3, "scope-value", &scope_value3, "edited", &edited2, "key", &key, NULL); g_assert_cmpstr (role, ==, gdata_access_rule_get_role (rule)); g_assert_cmpstr (scope_type, ==, scope_type3); g_assert_cmpstr (scope_value, ==, scope_value3); g_assert_cmpuint (edited2, ==, -1); g_assert_cmpstr (key, ==, NULL); g_free (role); g_free (scope_type3); g_free (scope_value3); /* Test that the GDataAccessRule:role and GDataEntry:title properties are linked */ gdata_entry_set_title (GDATA_ENTRY (rule), "Another role"); g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, "Another role"); gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE); g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (rule)), ==, "none"); g_object_unref (rule); g_object_unref (rule2); /* Check that a rule with scope type 'default' doesn't have a value. * See: https://developers.google.com/google-apps/calendar/v2/reference#gacl_reference */ rule = gdata_access_rule_new ("another-id"); gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE); gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_DEFAULT, NULL); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (rule)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the generated XML's OK */ gdata_test_assert_xml (rule, "" "" "none" "another-id" "" "" "" ""); /* Check by re-parsing the XML to a GDataAccessRule */ xml = gdata_parsable_get_xml (GDATA_PARSABLE (rule)); rule2 = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (GDATA_TYPE_ACCESS_RULE, xml, -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ACCESS_RULE (rule2)); g_clear_error (&error); g_free (xml); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (rule2)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, gdata_access_rule_get_role (rule2)); gdata_access_rule_get_scope (rule, &scope_type, &scope_value); gdata_access_rule_get_scope (rule2, &scope_type2, &scope_value2); g_assert_cmpstr (scope_type, ==, scope_type2); g_assert_cmpstr (scope_value, ==, scope_value2); edited = gdata_access_rule_get_edited (rule2); g_assert_cmpuint (edited, ==, -1); /* unspecified in XML */ g_object_unref (rule); g_object_unref (rule2); } static void test_access_rule_get_xml_with_key (void) { GDataAccessRule *rule; gint64 edited; const gchar *content_type, *scope_type, *scope_value; GError *error = NULL; rule = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (GDATA_TYPE_ACCESS_RULE, "" "" "none" "an-id" "" "" "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_ACCESS_RULE (rule)); /* Check the properties. */ g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, "none"); gdata_access_rule_get_scope (rule, &scope_type, &scope_value); g_assert_cmpstr (scope_type, ==, "user"); g_assert_cmpstr (scope_value, ==, "foo@example.com"); edited = gdata_access_rule_get_edited (rule); g_assert_cmpuint (edited, >, 0); /* current time */ g_assert_cmpstr (gdata_access_rule_get_key (rule), ==, "asdasd"); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (rule)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same. */ gdata_test_assert_xml (rule, "" "" "none" "an-id" "" "" "" ""); g_object_unref (rule); } static void test_access_rule_error_handling (void) { GDataAccessRule *rule; GError *error = NULL; #define TEST_XML_ERROR_HANDLING(x) rule = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (GDATA_TYPE_ACCESS_RULE,\ ""\ x\ "", -1, &error));\ g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);\ g_assert (rule == NULL);\ g_clear_error (&error) /* role */ TEST_XML_ERROR_HANDLING (""); /* missing value */ /* scope */ TEST_XML_ERROR_HANDLING (""); /* missing type */ TEST_XML_ERROR_HANDLING (""); /* missing value */ TEST_XML_ERROR_HANDLING (""); /* missing value */ /* edited */ TEST_XML_ERROR_HANDLING (""); /* missing date */ TEST_XML_ERROR_HANDLING ("not a date"); /* bad date */ /* withKey */ TEST_XML_ERROR_HANDLING (""); /* missing key */ TEST_XML_ERROR_HANDLING (""); /* missing role */ TEST_XML_ERROR_HANDLING (""); /* missing role */ #undef TEST_XML_ERROR_HANDLING } static void test_access_rule_escaping (void) { GDataAccessRule *rule; rule = gdata_access_rule_new (NULL); gdata_access_rule_set_role (rule, ""); gdata_access_rule_set_scope (rule, "", ""); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (rule, "" "" "<role>" "" "" "" ""); g_object_unref (rule); } static void test_comparable (void) { GDataComparable *category = GDATA_COMPARABLE (gdata_category_new ("term", "http://scheme", "label")); /* Test the NULL comparisons */ g_assert_cmpint (gdata_comparable_compare (category, NULL), ==, 1); g_assert_cmpint (gdata_comparable_compare (NULL, category), ==, -1); g_assert_cmpint (gdata_comparable_compare (NULL, NULL), ==, 0); g_assert_cmpint (gdata_comparable_compare (category, category), ==, 0); g_object_unref (category); } static void test_color_parsing (void) { GDataColor color; /* With hash */ g_assert (gdata_color_from_hexadecimal ("#F99Ff0", &color) == TRUE); g_assert_cmpuint (color.red, ==, 249); g_assert_cmpuint (color.green, ==, 159); g_assert_cmpuint (color.blue, ==, 240); /* Without hash */ g_assert (gdata_color_from_hexadecimal ("F99Ff0", &color) == TRUE); g_assert_cmpuint (color.red, ==, 249); g_assert_cmpuint (color.green, ==, 159); g_assert_cmpuint (color.blue, ==, 240); /* Invalid, but correct length */ g_assert (gdata_color_from_hexadecimal ("foobar", &color) == FALSE); /* Wildly invalid */ g_assert (gdata_color_from_hexadecimal ("this is not a real colour!", &color) == FALSE); } static void test_color_output (void) { GDataColor color; gchar *color_string; /* General test */ g_assert (gdata_color_from_hexadecimal ("#F99Ff0", &color) == TRUE); color_string = gdata_color_to_hexadecimal (&color); g_assert_cmpstr (color_string, ==, "#f99ff0"); g_free (color_string); /* Boundary tests */ g_assert (gdata_color_from_hexadecimal ("#ffffff", &color) == TRUE); color_string = gdata_color_to_hexadecimal (&color); g_assert_cmpstr (color_string, ==, "#ffffff"); g_free (color_string); g_assert (gdata_color_from_hexadecimal ("#000000", &color) == TRUE); color_string = gdata_color_to_hexadecimal (&color); g_assert_cmpstr (color_string, ==, "#000000"); g_free (color_string); } /*static void test_media_thumbnail_parse_time (const gchar *locale) { g_test_bug ("584737"); g_test_message ("Testing gdata_media_thumbnail_parse_time in the \"%s\" locale...", locale); g_assert_cmpstr (setlocale (LC_ALL, locale), ==, locale); g_assert_cmpint (gdata_media_thumbnail_parse_time ("00:01:42.500"), ==, 102500); g_assert_cmpint (gdata_media_thumbnail_parse_time ("00:02:45"), ==, 165000); g_assert_cmpint (gdata_media_thumbnail_parse_time ("12:00:15.000"), ==, 43215000); g_assert_cmpint (gdata_media_thumbnail_parse_time ("00:00:00"), ==, 0); g_assert_cmpint (gdata_media_thumbnail_parse_time ("foobar"), ==, -1); setlocale (LC_ALL, ""); }*/ static void test_atom_author (void) { GDataAuthor *author, *author2; const gchar *content_type; gchar *name, *uri, *email_address; GError *error = NULL; author = GDATA_AUTHOR (gdata_parsable_new_from_xml (GDATA_TYPE_AUTHOR, "" "John Smöth" "http://example.com/" "john@example.com" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_AUTHOR (author)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_author_get_name (author), ==, "John Smöth"); g_assert_cmpstr (gdata_author_get_uri (author), ==, "http://example.com/"); g_assert_cmpstr (gdata_author_get_email_address (author), ==, "john@example.com"); /* Compare it against another identical author */ author2 = gdata_author_new ("John Smöth", "http://example.com/", "john@example.com"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (author), GDATA_COMPARABLE (author2)), ==, 0); g_object_unref (author2); /* …and a different author */ author2 = gdata_author_new ("Brian Blessed", NULL, NULL); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (author), GDATA_COMPARABLE (author2)), !=, 0); g_object_unref (author2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (author)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (author, "" "" "John Smöth" "http://example.com/" "john@example.com" ""); /* Check the properties */ g_object_get (G_OBJECT (author), "name", &name, "uri", &uri, "email-address", &email_address, NULL); g_assert_cmpstr (name, ==, "John Smöth"); g_assert_cmpstr (uri, ==, "http://example.com/"); g_assert_cmpstr (email_address, ==, "john@example.com"); g_free (name); g_free (uri); g_free (email_address); g_object_unref (author); /* Now parse an author with little information available */ author = GDATA_AUTHOR (gdata_parsable_new_from_xml (GDATA_TYPE_AUTHOR, "" "James Johnson" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_AUTHOR (author)); g_clear_error (&error); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (author)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the properties */ g_assert_cmpstr (gdata_author_get_name (author), ==, "James Johnson"); g_assert (gdata_author_get_uri (author) == NULL); g_assert (gdata_author_get_email_address (author) == NULL); g_object_unref (author); } static void test_atom_author_error_handling (void) { GDataAuthor *author; GError *error = NULL; #define TEST_XML_ERROR_HANDLING(x) author = GDATA_AUTHOR (gdata_parsable_new_from_xml (GDATA_TYPE_AUTHOR,\ ""\ x\ "", -1, &error));\ g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);\ g_assert (author == NULL);\ g_clear_error (&error) /* name */ TEST_XML_ERROR_HANDLING ("John SmöthNot John Smöth"); /* duplicated name */ TEST_XML_ERROR_HANDLING (""); /* empty name */ TEST_XML_ERROR_HANDLING ("http://example.com/john@example.com"); /* missing name */ /* uri */ TEST_XML_ERROR_HANDLING ("http://example.com/http://another-example.com/"); /* duplicated URI */ /* email */ TEST_XML_ERROR_HANDLING ("john@example.comjohn@another-example.com"); /* duplicated e-mail address */ #undef TEST_XML_ERROR_HANDLING } static void test_atom_author_escaping (void) { GDataAuthor *author; author = gdata_author_new ("First & Last Name", "http://foo.com?foo&bar", "John Smith "); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (author, "" "" "First & Last Name" "http://foo.com?foo&bar" "John Smith <john.smith@gmail.com>" ""); g_object_unref (author); } static void test_atom_category (void) { GDataCategory *category, *category2; const gchar *content_type; gchar *term, *scheme, *label; GError *error = NULL; category = GDATA_CATEGORY (gdata_parsable_new_from_xml (GDATA_TYPE_CATEGORY, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_CATEGORY (category)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_category_get_term (category), ==, "jokes"); g_assert_cmpstr (gdata_category_get_scheme (category), ==, "http://foobar.com#categories"); g_assert_cmpstr (gdata_category_get_label (category), ==, "Jokes & Trivia"); /* Compare it against another identical category */ category2 = gdata_category_new ("jokes", "http://foobar.com#categories", "Jokes & Trivia"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (category), GDATA_COMPARABLE (category2)), ==, 0); g_object_unref (category2); /* …and a different category */ category2 = gdata_category_new ("sports", "http://foobar.com#categories", NULL); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (category), GDATA_COMPARABLE (category2)), !=, 0); g_object_unref (category2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (category)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (category, "" ""); /* Check the properties */ g_object_get (G_OBJECT (category), "term", &term, "scheme", &scheme, "label", &label, NULL); g_assert_cmpstr (term, ==, "jokes"); g_assert_cmpstr (scheme, ==, "http://foobar.com#categories"); g_assert_cmpstr (label, ==, "Jokes & Trivia"); g_free (term); g_free (scheme); g_free (label); g_object_unref (category); /* Now parse a category with less information available */ category = GDATA_CATEGORY (gdata_parsable_new_from_xml (GDATA_TYPE_CATEGORY, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_CATEGORY (category)); g_clear_error (&error); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (category)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the properties */ g_assert_cmpstr (gdata_category_get_term (category), ==, "sports"); g_assert (gdata_category_get_scheme (category) == NULL); g_assert (gdata_category_get_label (category) == NULL); g_object_unref (category); /* Try a category with custom content */ category = GDATA_CATEGORY (gdata_parsable_new_from_xml (GDATA_TYPE_CATEGORY, "" "" "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_CATEGORY (category)); g_clear_error (&error); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (category)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (category, "" "" "" "" ""); g_object_unref (category); } static void test_atom_category_error_handling (void) { GDataCategory *category; GError *error = NULL; /* Missing term */ category = GDATA_CATEGORY (gdata_parsable_new_from_xml (GDATA_TYPE_CATEGORY, "", -1, &error)); g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR); g_assert (category == NULL); g_clear_error (&error); } static void test_atom_category_escaping (void) { GDataCategory *category; category = gdata_category_new ("", "http://foo.com?foo&bar", "Label & Stuff"); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (category, "" ""); g_object_unref (category); } static void test_atom_generator (void) { GDataGenerator *generator, *generator2; const gchar *content_type; gchar *name, *uri, *version; GError *error = NULL; generator = GDATA_GENERATOR (gdata_parsable_new_from_xml (GDATA_TYPE_GENERATOR, "Bach & Son's Generator", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GENERATOR (generator)); g_clear_error (&error); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (generator)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Compare it against another identical generator */ generator2 = GDATA_GENERATOR (gdata_parsable_new_from_xml (GDATA_TYPE_GENERATOR, "Bach & Son's Generator", -1, NULL)); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (generator), GDATA_COMPARABLE (generator2)), ==, 0); g_object_unref (generator2); /* …and a different generator */ generator2 = GDATA_GENERATOR (gdata_parsable_new_from_xml (GDATA_TYPE_GENERATOR, "Different generator", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GENERATOR (generator)); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (generator), GDATA_COMPARABLE (generator2)), !=, 0); g_object_unref (generator2); /* Check the properties */ g_assert_cmpstr (gdata_generator_get_name (generator), ==, "Bach & Son's Generator"); g_assert_cmpstr (gdata_generator_get_uri (generator), ==, "http://example.com/"); g_assert_cmpstr (gdata_generator_get_version (generator), ==, "15"); /* Check them a different way too */ g_object_get (G_OBJECT (generator), "name", &name, "uri", &uri, "version", &version, NULL); g_assert_cmpstr (name, ==, "Bach & Son's Generator"); g_assert_cmpstr (uri, ==, "http://example.com/"); g_assert_cmpstr (version, ==, "15"); g_free (name); g_free (uri); g_free (version); g_object_unref (generator); /* Now parse a generator with less information available */ generator = GDATA_GENERATOR (gdata_parsable_new_from_xml (GDATA_TYPE_GENERATOR, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GENERATOR (generator)); g_clear_error (&error); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (generator)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the properties */ g_assert (gdata_generator_get_name (generator) == NULL); g_assert (gdata_generator_get_uri (generator) == NULL); g_assert (gdata_generator_get_version (generator) == NULL); g_object_unref (generator); } static void test_atom_generator_error_handling (void) { GDataGenerator *generator; GError *error = NULL; /* Empty URI */ generator = GDATA_GENERATOR (gdata_parsable_new_from_xml (GDATA_TYPE_GENERATOR, "", -1, &error)); g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR); g_assert (generator == NULL); g_clear_error (&error); } static void test_atom_link (void) { GDataLink *link1, *link2; gchar *uri, *relation_type, *content_type, *language, *title; gint length; GError *error = NULL; link1 = GDATA_LINK (gdata_parsable_new_from_xml (GDATA_TYPE_LINK, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_LINK (link1)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_link_get_uri (link1), ==, "http://example.com/"); g_assert_cmpstr (gdata_link_get_relation_type (link1), ==, "http://test.com#link-type"); g_assert_cmpstr (gdata_link_get_content_type (link1), ==, "text/plain"); g_assert_cmpstr (gdata_link_get_language (link1), ==, "de"); g_assert_cmpstr (gdata_link_get_title (link1), ==, "All About Angle Brackets: <, >"); g_assert_cmpint (gdata_link_get_length (link1), ==, 2000); /* Compare it against another identical link */ link2 = gdata_link_new ("http://example.com/", "http://test.com#link-type"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (link1), GDATA_COMPARABLE (link2)), ==, 0); gdata_link_set_content_type (link2, "text/plain"); gdata_link_set_language (link2, "de"); gdata_link_set_title (link2, "All About Angle Brackets: <, >"); gdata_link_set_length (link2, 2000); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (link1), GDATA_COMPARABLE (link2)), ==, 0); /* Try with a dissimilar link */ gdata_link_set_uri (link2, "http://gnome.org/"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (link1), GDATA_COMPARABLE (link2)), !=, 0); g_object_unref (link2); g_assert_cmpstr (gdata_parsable_get_content_type (GDATA_PARSABLE (link1)), ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (link1, "" ""); /* Set some of the properties */ g_object_set (G_OBJECT (link1), "uri", "http://another-example.com/", "relation-type", "http://test.com#link-type2", "content-type", "text/html", "language", "sv", "title", "This & That About ", "length", -1, NULL); /* Check the properties */ g_object_get (G_OBJECT (link1), "uri", &uri, "relation-type", &relation_type, "content-type", &content_type, "language", &language, "title", &title, "length", &length, NULL); g_assert_cmpstr (uri, ==, "http://another-example.com/"); g_assert_cmpstr (relation_type, ==, "http://test.com#link-type2"); g_assert_cmpstr (content_type, ==, "text/html"); g_assert_cmpstr (language, ==, "sv"); g_assert_cmpstr (title, ==, "This & That About "); g_assert_cmpint (length, ==, -1); g_free (uri); g_free (relation_type); g_free (content_type); g_free (language); g_free (title); g_object_unref (link1); /* Now parse a link with less information available */ link1 = GDATA_LINK (gdata_parsable_new_from_xml (GDATA_TYPE_LINK, "Test Content", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_LINK (link1)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_link_get_uri (link1), ==, "http://shizzle.com"); g_assert_cmpstr (gdata_link_get_relation_type (link1), ==, "http://www.iana.org/assignments/relation/alternate"); g_assert (gdata_link_get_content_type (link1) == NULL); g_assert (gdata_link_get_language (link1) == NULL); g_assert (gdata_link_get_title (link1) == NULL); g_assert (gdata_link_get_length (link1) == -1); g_assert_cmpstr (gdata_parsable_get_content_type (GDATA_PARSABLE (link1)), ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (link1, "" "" "Test Content"); g_object_unref (link1); } static void test_atom_link_error_handling (void) { GDataLink *_link; /* stupid unistd.h */ GError *error = NULL; #define TEST_XML_ERROR_HANDLING(x) _link = GDATA_LINK (gdata_parsable_new_from_xml (GDATA_TYPE_LINK,\ "", -1, &error));\ g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);\ g_assert (_link == NULL);\ g_clear_error (&error) /* href */ TEST_XML_ERROR_HANDLING (""); /* missing href */ TEST_XML_ERROR_HANDLING ("href=''"); /* empty href */ /* rel */ TEST_XML_ERROR_HANDLING ("href='http://example.com/' rel=''"); /* empty rel */ /* type */ TEST_XML_ERROR_HANDLING ("href='http://example.com/' type=''"); /* empty type */ /* hreflang */ TEST_XML_ERROR_HANDLING ("href='http://example.com/' hreflang=''"); /* empty hreflang */ #undef TEST_XML_ERROR_HANDLING } static void test_atom_link_escaping (void) { GDataLink *_link; _link = gdata_link_new ("http://foo.com?foo&bar", "http://foo.com?foo&relation=bar"); gdata_link_set_content_type (_link, ""); gdata_link_set_language (_link, ""); gdata_link_set_title (_link, "Title & stuff"); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (_link, "" ""); g_object_unref (_link); } static void test_app_categories (void) { GDataAPPCategories *categories; GList *_categories; gboolean fixed; const gchar *content_type; GError *error = NULL; categories = GDATA_APP_CATEGORIES (gdata_parsable_new_from_json (GDATA_TYPE_APP_CATEGORIES, "{" "'kind': 'youtube#videoCategoryListResponse'," "'etag': '\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/1v2mrzYSYG6onNLt2qTj13hkQZk\"'," "'items': [" "{" "'kind': 'youtube#videoCategory'," "'etag': '\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/Xy1mB4_yLrHy_BmKmPBggty2mZQ\"'," "'id': '1'," "'snippet': {" "'channelId': 'UCBR8-60-B28hp2BmDPdntcQ'," "'title': 'Film & Animation'," "'assignable': true" "}" "}," "{" "'kind': 'youtube#videoCategory'," "'etag': '\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/UZ1oLIIz2dxIhO45ZTFR3a3NyTA\"'," "'id': '2'," "'snippet': {" "'channelId': 'UCBR8-60-B28hp2BmDPdntcQ'," "'title': 'Autos & Vehicles'," "'assignable': true" "}" "}" "]" "}", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_APP_CATEGORIES (categories)); g_clear_error (&error); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (categories)); g_assert_cmpstr (content_type, ==, "application/json"); /* Check the properties */ g_assert (gdata_app_categories_is_fixed (categories) == FALSE); /* Check them a different way too */ g_object_get (G_OBJECT (categories), "is-fixed", &fixed, NULL); g_assert (fixed == FALSE); /* Check the categories and scheme inheritance */ _categories = gdata_app_categories_get_categories (categories); g_assert_cmpint (g_list_length (_categories), ==, 2); g_assert (GDATA_IS_CATEGORY (_categories->data)); g_assert_cmpstr (gdata_category_get_scheme (GDATA_CATEGORY (_categories->data)), ==, NULL); g_assert_cmpstr (gdata_category_get_label (GDATA_CATEGORY (_categories->data)), ==, "Film & Animation"); g_assert (GDATA_IS_CATEGORY (_categories->next->data)); g_assert_cmpstr (gdata_category_get_scheme (GDATA_CATEGORY (_categories->next->data)), ==, NULL); g_assert_cmpstr (gdata_category_get_label (GDATA_CATEGORY (_categories->next->data)), ==, "Autos & Vehicles"); g_object_unref (categories); /* Now parse one with less information available */ categories = GDATA_APP_CATEGORIES (gdata_parsable_new_from_json (GDATA_TYPE_APP_CATEGORIES, "{" "'kind': 'youtube#videoCategoryListResponse'," "'items': []" "}", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_APP_CATEGORIES (categories)); g_clear_error (&error); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (categories)); g_assert_cmpstr (content_type, ==, "application/json"); /* Check the properties */ g_assert (gdata_app_categories_is_fixed (categories) == FALSE); g_object_unref (categories); } static void test_gd_email_address (void) { GDataGDEmailAddress *email, *email2; GError *error = NULL; const gchar *content_type; email = GDATA_GD_EMAIL_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_EMAIL_ADDRESS, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_EMAIL_ADDRESS (email)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_email_address_get_address (email), ==, "fubar@gmail.com"); g_assert_cmpstr (gdata_gd_email_address_get_relation_type (email), ==, GDATA_GD_EMAIL_ADDRESS_HOME); g_assert_cmpstr (gdata_gd_email_address_get_label (email), ==, "Personal & Private"); g_assert_cmpstr (gdata_gd_email_address_get_display_name (email), ==, ""); g_assert (gdata_gd_email_address_is_primary (email) == TRUE); /* Compare it against another identical address */ email2 = gdata_gd_email_address_new ("fubar@gmail.com", GDATA_GD_EMAIL_ADDRESS_HOME, "Personal & Private", TRUE); gdata_gd_email_address_set_display_name (email2, ""); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (email), GDATA_COMPARABLE (email2)), ==, 0); /* …and a different one */ gdata_gd_email_address_set_address (email2, "test@example.com"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (email), GDATA_COMPARABLE (email2)), !=, 0); g_object_unref (email2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (email)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (email, "" ""); g_object_unref (email); /* Now parse an address with less information available */ email = GDATA_GD_EMAIL_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_EMAIL_ADDRESS, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_EMAIL_ADDRESS (email)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_email_address_get_address (email), ==, "test@example.com"); g_assert (gdata_gd_email_address_get_relation_type (email) == NULL); g_assert (gdata_gd_email_address_get_label (email) == NULL); g_assert (gdata_gd_email_address_get_display_name (email) == NULL); g_assert (gdata_gd_email_address_is_primary (email) == FALSE); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (email)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (email, "" ""); g_object_unref (email); } static void test_gd_email_address_escaping (void) { GDataGDEmailAddress *email; g_test_bug ("630350"); email = gdata_gd_email_address_new ("Fubar ", GDATA_GD_EMAIL_ADDRESS_HOME "?foo&bar", "Personal & Private", TRUE); gdata_gd_email_address_set_display_name (email, ""); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (email, "" ""); g_object_unref (email); } static void test_gd_email_address_comparison (void) { GDataGDEmailAddress *email1, *email2; /* Should only compare equal if addresses are equal. */ email1 = gdata_gd_email_address_new ("foo@example.com", NULL, NULL, TRUE); email2 = gdata_gd_email_address_new ("foo@example.com", NULL, "label", FALSE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (email1), GDATA_COMPARABLE (email2)), ==, 0); gdata_gd_email_address_set_address (email1, "bar@example.com"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (email1), GDATA_COMPARABLE (email2)), !=, 0); g_object_unref (email2); g_object_unref (email1); } static void test_gd_im_address (void) { GDataGDIMAddress *im, *im2; GError *error = NULL; const gchar *content_type; im = GDATA_GD_IM_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_IM_ADDRESS, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_IM_ADDRESS (im)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_im_address_get_address (im), ==, "foo@bar.msn.com"); g_assert_cmpstr (gdata_gd_im_address_get_protocol (im), ==, GDATA_GD_IM_PROTOCOL_LIVE_MESSENGER); g_assert_cmpstr (gdata_gd_im_address_get_relation_type (im), ==, GDATA_GD_IM_ADDRESS_HOME); g_assert (gdata_gd_im_address_get_label (im) == NULL); g_assert (gdata_gd_im_address_is_primary (im) == TRUE); /* Compare it against another identical address */ im2 = gdata_gd_im_address_new ("foo@bar.msn.com", GDATA_GD_IM_PROTOCOL_LIVE_MESSENGER, GDATA_GD_IM_ADDRESS_HOME, NULL, TRUE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (im), GDATA_COMPARABLE (im2)), ==, 0); /* …and a different one */ gdata_gd_im_address_set_protocol (im2, GDATA_GD_IM_PROTOCOL_GOOGLE_TALK); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (im), GDATA_COMPARABLE (im2)), !=, 0); g_object_unref (im2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (im)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (im, "" ""); g_object_unref (im); /* Now parse an address with less information available */ im = GDATA_GD_IM_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_IM_ADDRESS, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_IM_ADDRESS (im)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_im_address_get_address (im), ==, "foo@baz.example.com"); g_assert (gdata_gd_im_address_get_protocol (im) == NULL); g_assert (gdata_gd_im_address_get_relation_type (im) == NULL); g_assert_cmpstr (gdata_gd_im_address_get_label (im), ==, "Other & Miscellaneous"); g_assert (gdata_gd_im_address_is_primary (im) == FALSE); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (im)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (im, "" ""); g_object_unref (im); } static void test_gd_im_address_escaping (void) { GDataGDIMAddress *im; im = gdata_gd_im_address_new ("Fubar ", GDATA_GD_IM_PROTOCOL_GOOGLE_TALK "?foo&bar", GDATA_GD_IM_ADDRESS_HOME "?foo&bar", "Personal & Private", TRUE); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (im, "" ""); g_object_unref (im); } static void test_gd_im_address_comparison (void) { GDataGDIMAddress *im_address1, *im_address2; /* Should only compare equal if address and protocol are both equal. */ im_address1 = gdata_gd_im_address_new ("foo@example.com", GDATA_GD_IM_PROTOCOL_LIVE_MESSENGER, NULL, NULL, TRUE); im_address2 = gdata_gd_im_address_new ("foo@example.com", GDATA_GD_IM_PROTOCOL_LIVE_MESSENGER, NULL, "label", FALSE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (im_address1), GDATA_COMPARABLE (im_address2)), ==, 0); /* Different addresses, same protocol. */ gdata_gd_im_address_set_address (im_address1, "bar@example.com"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (im_address1), GDATA_COMPARABLE (im_address2)), !=, 0); /* Same address, different protocols. */ gdata_gd_im_address_set_address (im_address1, "foo@example.com"); gdata_gd_im_address_set_protocol (im_address1, GDATA_GD_IM_PROTOCOL_JABBER); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (im_address1), GDATA_COMPARABLE (im_address2)), !=, 0); g_object_unref (im_address2); g_object_unref (im_address1); } static void test_gd_name (void) { GDataGDName *name, *name2; GError *error = NULL; const gchar *content_type; name = GDATA_GD_NAME (gdata_parsable_new_from_xml (GDATA_TYPE_GD_NAME, "" "Brian" "Charles" "Blessed" "Mr" "ABC" "Mr Brian Charles Blessed, ABC" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_NAME (name)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_name_get_given_name (name), ==, "Brian"); g_assert_cmpstr (gdata_gd_name_get_additional_name (name), ==, "Charles"); g_assert_cmpstr (gdata_gd_name_get_family_name (name), ==, "Blessed"); g_assert_cmpstr (gdata_gd_name_get_prefix (name), ==, "Mr"); g_assert_cmpstr (gdata_gd_name_get_suffix (name), ==, "ABC"); g_assert_cmpstr (gdata_gd_name_get_full_name (name), ==, "Mr Brian Charles Blessed, ABC"); /* Compare it against another identical name */ name2 = gdata_gd_name_new ("Brian", "Blessed"); gdata_gd_name_set_additional_name (name2, "Charles"); gdata_gd_name_set_prefix (name2, "Mr"); gdata_gd_name_set_suffix (name2, "ABC"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (name), GDATA_COMPARABLE (name2)), ==, 0); /* …and a different one */ gdata_gd_name_set_prefix (name2, "Mrs"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (name), GDATA_COMPARABLE (name2)), !=, 0); g_object_unref (name2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (name)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (name, "" "" "Brian" "Charles" "Blessed" "Mr" "ABC" "Mr Brian Charles Blessed, ABC" ""); g_object_unref (name); /* Now parse an address with less information available */ name = GDATA_GD_NAME (gdata_parsable_new_from_xml (GDATA_TYPE_GD_NAME, "Bob", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_NAME (name)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_name_get_given_name (name), ==, "Bob"); g_assert (gdata_gd_name_get_additional_name (name) == NULL); g_assert (gdata_gd_name_get_family_name (name) == NULL); g_assert (gdata_gd_name_get_prefix (name) == NULL); g_assert (gdata_gd_name_get_suffix (name) == NULL); g_assert (gdata_gd_name_get_full_name (name) == NULL); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (name)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is still correct */ gdata_test_assert_xml (name, "" "" "Bob" ""); g_object_unref (name); } static void test_gd_name_empty_strings (void) { GDataGDName *name; GError *error = NULL; g_test_bug ("662290"); /* Test that empty full names get treated as NULL correctly. */ name = GDATA_GD_NAME (gdata_parsable_new_from_xml (GDATA_TYPE_GD_NAME, "" "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_NAME (name)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_name_get_given_name (name), ==, NULL); g_assert_cmpstr (gdata_gd_name_get_additional_name (name), ==, NULL); g_assert_cmpstr (gdata_gd_name_get_family_name (name), ==, NULL); g_assert_cmpstr (gdata_gd_name_get_prefix (name), ==, NULL); g_assert_cmpstr (gdata_gd_name_get_suffix (name), ==, NULL); g_assert_cmpstr (gdata_gd_name_get_full_name (name), ==, NULL); g_object_unref (name); /* Build a name with an empty string full name and check the serialisation */ name = gdata_gd_name_new ("Georgey", "Porgey"); gdata_gd_name_set_full_name (name, ""); g_assert_cmpstr (gdata_gd_name_get_full_name (name), ==, NULL); /* Check the outputted XML is the same */ gdata_test_assert_xml (name, "" "" "Georgey" "Porgey" ""); g_object_unref (name); } static void test_gd_name_comparison (void) { GDataGDName *name1, *name2; /* Names are only equal if the given, additional and family names are all equal, and the prefixes are equal too. */ name1 = gdata_gd_name_new ("Given", "Family"); gdata_gd_name_set_additional_name (name1, "Additional"); gdata_gd_name_set_prefix (name1, "Mrs"); name2 = gdata_gd_name_new ("Given", "Family"); gdata_gd_name_set_additional_name (name2, "Additional"); gdata_gd_name_set_prefix (name2, "Mrs"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (name1), GDATA_COMPARABLE (name2)), ==, 0); /* Different given names. */ gdata_gd_name_set_given_name (name1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (name1), GDATA_COMPARABLE (name2)), !=, 0); /* Different additional names. */ gdata_gd_name_set_given_name (name1, "Given"); gdata_gd_name_set_additional_name (name1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (name1), GDATA_COMPARABLE (name2)), !=, 0); /* Different family names. */ gdata_gd_name_set_additional_name (name1, "Additional"); gdata_gd_name_set_family_name (name1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (name1), GDATA_COMPARABLE (name2)), !=, 0); /* Different prefixes. */ gdata_gd_name_set_family_name (name1, "Family"); gdata_gd_name_set_prefix (name1, "Mr"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (name1), GDATA_COMPARABLE (name2)), !=, 0); g_object_unref (name2); g_object_unref (name1); } static void test_gd_organization (void) { GDataGDOrganization *org, *org2; GDataGDWhere *location; GError *error = NULL; const gchar *content_type; org = GDATA_GD_ORGANIZATION (gdata_parsable_new_from_xml (GDATA_TYPE_GD_ORGANIZATION, "" "Google, Inc." "<Angle Bracketeer>" "Finance" "Doing stuff." "FOO" "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_ORGANIZATION (org)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_organization_get_name (org), ==, "Google, Inc."); g_assert_cmpstr (gdata_gd_organization_get_title (org), ==, ""); g_assert_cmpstr (gdata_gd_organization_get_relation_type (org), ==, GDATA_GD_ORGANIZATION_WORK); g_assert_cmpstr (gdata_gd_organization_get_label (org), ==, "Work & Occupation"); g_assert_cmpstr (gdata_gd_organization_get_department (org), ==, "Finance"); g_assert_cmpstr (gdata_gd_organization_get_job_description (org), ==, "Doing stuff."); g_assert_cmpstr (gdata_gd_organization_get_symbol (org), ==, "FOO"); location = gdata_gd_organization_get_location (org); g_assert (GDATA_IS_GD_WHERE (location)); g_assert (gdata_gd_organization_is_primary (org) == TRUE); /* Compare it against another identical organization */ org2 = gdata_gd_organization_new ("Google, Inc.", "", GDATA_GD_ORGANIZATION_WORK, "Work & Occupation", TRUE); gdata_gd_organization_set_department (org2, "Finance"); gdata_gd_organization_set_location (org2, location); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (org), GDATA_COMPARABLE (org2)), ==, 0); /* …and a different one */ gdata_gd_organization_set_title (org2, "Demoted!"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (org), GDATA_COMPARABLE (org2)), !=, 0); g_object_unref (org2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (org)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (org, "" "" "Google, Inc." "<Angle Bracketeer>" "Finance" "Doing stuff." "FOO" "" ""); g_object_unref (org); /* Now parse an organization with less information available */ org = GDATA_GD_ORGANIZATION (gdata_parsable_new_from_xml (GDATA_TYPE_GD_ORGANIZATION, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_ORGANIZATION (org)); g_clear_error (&error); /* Check the properties */ g_assert (gdata_gd_organization_get_name (org) == NULL); g_assert (gdata_gd_organization_get_title (org) == NULL); g_assert (gdata_gd_organization_get_relation_type (org) == NULL); g_assert (gdata_gd_organization_get_label (org) == NULL); g_assert (gdata_gd_organization_is_primary (org) == FALSE); g_assert (gdata_gd_organization_get_department (org) == NULL); g_assert (gdata_gd_organization_get_job_description (org) == NULL); g_assert (gdata_gd_organization_get_symbol (org) == NULL); g_assert (gdata_gd_organization_get_location (org) == NULL); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (org)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (org, "" ""); g_object_unref (org); } static void test_gd_organization_escaping (void) { GDataGDOrganization *org; org = gdata_gd_organization_new ("Steptoe & Son", "Title & Stuff", GDATA_GD_ORGANIZATION_WORK "?foo&bar", "Personal & Private", TRUE); gdata_gd_organization_set_department (org, "Department & Stuff"); gdata_gd_organization_set_job_description (org, "Escaping ."); gdata_gd_organization_set_symbol (org, "<&>"); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (org, "" "" "Steptoe & Son" "Title & Stuff" "Department & Stuff" "Escaping <brackets>." "<&>" ""); g_object_unref (org); } static void test_gd_organization_comparison (void) { GDataGDOrganization *org1, *org2; /* Organisation positions are equal if the name, title and department are all equal. */ org1 = gdata_gd_organization_new ("Name", "Title", NULL, NULL, TRUE); gdata_gd_organization_set_department (org1, "Department"); org2 = gdata_gd_organization_new ("Name", "Title", NULL, "label", FALSE); gdata_gd_organization_set_department (org2, "Department"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (org1), GDATA_COMPARABLE (org2)), ==, 0); /* Different name. */ gdata_gd_organization_set_name (org1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (org1), GDATA_COMPARABLE (org2)), !=, 0); /* Different title. */ gdata_gd_organization_set_name (org1, "Name"); gdata_gd_organization_set_title (org1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (org1), GDATA_COMPARABLE (org2)), !=, 0); /* Different department. */ gdata_gd_organization_set_title (org1, "Title"); gdata_gd_organization_set_department (org1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (org1), GDATA_COMPARABLE (org2)), !=, 0); g_object_unref (org2); g_object_unref (org1); } static void test_gd_phone_number (void) { GDataGDPhoneNumber *phone, *phone2; GError *error = NULL; const gchar *content_type; phone = GDATA_GD_PHONE_NUMBER (gdata_parsable_new_from_xml (GDATA_TYPE_GD_PHONE_NUMBER, "+1 206 555 1212", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_PHONE_NUMBER (phone)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_phone_number_get_number (phone), ==, "+1 206 555 1212"); g_assert_cmpstr (gdata_gd_phone_number_get_uri (phone), ==, "tel:+12065551212"); g_assert_cmpstr (gdata_gd_phone_number_get_relation_type (phone), ==, GDATA_GD_PHONE_NUMBER_MOBILE); g_assert_cmpstr (gdata_gd_phone_number_get_label (phone), ==, "Personal & business calls only"); g_assert (gdata_gd_phone_number_is_primary (phone) == FALSE); /* Compare it against another identical number */ phone2 = gdata_gd_phone_number_new ("+1 206 555 1212", GDATA_GD_PHONE_NUMBER_MOBILE, "Personal & business calls only", "tel:+12065551212", FALSE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone), GDATA_COMPARABLE (phone2)), ==, 0); /* …and a different one */ gdata_gd_phone_number_set_number (phone2, "+1 206 555 1212 666"); gdata_gd_phone_number_set_uri (phone2, NULL); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone), GDATA_COMPARABLE (phone2)), !=, 0); g_object_unref (phone2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (phone)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (phone, "" "+1 206 555 1212"); /* Check we trim whitespace properly, and respect Unicode characters */ gdata_gd_phone_number_set_number (phone, " 0123456 (789) ëxt 300 "); g_assert_cmpstr (gdata_gd_phone_number_get_number (phone), ==, "0123456 (789) ëxt 300"); g_object_unref (phone); /* Now parse a phone number with less information available, but some extraneous whitespace */ phone = GDATA_GD_PHONE_NUMBER (gdata_parsable_new_from_xml (GDATA_TYPE_GD_PHONE_NUMBER, " (425) 555-8080 ext. 72585 \n ", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_PHONE_NUMBER (phone)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_phone_number_get_number (phone), ==, "(425) 555-8080 ext. 72585"); g_assert (gdata_gd_phone_number_get_uri (phone) == NULL); g_assert (gdata_gd_phone_number_get_relation_type (phone) == NULL); g_assert (gdata_gd_phone_number_get_label (phone) == NULL); g_assert (gdata_gd_phone_number_is_primary (phone) == FALSE); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (phone)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (phone, "" "(425) 555-8080 ext. 72585"); g_object_unref (phone); } static void test_gd_phone_number_escaping (void) { GDataGDPhoneNumber *phone; phone = gdata_gd_phone_number_new ("0123456789 <54>", GDATA_GD_PHONE_NUMBER_WORK_MOBILE "?foo&bar", "Personal & Private", "tel:+012345678954?foo&bar", TRUE); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (phone, "" "0123456789 <54>"); g_object_unref (phone); } static void test_gd_phone_number_comparison (void) { GDataGDPhoneNumber *phone1, *phone2; /* Phone numbers are equal if the number or the URI matches (NULL URIs cannot match). */ phone1 = gdata_gd_phone_number_new ("123", NULL, NULL, "phone://123", TRUE); phone2 = gdata_gd_phone_number_new ("123", NULL, "label", "phone://123", FALSE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone1), GDATA_COMPARABLE (phone2)), ==, 0); /* Same numbers, different URIs. */ gdata_gd_phone_number_set_uri (phone1, "phone://+44123"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone1), GDATA_COMPARABLE (phone2)), ==, 0); /* Different numbers, same URIs. */ gdata_gd_phone_number_set_uri (phone1, "phone://123"); gdata_gd_phone_number_set_number (phone1, "+44123"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone1), GDATA_COMPARABLE (phone2)), ==, 0); /* Different numbers and URIs. */ gdata_gd_phone_number_set_number (phone1, "456"); gdata_gd_phone_number_set_uri (phone1, "phone://456"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone1), GDATA_COMPARABLE (phone2)), !=, 0); /* Different numbers, NULL URIs. */ gdata_gd_phone_number_set_uri (phone1, NULL); gdata_gd_phone_number_set_uri (phone2, NULL); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone1), GDATA_COMPARABLE (phone2)), !=, 0); /* Same numbers, NULL URIs. */ gdata_gd_phone_number_set_number (phone1, "123"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (phone1), GDATA_COMPARABLE (phone2)), ==, 0); g_object_unref (phone2); g_object_unref (phone1); } static void test_gd_postal_address (void) { GDataGDPostalAddress *postal, *postal2; GError *error = NULL; const gchar *content_type; postal = GDATA_GD_POSTAL_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_POSTAL_ADDRESS, "" "500 West 45th Street" "New York" "NY 10036" "United States" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_POSTAL_ADDRESS (postal)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_postal_address_get_street (postal), ==, "500 West 45th Street"); g_assert_cmpstr (gdata_gd_postal_address_get_city (postal), ==, "New York"); 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 */ postal2 = gdata_gd_postal_address_new (GDATA_GD_POSTAL_ADDRESS_HOME, "Home & Safe House", TRUE); 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 */ gdata_gd_postal_address_set_city (postal2, "Atlas Mountains"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (postal), GDATA_COMPARABLE (postal2)), !=, 0); g_object_unref (postal2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (postal)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (postal, "" "" "500 West 45th Street" "New York" "NY 10036" "United States" ""); /* Check we trim whitespace properly, and respect Unicode characters */ gdata_gd_postal_address_set_address (postal, " Schöne Grüße Straße\nGermany "); g_assert_cmpstr (gdata_gd_postal_address_get_address (postal), ==, "Schöne Grüße Straße\nGermany"); g_object_unref (postal); /* Now parse an address with less information available */ postal = GDATA_GD_POSTAL_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_POSTAL_ADDRESS, "f", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_POSTAL_ADDRESS (postal)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_postal_address_get_street (postal), ==, "f"); g_assert (gdata_gd_postal_address_get_relation_type (postal) == NULL); g_assert (gdata_gd_postal_address_get_label (postal) == NULL); g_assert (gdata_gd_postal_address_is_primary (postal) == FALSE); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (postal)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (postal, "" "" "f"); g_object_unref (postal); } static void test_gd_postal_address_escaping (void) { GDataGDPostalAddress *address; address = gdata_gd_postal_address_new (GDATA_GD_POSTAL_ADDRESS_WORK "?foo&bar", "Personal & Private", TRUE); gdata_gd_postal_address_set_address (address, "
"); gdata_gd_postal_address_set_mail_class (address, GDATA_GD_MAIL_CLASS_BOTH "?foo&bar"); gdata_gd_postal_address_set_usage (address, GDATA_GD_ADDRESS_USAGE_GENERAL "?foo&bar"); gdata_gd_postal_address_set_agent (address, ""); gdata_gd_postal_address_set_house_name (address, "House & House"); gdata_gd_postal_address_set_street (address, "Church & Main Street"); gdata_gd_postal_address_set_po_box (address, "<515>"); gdata_gd_postal_address_set_neighborhood (address, ""); gdata_gd_postal_address_set_city (address, "City <17>"); gdata_gd_postal_address_set_subregion (address, "Subregion <5>"); gdata_gd_postal_address_set_region (address, ""); gdata_gd_postal_address_set_postcode (address, "Postcode & stuff"); gdata_gd_postal_address_set_country (address, "", ""); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (address, "" "" "<agent>" "House & House" "Church & Main Street" "<515>" "<neighbourhood>" "City <17>" "Subregion <5>" "<region>" "Postcode & stuff" "<foo>" "<address>" ""); g_object_unref (address); } static void test_gd_postal_address_comparison (void) { GDataGDPostalAddress *address1, *address2; /* Postal addresses compare equal if the street, city, PO box and postcode are all equal. */ address1 = gdata_gd_postal_address_new (NULL, NULL, TRUE); gdata_gd_postal_address_set_street (address1, "Street"); gdata_gd_postal_address_set_city (address1, "City"); gdata_gd_postal_address_set_po_box (address1, "PO box"); gdata_gd_postal_address_set_postcode (address1, "Postcode"); address2 = gdata_gd_postal_address_new (NULL, "label", FALSE); gdata_gd_postal_address_set_street (address2, "Street"); gdata_gd_postal_address_set_city (address2, "City"); gdata_gd_postal_address_set_po_box (address2, "PO box"); gdata_gd_postal_address_set_postcode (address2, "Postcode"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (address1), GDATA_COMPARABLE (address2)), ==, 0); /* Different streets. */ gdata_gd_postal_address_set_street (address1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (address1), GDATA_COMPARABLE (address2)), !=, 0); /* Different cities. */ gdata_gd_postal_address_set_street (address1, "Street"); gdata_gd_postal_address_set_city (address1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (address1), GDATA_COMPARABLE (address2)), !=, 0); /* Different PO box. */ gdata_gd_postal_address_set_city (address1, "City"); gdata_gd_postal_address_set_po_box (address1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (address1), GDATA_COMPARABLE (address2)), !=, 0); /* Different postcode. */ gdata_gd_postal_address_set_po_box (address1, "PO box"); gdata_gd_postal_address_set_postcode (address1, "Different"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (address1), GDATA_COMPARABLE (address2)), !=, 0); g_object_unref (address2); g_object_unref (address1); } static void test_gd_reminder (void) { GDataGDReminder *reminder, *reminder2; gint64 _time; GError *error = NULL; const gchar *content_type; reminder = GDATA_GD_REMINDER (gdata_parsable_new_from_xml (GDATA_TYPE_GD_REMINDER, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_REMINDER (reminder)); g_clear_error (&error); /* Check the properties */ g_assert (gdata_gd_reminder_get_method (reminder) == NULL); g_assert (gdata_gd_reminder_is_absolute_time (reminder) == FALSE); g_assert_cmpint (gdata_gd_reminder_get_relative_time (reminder), ==, 15 * 24 * 60); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (reminder)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML */ gdata_test_assert_xml (reminder, "" ""); g_object_unref (reminder); /* Try again with a different property */ reminder = GDATA_GD_REMINDER (gdata_parsable_new_from_xml (GDATA_TYPE_GD_REMINDER, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_REMINDER (reminder)); g_clear_error (&error); /* Check the properties */ g_assert (gdata_gd_reminder_get_method (reminder) == NULL); g_assert (gdata_gd_reminder_is_absolute_time (reminder) == FALSE); g_assert_cmpint (gdata_gd_reminder_get_relative_time (reminder), ==, 15 * 60); /* Compare to another reminder */ reminder2 = gdata_gd_reminder_new (NULL, -1, 15 * 60); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (reminder), GDATA_COMPARABLE (reminder2)), ==, 0); g_object_unref (reminder2); g_object_unref (reminder); /* …and another */ reminder = GDATA_GD_REMINDER (gdata_parsable_new_from_xml (GDATA_TYPE_GD_REMINDER, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_REMINDER (reminder)); g_clear_error (&error); /* Check the properties */ g_assert (gdata_gd_reminder_get_method (reminder) == NULL); g_assert (gdata_gd_reminder_is_absolute_time (reminder) == FALSE); g_assert_cmpint (gdata_gd_reminder_get_relative_time (reminder), ==, 15); g_object_unref (reminder); /* Try again with an absolute time and a method */ reminder = GDATA_GD_REMINDER (gdata_parsable_new_from_xml (GDATA_TYPE_GD_REMINDER, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_REMINDER (reminder)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_reminder_get_method (reminder), ==, GDATA_GD_REMINDER_ALERT); g_assert (gdata_gd_reminder_is_absolute_time (reminder) == TRUE); _time = gdata_gd_reminder_get_absolute_time (reminder); g_assert_cmpint (_time, ==, 1118105700); /* Compare to another reminder */ reminder2 = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT, _time, -1); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (reminder), GDATA_COMPARABLE (reminder2)), ==, 0); g_object_unref (reminder2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (reminder)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML */ gdata_test_assert_xml (reminder, "" ""); g_object_unref (reminder); } static void test_gd_reminder_escaping (void) { GDataGDReminder *reminder; reminder = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT "?foo&bar", -1, 15); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (reminder, "" ""); g_object_unref (reminder); } static void test_gd_reminder_comparison (void) { GDataGDReminder *reminder1, *reminder2; #define ASSERT_COMPARISON(op) \ g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (reminder1), GDATA_COMPARABLE (reminder2)), op, 0) /* Check for equality. */ reminder1 = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT, -1, 15); reminder2 = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT, -1, 15); ASSERT_COMPARISON(==); /* Different methods, same time type, same time. */ gdata_gd_reminder_set_method (reminder1, GDATA_GD_REMINDER_SMS); ASSERT_COMPARISON(>); /* Same method, different time type, same time. */ gdata_gd_reminder_set_method (reminder1, GDATA_GD_REMINDER_ALERT); gdata_gd_reminder_set_relative_time (reminder1, -1); gdata_gd_reminder_set_absolute_time (reminder1, 5); ASSERT_COMPARISON(>); /* Same method, same time type, different time. */ gdata_gd_reminder_set_absolute_time (reminder1, -1); gdata_gd_reminder_set_relative_time (reminder1, 20); ASSERT_COMPARISON(>); g_object_unref (reminder2); g_object_unref (reminder1); #undef ASSERT_COMPARISON } static void test_gd_when (void) { GDataGDWhen *when, *when2; GDataGDReminder *reminder; GList *reminders; gint64 _time, _time2; GError *error = NULL; const gchar *content_type; when = GDATA_GD_WHEN (gdata_parsable_new_from_xml (GDATA_TYPE_GD_WHEN, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_WHEN (when)); g_clear_error (&error); /* Check the properties */ _time = gdata_gd_when_get_start_time (when); g_assert_cmpint (_time, ==, 1118106000); _time2 = gdata_gd_when_get_end_time (when); g_assert_cmpint (_time2, ==, 1118109600); g_assert (gdata_gd_when_is_date (when) == FALSE); g_assert (gdata_gd_when_get_value_string (when) == NULL); g_assert (gdata_gd_when_get_reminders (when) == NULL); /* Compare it against another identical time */ when2 = gdata_gd_when_new (_time, _time2, FALSE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (when), GDATA_COMPARABLE (when2)), ==, 0); /* …and a different one */ _time2 = 100; gdata_gd_when_set_end_time (when2, _time2); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (when), GDATA_COMPARABLE (when2)), !=, 0); g_object_unref (when2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (when)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (when, "" ""); g_object_unref (when); /* Now parse a time with different information */ when = GDATA_GD_WHEN (gdata_parsable_new_from_xml (GDATA_TYPE_GD_WHEN, "" "" "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_WHEN (when)); g_clear_error (&error); /* Check the properties */ _time = gdata_gd_when_get_start_time (when); g_assert_cmpint (_time, ==, 1118016000); _time2 = gdata_gd_when_get_end_time (when); g_assert_cmpint (_time2, ==, 1118188800); g_assert (gdata_gd_when_is_date (when) == TRUE); g_assert_cmpstr (gdata_gd_when_get_value_string (when), ==, "This weekend"); reminders = gdata_gd_when_get_reminders (when); g_assert (reminders != NULL); g_assert (GDATA_IS_GD_REMINDER (reminders->data)); g_assert (reminders->next == NULL); g_assert (gdata_gd_reminder_is_absolute_time (GDATA_GD_REMINDER (reminders->data)) == FALSE); g_assert_cmpint (gdata_gd_reminder_get_relative_time (GDATA_GD_REMINDER (reminders->data)), ==, 15); /* Add another reminder */ reminder = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT, _time, -1); gdata_gd_when_add_reminder (when, reminder); g_object_unref (reminder); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (when)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is correct */ gdata_test_assert_xml (when, "" "" "" "" "" ""); g_object_unref (when); } static void test_gd_when_escaping (void) { GDataGDWhen *when; GTimeVal start_time; g_time_val_from_iso8601 ("2005-06-07T01:00:00Z", &start_time); when = gdata_gd_when_new (start_time.tv_sec, -1, FALSE); gdata_gd_when_set_value_string (when, "Value string & stuff!"); /* Check the outputted XML is escaped properly */ gdata_test_assert_xml (when, "" ""); g_object_unref (when); } static void test_gd_when_comparison (void) { GDataGDWhen *when1, *when2; /* Whens are non-equal if one is a date and the other isn't, if their start times differ, or if their end times differ. */ when1 = gdata_gd_when_new (0, 1000, FALSE); when2 = gdata_gd_when_new (0, 1000, FALSE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (when1), GDATA_COMPARABLE (when2)), ==, 0); /* Different date/time type. */ gdata_gd_when_set_is_date (when1, TRUE); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (when1), GDATA_COMPARABLE (when2)), !=, 0); /* Different start time. */ gdata_gd_when_set_is_date (when1, FALSE); gdata_gd_when_set_start_time (when1, 500); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (when1), GDATA_COMPARABLE (when2)), !=, 0); /* Different end time. */ gdata_gd_when_set_start_time (when1, 0); gdata_gd_when_set_end_time (when1, 15000); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (when1), GDATA_COMPARABLE (when2)), !=, 0); g_object_unref (when2); g_object_unref (when1); } static void test_gd_where (void) { GDataGDWhere *where, *where2; GError *error = NULL; const gchar *content_type; where = GDATA_GD_WHERE (gdata_parsable_new_from_xml (GDATA_TYPE_GD_WHERE, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_WHERE (where)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_where_get_relation_type (where), ==, GDATA_GD_WHERE_EVENT_ALTERNATE); g_assert_cmpstr (gdata_gd_where_get_value_string (where), ==, "Metropolis"); g_assert_cmpstr (gdata_gd_where_get_label (where), ==, "New York Location "); /* Compare it against another identical place */ where2 = gdata_gd_where_new (GDATA_GD_WHERE_EVENT_ALTERNATE, "Metropolis", "New York Location "); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (where), GDATA_COMPARABLE (where2)), ==, 0); /* …and a different one */ gdata_gd_where_set_label (where2, "Atlas Mountains"); g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (where), GDATA_COMPARABLE (where2)), !=, 0); g_object_unref (where2); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (where)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML is the same */ gdata_test_assert_xml (where, "" ""); g_object_unref (where); /* Now parse a place with less information available */ where = GDATA_GD_WHERE (gdata_parsable_new_from_xml (GDATA_TYPE_GD_WHERE, "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_GD_WHERE (where)); g_clear_error (&error); /* Check the properties */ g_assert_cmpstr (gdata_gd_where_get_value_string (where), ==, "Google Cafeteria "); g_assert (gdata_gd_where_get_relation_type (where) == NULL); g_assert (gdata_gd_where_get_label (where) == NULL); content_type = gdata_parsable_get_content_type (GDATA_PARSABLE (where)); g_assert_cmpstr (content_type, ==, "application/atom+xml"); /* Check the outputted XML contains the unknown XML */ gdata_test_assert_xml (where, "" ""); g_object_unref (where); } static void test_gd_where_escaping (void) { GDataGDWhere *where; where = gdata_gd_where_new (GDATA_GD_WHERE_EVENT "?foo&bar", "Value string & stuff!", "