~ubuntu-branches/ubuntu/natty/libgdata/natty-updates

« back to all changes in this revision

Viewing changes to gdata/tests/general.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2011-01-05 11:09:00 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110105110900-gkjnbslnr18s45us
Tags: 0.8.0-0ubuntu1
* New upstream release
* debian/control:
  - Use gir1.2 packages
  - Use standards version 3.9.1
  - Add Vcs-Bzr link
  - Rename libgdata10 to libgdata11
* debian/rules:
  - Drop simple-patchsys.mk
* debian/source:
  - Use source version 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "common.h"
25
25
 
26
26
static void
 
27
test_xml_comparison (void)
 
28
{
 
29
        GDataAccessRule *rule;
 
30
 
 
31
        /* 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
 
32
         * blindly assert that its results are correct. */
 
33
        rule = gdata_access_rule_new ("an-id");
 
34
        gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE);
 
35
        gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "foo@example.com");
 
36
 
 
37
        /* Check a valid comparison */
 
38
        gdata_test_assert_xml (rule,
 
39
                "<?xml version='1.0' encoding='UTF-8'?>"
 
40
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
41
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
42
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
43
                        "<title type='text'>none</title>"
 
44
                        "<id>an-id</id>"
 
45
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
46
                        "<gAcl:role value='none'/>"
 
47
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
48
                "</entry>");
 
49
 
 
50
        /* Check a valid comparison with namespaces swapped */
 
51
        gdata_test_assert_xml (rule,
 
52
                "<?xml version='1.0' encoding='UTF-8'?>"
 
53
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
54
                       "xmlns:gAcl='http://schemas.google.com/acl/2007' "
 
55
                       "xmlns:gd='http://schemas.google.com/g/2005'>"
 
56
                        "<title type='text'>none</title>"
 
57
                        "<id>an-id</id>"
 
58
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
59
                        "<gAcl:role value='none'/>"
 
60
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
61
                "</entry>");
 
62
 
 
63
        /* Check a valid comparison with elements swapped */
 
64
        gdata_test_assert_xml (rule,
 
65
                "<?xml version='1.0' encoding='UTF-8'?>"
 
66
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
67
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
68
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
69
                        "<id>an-id</id>"
 
70
                        "<title type='text'>none</title>"
 
71
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
72
                        "<gAcl:role value='none'/>"
 
73
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
74
                "</entry>");
 
75
 
 
76
        /* Missing namespace (still valid XML, just not what's expected) */
 
77
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
78
                "<?xml version='1.0' encoding='UTF-8'?>"
 
79
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
80
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
81
                        "<title type='text'>none</title>"
 
82
                        "<id>an-id</id>"
 
83
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
84
                        "<gAcl:role value='none'/>"
 
85
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
86
                "</entry>", FALSE) == FALSE);
 
87
 
 
88
        /* Extra namespace */
 
89
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
90
                "<?xml version='1.0' encoding='UTF-8'?>"
 
91
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
92
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
93
                       "xmlns:gAcl='http://schemas.google.com/acl/2007' "
 
94
                       "xmlns:foo='http://foo.com/'>"
 
95
                        "<title type='text'>none</title>"
 
96
                        "<id>an-id</id>"
 
97
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
98
                        "<gAcl:role value='none'/>"
 
99
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
100
                "</entry>", FALSE) == FALSE);
 
101
 
 
102
        /* Missing element */
 
103
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
104
                "<?xml version='1.0' encoding='UTF-8'?>"
 
105
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
106
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
107
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
108
                        "<id>an-id</id>"
 
109
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
110
                        "<gAcl:role value='none'/>"
 
111
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
112
                "</entry>", FALSE) == FALSE);
 
113
 
 
114
        /* Extra element */
 
115
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
116
                "<?xml version='1.0' encoding='UTF-8'?>"
 
117
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
118
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
119
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
120
                        "<title type='text'>none</title>"
 
121
                        "<foo>bar</foo>"
 
122
                        "<id>an-id</id>"
 
123
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
124
                        "<gAcl:role value='none'/>"
 
125
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
126
                "</entry>", FALSE) == FALSE);
 
127
 
 
128
        /* Incorrect namespace on element */
 
129
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
130
                "<?xml version='1.0' encoding='UTF-8'?>"
 
131
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
132
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
133
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
134
                        "<gAcl:title type='text'>none</gAcl:title>"
 
135
                        "<id>an-id</id>"
 
136
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
137
                        "<gAcl:role value='none'/>"
 
138
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
139
                "</entry>", FALSE) == FALSE);
 
140
 
 
141
        /* Mis-valued content */
 
142
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
143
                "<?xml version='1.0' encoding='UTF-8'?>"
 
144
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
145
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
146
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
147
                        "<title type='text'>none</title>"
 
148
                        "<id>an-other-id</id>"
 
149
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
150
                        "<gAcl:role value='none'/>"
 
151
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
152
                "</entry>", FALSE) == FALSE);
 
153
 
 
154
        /* Missing attribute */
 
155
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
156
                "<?xml version='1.0' encoding='UTF-8'?>"
 
157
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
158
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
159
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
160
                        "<title type='text'>none</title>"
 
161
                        "<id>an-id</id>"
 
162
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
163
                        "<gAcl:role/>"
 
164
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
165
                "</entry>", FALSE) == FALSE);
 
166
 
 
167
        /* Extra attribute */
 
168
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
169
                "<?xml version='1.0' encoding='UTF-8'?>"
 
170
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
171
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
172
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
173
                        "<title type='text'>none</title>"
 
174
                        "<id>an-id</id>"
 
175
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
176
                        "<gAcl:role value='none' other-value='foo'/>"
 
177
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
178
                "</entry>", FALSE) == FALSE);
 
179
 
 
180
        /* Mis-valued attribute */
 
181
        g_assert (gdata_test_compare_xml (GDATA_PARSABLE (rule),
 
182
                "<?xml version='1.0' encoding='UTF-8'?>"
 
183
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
184
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
185
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
186
                        "<title type='text'>none</title>"
 
187
                        "<id>an-id</id>"
 
188
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
189
                        "<gAcl:role value='other'/>"
 
190
                        "<gAcl:scope type='user' value='foo@example.com'/>"
 
191
                "</entry>", FALSE) == FALSE);
 
192
 
 
193
        g_object_unref (rule);
 
194
}
 
195
 
 
196
static void
27
197
test_entry_get_xml (void)
28
198
{
29
199
        gint64 updated, published, updated2, published2, updated3, published3;
67
237
        gdata_entry_set_content_uri (entry, "http://bar.com/");
68
238
 
69
239
        /* Check the generated XML's OK */
70
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
71
 
        g_assert_cmpstr (xml, ==,
 
240
        gdata_test_assert_xml (entry,
72
241
                         "<?xml version='1.0' encoding='UTF-8'?>"
73
242
                         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>"
74
243
                                 "<title type='text'>Testing title &amp; escaping</title>"
75
244
                                 "<content type='text/plain' src='http://bar.com/'/>"
76
245
                         "</entry>");
77
 
        g_free (xml);
78
246
 
79
247
        /* Reset the content */
80
248
        gdata_entry_set_content (entry, "This is some sample content testing, amongst other things, <markup> & odd characters‽");
124
292
        g_object_unref (author);
125
293
 
126
294
        /* Check the generated XML's OK */
127
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
128
 
        g_assert_cmpstr (xml, ==,
 
295
        gdata_test_assert_xml (entry,
129
296
                         "<?xml version='1.0' encoding='UTF-8'?>"
130
297
                         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>"
131
298
                                 "<title type='text'>Testing title &amp; escaping</title>"
144
311
                         "</entry>");
145
312
 
146
313
        /* Check again by re-parsing the XML to a GDataEntry */
 
314
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
147
315
        entry2 = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, xml, -1, &error));
148
316
        g_assert_no_error (error);
149
317
        g_assert (GDATA_IS_ENTRY (entry2));
291
459
test_entry_parse_xml (void)
292
460
{
293
461
        GDataEntry *entry;
294
 
        gchar *xml;
295
462
        GError *error = NULL;
296
463
 
297
464
        /* Create an entry from XML with unhandled elements */
310
477
        g_clear_error (&error);
311
478
 
312
479
        /* Now check the outputted XML from the entry still has the unhandled elements */
313
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
314
 
        g_assert_cmpstr (xml, ==,
 
480
        gdata_test_assert_xml (entry,
315
481
                         "<?xml version='1.0' encoding='UTF-8'?>"
316
482
                         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:ns='http://example.com/'>"
317
483
                                "<title type='text'>Testing unhandled XML</title>"
322
488
                                "<barfoo shizzle=\"zing\"/>"
323
489
                                "<ns:barfoo shizzle=\"zing\" fo=\"shizzle\">How about some characters‽</ns:barfoo>"
324
490
                         "</entry>");
325
 
        g_free (xml);
326
491
        g_object_unref (entry);
327
492
}
328
493
 
359
524
}
360
525
 
361
526
static void
 
527
test_entry_escaping (void)
 
528
{
 
529
        GDataEntry *entry;
 
530
        GError *error = NULL;
 
531
 
 
532
        /* Since we can't construct a GDataEntry directly, we need to parse it from XML */
 
533
        entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY,
 
534
                "<?xml version='1.0' encoding='UTF-8'?>"
 
535
                "<entry xmlns='http://www.w3.org/2005/Atom'>"
 
536
                        "<title type='text'>Escaped content &amp; stuff</title>"
 
537
                        "<id>http://foo.com/?foo&amp;bar</id>"
 
538
                        "<updated>2010-12-10T17:21:24Z</updated>"
 
539
                        "<published>2010-12-10T17:21:24Z</published>"
 
540
                        "<summary type='text'>Summary &amp; stuff</summary>"
 
541
                        "<rights>Free &amp; open source</rights>"
 
542
                        "<content type='text'>Content &amp; things.</content>"
 
543
                "</entry>", -1, &error));
 
544
        g_assert_no_error (error);
 
545
        g_assert (GDATA_IS_ENTRY (entry));
 
546
 
 
547
        /* Check the outputted XML is escaped properly */
 
548
        gdata_test_assert_xml (entry,
 
549
                "<?xml version='1.0' encoding='UTF-8'?>"
 
550
                "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>"
 
551
                        "<title type='text'>Escaped content &amp; stuff</title>"
 
552
                        "<id>http://foo.com/?foo&amp;bar</id>"
 
553
                        "<updated>2010-12-10T17:21:24Z</updated>"
 
554
                        "<published>2010-12-10T17:21:24Z</published>"
 
555
                        "<summary type='text'>Summary &amp; stuff</summary>"
 
556
                        "<rights>Free &amp; open source</rights>"
 
557
                        "<content type='text'>Content &amp; things.</content>"
 
558
                "</entry>");
 
559
        g_object_unref (entry);
 
560
 
 
561
        /* Repeat with content given by a URI */
 
562
        entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY,
 
563
                "<?xml version='1.0' encoding='UTF-8'?>"
 
564
                "<entry xmlns='http://www.w3.org/2005/Atom'>"
 
565
                        "<title type='text'>Escaped content &amp; stuff</title>"
 
566
                        "<content type='text/plain' src='http://foo.com?foo&amp;bar'/>"
 
567
                "</entry>", -1, &error));
 
568
        g_assert_no_error (error);
 
569
        g_assert (GDATA_IS_ENTRY (entry));
 
570
 
 
571
        /* Check the outputted XML is escaped properly */
 
572
        gdata_test_assert_xml (entry,
 
573
                "<?xml version='1.0' encoding='UTF-8'?>"
 
574
                "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>"
 
575
                        "<title type='text'>Escaped content &amp; stuff</title>"
 
576
                        "<content type='text/plain' src='http://foo.com?foo&amp;bar'/>"
 
577
                "</entry>");
 
578
        g_object_unref (entry);
 
579
}
 
580
 
 
581
static void
362
582
test_feed_parse_xml (void)
363
583
{
364
584
        GDataFeed *feed;
608
828
}
609
829
 
610
830
static void
 
831
test_feed_escaping (void)
 
832
{
 
833
        GDataFeed *feed;
 
834
        GError *error = NULL;
 
835
 
 
836
        /* Since we can't construct a GDataEntry directly, we need to parse it from XML */
 
837
        feed = GDATA_FEED (gdata_parsable_new_from_xml (GDATA_TYPE_FEED,
 
838
                "<?xml version='1.0' encoding='UTF-8'?>"
 
839
                "<feed xmlns='http://www.w3.org/2005/Atom'>"
 
840
                        "<id>http://foo.com?foo&amp;bar</id>"
 
841
                        "<updated>2010-12-10T17:49:15Z</updated>"
 
842
                        "<title type='text'>Test feed &amp; stuff.</title>"
 
843
                "</feed>", -1, &error));
 
844
        g_assert_no_error (error);
 
845
        g_assert (GDATA_IS_FEED (feed));
 
846
 
 
847
        /* Check the outputted XML is escaped properly */
 
848
        gdata_test_assert_xml (feed,
 
849
                "<?xml version='1.0' encoding='UTF-8'?>"
 
850
                "<feed xmlns='http://www.w3.org/2005/Atom'>"
 
851
                        "<title type='text'>Test feed &amp; stuff.</title>"
 
852
                        "<id>http://foo.com?foo&amp;bar</id>"
 
853
                        "<updated>2010-12-10T17:49:15Z</updated>"
 
854
                "</feed>");
 
855
        g_object_unref (feed);
 
856
}
 
857
 
 
858
static void
611
859
test_query_categories (void)
612
860
{
613
861
        GDataQuery *query;
790
1038
        gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "foo@example.com");
791
1039
 
792
1040
        /* Check the generated XML's OK */
793
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (rule));
794
 
        g_assert_cmpstr (xml, ==,
 
1041
        gdata_test_assert_xml (rule,
795
1042
                         "<?xml version='1.0' encoding='UTF-8'?>"
796
1043
                         "<entry xmlns='http://www.w3.org/2005/Atom' "
797
1044
                         "xmlns:gd='http://schemas.google.com/g/2005' "
804
1051
                         "</entry>");
805
1052
 
806
1053
        /* Check again by re-parsing the XML to a GDataAccessRule */
 
1054
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (rule));
807
1055
        rule2 = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (GDATA_TYPE_ACCESS_RULE, xml, -1, &error));
808
1056
        g_assert_no_error (error);
809
1057
        g_assert (GDATA_IS_ACCESS_RULE (rule2));
873
1121
}
874
1122
 
875
1123
static void
 
1124
test_access_rule_escaping (void)
 
1125
{
 
1126
        GDataAccessRule *rule;
 
1127
 
 
1128
        rule = gdata_access_rule_new (NULL);
 
1129
        gdata_access_rule_set_role (rule, "<role>");
 
1130
        gdata_access_rule_set_scope (rule, "<scope>", "<value>");
 
1131
 
 
1132
        /* Check the outputted XML is escaped properly */
 
1133
        gdata_test_assert_xml (rule,
 
1134
                "<?xml version='1.0' encoding='UTF-8'?>"
 
1135
                "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
 
1136
                       "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
 
1137
                        "<title type='text'>&lt;role&gt;</title>"
 
1138
                        "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
 
1139
                        "<gAcl:role value='&lt;role&gt;'/>"
 
1140
                        "<gAcl:scope type='&lt;scope&gt;' value='&lt;value&gt;'/>"
 
1141
                "</entry>");
 
1142
        g_object_unref (rule);
 
1143
}
 
1144
 
 
1145
static void
876
1146
test_comparable (void)
877
1147
{
878
1148
        GDataComparable *category = GDATA_COMPARABLE (gdata_category_new ("term", "http://scheme", "label"));
955
1225
test_atom_author (void)
956
1226
{
957
1227
        GDataAuthor *author, *author2;
958
 
        gchar *xml, *name, *uri, *email_address;
 
1228
        gchar *name, *uri, *email_address;
959
1229
        GError *error = NULL;
960
1230
 
961
1231
        author = GDATA_AUTHOR (gdata_parsable_new_from_xml (GDATA_TYPE_AUTHOR,
984
1254
        g_object_unref (author2);
985
1255
 
986
1256
        /* Check the outputted XML is the same */
987
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (author));
988
 
        g_assert_cmpstr (xml, ==,
 
1257
        gdata_test_assert_xml (author,
989
1258
                         "<?xml version='1.0' encoding='UTF-8'?>"
990
1259
                         "<author xmlns='http://www.w3.org/2005/Atom'>"
991
1260
                                "<name>John Smöth</name>"
992
1261
                                "<uri>http://example.com/</uri>"
993
1262
                                "<email>john@example.com</email>"
994
1263
                         "</author>");
995
 
        g_free (xml);
996
1264
 
997
1265
        /* Check the properties */
998
1266
        g_object_get (G_OBJECT (author),
1056
1324
}
1057
1325
 
1058
1326
static void
 
1327
test_atom_author_escaping (void)
 
1328
{
 
1329
        GDataAuthor *author;
 
1330
 
 
1331
        author = gdata_author_new ("First & Last Name", "http://foo.com?foo&bar", "John Smith <john.smith@gmail.com>");
 
1332
 
 
1333
        /* Check the outputted XML is escaped properly */
 
1334
        gdata_test_assert_xml (author,
 
1335
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
1336
                         "<author xmlns='http://www.w3.org/2005/Atom'>"
 
1337
                                "<name>First &amp; Last Name</name>"
 
1338
                                "<uri>http://foo.com?foo&amp;bar</uri>"
 
1339
                                "<email>John Smith &lt;john.smith@gmail.com&gt;</email>"
 
1340
                         "</author>");
 
1341
        g_object_unref (author);
 
1342
}
 
1343
 
 
1344
static void
1059
1345
test_atom_category (void)
1060
1346
{
1061
1347
        GDataCategory *category, *category2;
1062
 
        gchar *xml, *term, *scheme, *label;
 
1348
        gchar *term, *scheme, *label;
1063
1349
        GError *error = NULL;
1064
1350
 
1065
1351
        category = GDATA_CATEGORY (gdata_parsable_new_from_xml (GDATA_TYPE_CATEGORY,
1084
1370
        g_object_unref (category2);
1085
1371
 
1086
1372
        /* Check the outputted XML is the same */
1087
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (category));
1088
 
        g_assert_cmpstr (xml, ==,
 
1373
        gdata_test_assert_xml (category,
1089
1374
                         "<?xml version='1.0' encoding='UTF-8'?>"
1090
1375
                         "<category xmlns='http://www.w3.org/2005/Atom' "
1091
1376
                                "term='jokes' scheme='http://foobar.com#categories' label='Jokes &amp; Trivia'/>");
1092
 
        g_free (xml);
1093
1377
 
1094
1378
        /* Check the properties */
1095
1379
        g_object_get (G_OBJECT (category),
1131
1415
        g_clear_error (&error);
1132
1416
 
1133
1417
        /* Check the outputted XML contains the unknown XML */
1134
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (category));
1135
 
        g_assert_cmpstr (xml, ==,
 
1418
        gdata_test_assert_xml (category,
1136
1419
                         "<?xml version='1.0' encoding='UTF-8'?>"
1137
1420
                         "<category xmlns='http://www.w3.org/2005/Atom' term='documentary'>"
1138
1421
                                "<foobar/>"
1139
1422
                                "<shizzle/>"
1140
1423
                         "</category>");
1141
 
        g_free (xml);
1142
1424
        g_object_unref (category);
1143
1425
}
1144
1426
 
1156
1438
}
1157
1439
 
1158
1440
static void
 
1441
test_atom_category_escaping (void)
 
1442
{
 
1443
        GDataCategory *category;
 
1444
 
 
1445
        category = gdata_category_new ("<term>", "http://foo.com?foo&bar", "Label & Stuff");
 
1446
 
 
1447
        /* Check the outputted XML is escaped properly */
 
1448
        gdata_test_assert_xml (category,
 
1449
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
1450
                         "<category xmlns='http://www.w3.org/2005/Atom' term='&lt;term&gt;' scheme='http://foo.com?foo&amp;bar' "
 
1451
                                "label='Label &amp; Stuff'/>");
 
1452
        g_object_unref (category);
 
1453
}
 
1454
 
 
1455
static void
1159
1456
test_atom_generator (void)
1160
1457
{
1161
1458
        GDataGenerator *generator, *generator2;
1234
1531
test_atom_link (void)
1235
1532
{
1236
1533
        GDataLink *link1, *link2;
1237
 
        gchar *xml, *uri, *relation_type, *content_type, *language, *title;
 
1534
        gchar *uri, *relation_type, *content_type, *language, *title;
1238
1535
        gint length;
1239
1536
        GError *error = NULL;
1240
1537
 
1268
1565
        g_object_unref (link2);
1269
1566
 
1270
1567
        /* Check the outputted XML is the same */
1271
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (link1));
1272
 
        g_assert_cmpstr (xml, ==,
 
1568
        gdata_test_assert_xml (link1,
1273
1569
                         "<?xml version='1.0' encoding='UTF-8'?>"
1274
1570
                         "<link xmlns='http://www.w3.org/2005/Atom' href='http://example.com/' title='All About Angle Brackets: &lt;, &gt;' "
1275
1571
                                "rel='http://test.com#link-type' type='text/plain' hreflang='de' length='2000'/>");
1276
 
        g_free (xml);
1277
1572
 
1278
1573
        /* Set some of the properties */
1279
1574
        g_object_set (G_OBJECT (link1),
1325
1620
        g_assert (gdata_link_get_length (link1) == -1);
1326
1621
 
1327
1622
        /* Check the outputted XML contains the unknown XML */
1328
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (link1));
1329
 
        g_assert_cmpstr (xml, ==,
 
1623
        gdata_test_assert_xml (link1,
1330
1624
                         "<?xml version='1.0' encoding='UTF-8'?>"
1331
1625
                         "<link xmlns='http://www.w3.org/2005/Atom' href='http://shizzle.com' rel='http://www.iana.org/assignments/relation/alternate'>"
1332
1626
                                "Test Content<foobar/></link>");
1333
 
        g_free (xml);
1334
1627
        g_object_unref (link1);
1335
1628
}
1336
1629
 
1363
1656
}
1364
1657
 
1365
1658
static void
 
1659
test_atom_link_escaping (void)
 
1660
{
 
1661
        GDataLink *_link;
 
1662
 
 
1663
        _link = gdata_link_new ("http://foo.com?foo&bar", "http://foo.com?foo&relation=bar");
 
1664
        gdata_link_set_content_type (_link, "<content type>");
 
1665
        gdata_link_set_language (_link, "<language>");
 
1666
        gdata_link_set_title (_link, "Title & stuff");
 
1667
 
 
1668
 
 
1669
        /* Check the outputted XML is escaped properly */
 
1670
        gdata_test_assert_xml (_link,
 
1671
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
1672
                         "<link xmlns='http://www.w3.org/2005/Atom' href='http://foo.com?foo&amp;bar' title='Title &amp; stuff' "
 
1673
                                "rel='http://foo.com?foo&amp;relation=bar' type='&lt;content type&gt;' hreflang='&lt;language&gt;'/>");
 
1674
        g_object_unref (_link);
 
1675
}
 
1676
 
 
1677
static void
1366
1678
test_app_categories (void)
1367
1679
{
1368
1680
        GDataAPPCategories *categories;
1414
1726
test_gd_email_address (void)
1415
1727
{
1416
1728
        GDataGDEmailAddress *email, *email2;
1417
 
        gchar *xml;
1418
1729
        GError *error = NULL;
1419
1730
 
1420
1731
        email = GDATA_GD_EMAIL_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_EMAIL_ADDRESS,
1442
1753
        g_object_unref (email2);
1443
1754
 
1444
1755
        /* Check the outputted XML is the same */
1445
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (email));
1446
 
        g_assert_cmpstr (xml, ==,
 
1756
        gdata_test_assert_xml (email,
1447
1757
                         "<?xml version='1.0' encoding='UTF-8'?>"
1448
1758
                         "<gd:email xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' address='fubar@gmail.com' "
1449
1759
                                "rel='http://schemas.google.com/g/2005#home' label='Personal &amp; Private' displayName='&lt;John Smith&gt;' "
1450
1760
                                "primary='true'/>");
1451
 
        g_free (xml);
1452
1761
        g_object_unref (email);
1453
1762
 
1454
1763
        /* Now parse an address with less information available */
1466
1775
        g_assert (gdata_gd_email_address_is_primary (email) == FALSE);
1467
1776
 
1468
1777
        /* Check the outputted XML contains the unknown XML */
1469
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (email));
1470
 
        g_assert_cmpstr (xml, ==,
 
1778
        gdata_test_assert_xml (email,
1471
1779
                         "<?xml version='1.0' encoding='UTF-8'?>"
1472
1780
                         "<gd:email xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' address='test@example.com' "
1473
1781
                                "primary='false'/>");
1474
 
        g_free (xml);
1475
1782
        g_object_unref (email);
1476
1783
}
1477
1784
 
1479
1786
test_gd_email_address_escaping (void)
1480
1787
{
1481
1788
        GDataGDEmailAddress *email;
1482
 
        gchar *xml;
1483
1789
 
1484
1790
        g_test_bug ("630350");
1485
1791
 
1487
1793
        gdata_gd_email_address_set_display_name (email, "<John Smith>");
1488
1794
 
1489
1795
        /* Check the outputted XML is escaped properly */
1490
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (email));
1491
 
        g_assert_cmpstr (xml, ==,
 
1796
        gdata_test_assert_xml (email,
1492
1797
                         "<?xml version='1.0' encoding='UTF-8'?>"
1493
1798
                         "<gd:email xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1494
1799
                                   "address='Fubar &lt;fubar@gmail.com&gt;' rel='http://schemas.google.com/g/2005#home?foo&amp;bar' "
1495
1800
                                   "label='Personal &amp; Private' displayName='&lt;John Smith&gt;' primary='true'/>");
1496
 
        g_free (xml);
1497
1801
        g_object_unref (email);
1498
1802
}
1499
1803
 
1501
1805
test_gd_im_address (void)
1502
1806
{
1503
1807
        GDataGDIMAddress *im, *im2;
1504
 
        gchar *xml;
1505
1808
        GError *error = NULL;
1506
1809
 
1507
1810
        im = GDATA_GD_IM_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_IM_ADDRESS,
1528
1831
        g_object_unref (im2);
1529
1832
 
1530
1833
        /* Check the outputted XML is the same */
1531
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (im));
1532
 
        g_assert_cmpstr (xml, ==,
 
1834
        gdata_test_assert_xml (im,
1533
1835
                         "<?xml version='1.0' encoding='UTF-8'?>"
1534
1836
                         "<gd:im xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1535
1837
                                "address='foo@bar.msn.com' protocol='http://schemas.google.com/g/2005#MSN' "
1536
1838
                                "rel='http://schemas.google.com/g/2005#home' primary='true'/>");
1537
 
        g_free (xml);
1538
1839
        g_object_unref (im);
1539
1840
 
1540
1841
        /* Now parse an address with less information available */
1552
1853
        g_assert (gdata_gd_im_address_is_primary (im) == FALSE);
1553
1854
 
1554
1855
        /* Check the outputted XML contains the unknown XML */
1555
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (im));
1556
 
        g_assert_cmpstr (xml, ==,
 
1856
        gdata_test_assert_xml (im,
1557
1857
                         "<?xml version='1.0' encoding='UTF-8'?>"
1558
1858
                         "<gd:im xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' address='foo@baz.example.com' "
1559
1859
                                "label='Other &amp; Miscellaneous' primary='false'/>");
1560
 
        g_free (xml);
1561
1860
        g_object_unref (im);
1562
1861
}
1563
1862
 
1565
1864
test_gd_im_address_escaping (void)
1566
1865
{
1567
1866
        GDataGDIMAddress *im;
1568
 
        gchar *xml;
1569
1867
 
1570
1868
        im = gdata_gd_im_address_new ("Fubar <fubar@gmail.com>", GDATA_GD_IM_PROTOCOL_GOOGLE_TALK "?foo&bar", GDATA_GD_IM_ADDRESS_HOME "?foo&bar",
1571
1869
                                      "Personal & Private", TRUE);
1572
1870
 
1573
1871
        /* Check the outputted XML is escaped properly */
1574
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (im));
1575
 
        g_assert_cmpstr (xml, ==,
 
1872
        gdata_test_assert_xml (im,
1576
1873
                         "<?xml version='1.0' encoding='UTF-8'?>"
1577
1874
                         "<gd:im xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1578
1875
                                "address='Fubar &lt;fubar@gmail.com&gt;' protocol='http://schemas.google.com/g/2005#GOOGLE_TALK?foo&amp;bar' "
1579
1876
                                "rel='http://schemas.google.com/g/2005#home?foo&amp;bar' label='Personal &amp; Private' primary='true'/>");
1580
 
        g_free (xml);
1581
1877
        g_object_unref (im);
1582
1878
}
1583
1879
 
1585
1881
test_gd_name (void)
1586
1882
{
1587
1883
        GDataGDName *name, *name2;
1588
 
        gchar *xml;
1589
1884
        GError *error = NULL;
1590
1885
 
1591
1886
        name = GDATA_GD_NAME (gdata_parsable_new_from_xml (GDATA_TYPE_GD_NAME,
1622
1917
        g_object_unref (name2);
1623
1918
 
1624
1919
        /* Check the outputted XML is the same */
1625
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (name));
1626
 
        g_assert_cmpstr (xml, ==,
 
1920
        gdata_test_assert_xml (name,
1627
1921
                         "<?xml version='1.0' encoding='UTF-8'?>"
1628
1922
                         "<gd:name xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>"
1629
1923
                                "<gd:givenName>Brian</gd:givenName>"
1633
1927
                                "<gd:nameSuffix>ABC</gd:nameSuffix>"
1634
1928
                                "<gd:fullName>Mr Brian Charles Blessed, ABC</gd:fullName>"
1635
1929
                         "</gd:name>");
1636
 
        g_free (xml);
1637
1930
        g_object_unref (name);
1638
1931
 
1639
1932
        /* Now parse an address with less information available */
1652
1945
        g_assert (gdata_gd_name_get_full_name (name) == NULL);
1653
1946
 
1654
1947
        /* Check the outputted XML is still correct */
1655
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (name));
1656
 
        g_assert_cmpstr (xml, ==,
 
1948
        gdata_test_assert_xml (name,
1657
1949
                         "<?xml version='1.0' encoding='UTF-8'?>"
1658
1950
                         "<gd:name xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>"
1659
1951
                                "<gd:givenName>Bob</gd:givenName>"
1660
1952
                         "</gd:name>");
1661
 
        g_free (xml);
1662
1953
        g_object_unref (name);
1663
1954
}
1664
1955
 
1667
1958
{
1668
1959
        GDataGDOrganization *org, *org2;
1669
1960
        GDataGDWhere *location;
1670
 
        gchar *xml;
1671
1961
        GError *error = NULL;
1672
1962
 
1673
1963
        org = GDATA_GD_ORGANIZATION (gdata_parsable_new_from_xml (GDATA_TYPE_GD_ORGANIZATION,
1708
1998
        g_object_unref (org2);
1709
1999
 
1710
2000
        /* Check the outputted XML is the same */
1711
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (org));
1712
 
        g_assert_cmpstr (xml, ==,
 
2001
        gdata_test_assert_xml (org,
1713
2002
                         "<?xml version='1.0' encoding='UTF-8'?>"
1714
2003
                         "<gd:organization xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1715
2004
                                "rel='http://schemas.google.com/g/2005#work' label='Work &amp; Occupation' primary='true'>"
1720
2009
                                "<gd:orgSymbol>FOO</gd:orgSymbol>"
1721
2010
                                "<gd:where valueString='Test location'/>"
1722
2011
                         "</gd:organization>");
1723
 
        g_free (xml);
1724
2012
        g_object_unref (org);
1725
2013
 
1726
2014
        /* Now parse an organization with less information available */
1742
2030
        g_assert (gdata_gd_organization_get_location (org) == NULL);
1743
2031
 
1744
2032
        /* Check the outputted XML contains the unknown XML */
1745
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (org));
1746
 
        g_assert_cmpstr (xml, ==,
 
2033
        gdata_test_assert_xml (org,
1747
2034
                         "<?xml version='1.0' encoding='UTF-8'?>"
1748
2035
                         "<gd:organization xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' primary='false'/>");
1749
 
        g_free (xml);
1750
2036
        g_object_unref (org);
1751
2037
}
1752
2038
 
1754
2040
test_gd_organization_escaping (void)
1755
2041
{
1756
2042
        GDataGDOrganization *org;
1757
 
        gchar *xml;
1758
2043
 
1759
2044
        org = gdata_gd_organization_new ("Steptoe & Son", "Title & Stuff", GDATA_GD_ORGANIZATION_WORK "?foo&bar", "Personal & Private", TRUE);
1760
2045
        gdata_gd_organization_set_department (org, "Department & Stuff");
1762
2047
        gdata_gd_organization_set_symbol (org, "<&>");
1763
2048
 
1764
2049
        /* Check the outputted XML is escaped properly */
1765
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (org));
1766
 
        g_assert_cmpstr (xml, ==,
 
2050
        gdata_test_assert_xml (org,
1767
2051
                         "<?xml version='1.0' encoding='UTF-8'?>"
1768
2052
                         "<gd:organization xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1769
2053
                                          "rel='http://schemas.google.com/g/2005#work?foo&amp;bar' label='Personal &amp; Private' primary='true'>"
1773
2057
                                 "<gd:orgJobDescription>Escaping &lt;brackets&gt;.</gd:orgJobDescription>"
1774
2058
                                 "<gd:orgSymbol>&lt;&amp;&gt;</gd:orgSymbol>"
1775
2059
                         "</gd:organization>");
1776
 
        g_free (xml);
1777
2060
        g_object_unref (org);
1778
2061
}
1779
2062
 
1781
2064
test_gd_phone_number (void)
1782
2065
{
1783
2066
        GDataGDPhoneNumber *phone, *phone2;
1784
 
        gchar *xml;
1785
2067
        GError *error = NULL;
1786
2068
 
1787
2069
        phone = GDATA_GD_PHONE_NUMBER (gdata_parsable_new_from_xml (GDATA_TYPE_GD_PHONE_NUMBER,
1809
2091
        g_object_unref (phone2);
1810
2092
 
1811
2093
        /* Check the outputted XML is the same */
1812
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (phone));
1813
 
        g_assert_cmpstr (xml, ==,
 
2094
        gdata_test_assert_xml (phone,
1814
2095
                         "<?xml version='1.0' encoding='UTF-8'?>"
1815
2096
                         "<gd:phoneNumber xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1816
2097
                                "uri='tel:+12065551212' rel='http://schemas.google.com/g/2005#mobile' label='Personal &amp; business calls only' "
1817
2098
                                "primary='false'>+1 206 555 1212</gd:phoneNumber>");
1818
 
        g_free (xml);
1819
2099
 
1820
2100
        /* Check we trim whitespace properly, and respect Unicode characters */
1821
2101
        gdata_gd_phone_number_set_number (phone, "       0123456 (789) ëxt 300  ");
1837
2117
        g_assert (gdata_gd_phone_number_is_primary (phone) == FALSE);
1838
2118
 
1839
2119
        /* Check the outputted XML contains the unknown XML */
1840
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (phone));
1841
 
        g_assert_cmpstr (xml, ==,
 
2120
        gdata_test_assert_xml (phone,
1842
2121
                         "<?xml version='1.0' encoding='UTF-8'?>"
1843
2122
                         "<gd:phoneNumber xmlns='http://www.w3.org/2005/Atom' "
1844
2123
                                "xmlns:gd='http://schemas.google.com/g/2005' primary='false'>(425) 555-8080 ext. 72585</gd:phoneNumber>");
1845
 
        g_free (xml);
1846
2124
        g_object_unref (phone);
1847
2125
}
1848
2126
 
1850
2128
test_gd_phone_number_escaping (void)
1851
2129
{
1852
2130
        GDataGDPhoneNumber *phone;
1853
 
        gchar *xml;
1854
2131
 
1855
2132
        phone = gdata_gd_phone_number_new ("0123456789 <54>", GDATA_GD_PHONE_NUMBER_WORK_MOBILE "?foo&bar", "Personal & Private",
1856
2133
                                           "tel:+012345678954?foo&bar", TRUE);
1857
2134
 
1858
2135
        /* Check the outputted XML is escaped properly */
1859
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (phone));
1860
 
        g_assert_cmpstr (xml, ==,
 
2136
        gdata_test_assert_xml (phone,
1861
2137
                         "<?xml version='1.0' encoding='UTF-8'?>"
1862
2138
                         "<gd:phoneNumber xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1863
2139
                                         "uri='tel:+012345678954?foo&amp;bar' rel='http://schemas.google.com/g/2005#work_mobile?foo&amp;bar' "
1864
2140
                                         "label='Personal &amp; Private' primary='true'>0123456789 &lt;54&gt;</gd:phoneNumber>");
1865
 
        g_free (xml);
1866
2141
        g_object_unref (phone);
1867
2142
}
1868
2143
 
1870
2145
test_gd_postal_address (void)
1871
2146
{
1872
2147
        GDataGDPostalAddress *postal, *postal2;
1873
 
        gchar *xml;
1874
2148
        GError *error = NULL;
1875
2149
 
1876
2150
        postal = GDATA_GD_POSTAL_ADDRESS (gdata_parsable_new_from_xml (GDATA_TYPE_GD_POSTAL_ADDRESS,
1909
2183
        g_object_unref (postal2);
1910
2184
 
1911
2185
        /* Check the outputted XML is the same */
1912
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (postal));
1913
 
        g_assert_cmpstr (xml, ==,
 
2186
        gdata_test_assert_xml (postal,
1914
2187
                         "<?xml version='1.0' encoding='UTF-8'?>"
1915
2188
                         "<gd:structuredPostalAddress xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1916
2189
                                "rel='http://schemas.google.com/g/2005#home' label='Home &amp; Safe House' primary='true'>"
1919
2192
                                "<gd:postcode>NY 10036</gd:postcode>"
1920
2193
                                "<gd:country code='US'>United States</gd:country>"
1921
2194
                         "</gd:structuredPostalAddress>");
1922
 
        g_free (xml);
1923
2195
 
1924
2196
        /* Check we trim whitespace properly, and respect Unicode characters */
1925
2197
        gdata_gd_postal_address_set_address (postal, "           Schöne Grüße Straße\nGermany  ");
1941
2213
        g_assert (gdata_gd_postal_address_is_primary (postal) == FALSE);
1942
2214
 
1943
2215
        /* Check the outputted XML contains the unknown XML */
1944
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (postal));
1945
 
        g_assert_cmpstr (xml, ==,
 
2216
        gdata_test_assert_xml (postal,
1946
2217
                         "<?xml version='1.0' encoding='UTF-8'?>"
1947
2218
                         "<gd:structuredPostalAddress xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' primary='false'>"
1948
2219
                                 "<gd:street>f</gd:street></gd:structuredPostalAddress>");
1949
 
        g_free (xml);
1950
2220
        g_object_unref (postal);
1951
2221
}
1952
2222
 
1954
2224
test_gd_postal_address_escaping (void)
1955
2225
{
1956
2226
        GDataGDPostalAddress *address;
1957
 
        gchar *xml;
1958
2227
 
1959
2228
        address = gdata_gd_postal_address_new (GDATA_GD_POSTAL_ADDRESS_WORK "?foo&bar", "Personal & Private", TRUE);
1960
2229
        gdata_gd_postal_address_set_address (address, "<address>");
1972
2241
        gdata_gd_postal_address_set_country (address, "<foo>", "<bar>");
1973
2242
 
1974
2243
        /* Check the outputted XML is escaped properly */
1975
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (address));
1976
 
        g_assert_cmpstr (xml, ==,
 
2244
        gdata_test_assert_xml (address,
1977
2245
                         "<?xml version='1.0' encoding='UTF-8'?>"
1978
2246
                         "<gd:structuredPostalAddress xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
1979
2247
                                                     "rel='http://schemas.google.com/g/2005#work?foo&amp;bar' label='Personal &amp; Private' "
1991
2259
                                 "<gd:country code='&lt;bar&gt;'>&lt;foo&gt;</gd:country>"
1992
2260
                                 "<gd:formattedAddress>&lt;address&gt;</gd:formattedAddress>"
1993
2261
                         "</gd:structuredPostalAddress>");
1994
 
        g_free (xml);
1995
2262
        g_object_unref (address);
1996
2263
}
1997
2264
 
1999
2266
test_gd_reminder (void)
2000
2267
{
2001
2268
        GDataGDReminder *reminder, *reminder2;
2002
 
        gchar *xml;
2003
2269
        gint64 _time;
2004
2270
        GError *error = NULL;
2005
2271
 
2015
2281
        g_assert_cmpint (gdata_gd_reminder_get_relative_time (reminder), ==, 15 * 24 * 60);
2016
2282
 
2017
2283
        /* Check the outputted XML */
2018
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (reminder));
2019
 
        g_assert_cmpstr (xml, ==,
 
2284
        gdata_test_assert_xml (reminder,
2020
2285
                         "<?xml version='1.0' encoding='UTF-8'?>"
2021
2286
                         "<gd:reminder xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' minutes='21600'/>");
2022
 
        g_free (xml);
2023
2287
        g_object_unref (reminder);
2024
2288
 
2025
2289
        /* Try again with a different property */
2072
2336
        g_object_unref (reminder2);
2073
2337
 
2074
2338
        /* Check the outputted XML */
2075
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (reminder));
2076
 
        g_assert_cmpstr (xml, ==,
 
2339
        gdata_test_assert_xml (reminder,
2077
2340
                         "<?xml version='1.0' encoding='UTF-8'?>"
2078
2341
                         "<gd:reminder xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2079
2342
                                "absoluteTime='2005-06-07T00:55:00Z' method='alert'/>");
2080
 
        g_free (xml);
2081
2343
        g_object_unref (reminder);
2082
2344
}
2083
2345
 
2085
2347
test_gd_reminder_escaping (void)
2086
2348
{
2087
2349
        GDataGDReminder *reminder;
2088
 
        gchar *xml;
2089
2350
 
2090
2351
        reminder = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT "?foo&bar", -1, 15);
2091
2352
 
2092
2353
        /* Check the outputted XML is escaped properly */
2093
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (reminder));
2094
 
        g_assert_cmpstr (xml, ==,
 
2354
        gdata_test_assert_xml (reminder,
2095
2355
                         "<?xml version='1.0' encoding='UTF-8'?>"
2096
2356
                         "<gd:reminder xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2097
2357
                                      "minutes='15' method='alert?foo&amp;bar'/>");
2098
 
        g_free (xml);
2099
2358
        g_object_unref (reminder);
2100
2359
}
2101
2360
 
2104
2363
{
2105
2364
        GDataGDWhen *when, *when2;
2106
2365
        GDataGDReminder *reminder;
2107
 
        gchar *xml;
2108
2366
        GList *reminders;
2109
2367
        gint64 _time, _time2;
2110
2368
        GError *error = NULL;
2136
2394
        g_object_unref (when2);
2137
2395
 
2138
2396
        /* Check the outputted XML is the same */
2139
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (when));
2140
 
        g_assert_cmpstr (xml, ==,
 
2397
        gdata_test_assert_xml (when,
2141
2398
                         "<?xml version='1.0' encoding='UTF-8'?>"
2142
2399
                         "<gd:when xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-07T01:00:00Z' "
2143
2400
                                "endTime='2005-06-07T02:00:00Z'/>");
2144
 
        g_free (xml);
2145
2401
        g_object_unref (when);
2146
2402
 
2147
2403
        /* Now parse a time with different information */
2175
2431
        g_object_unref (reminder);
2176
2432
 
2177
2433
        /* Check the outputted XML is correct */
2178
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (when));
2179
 
        g_assert_cmpstr (xml, ==,
 
2434
        gdata_test_assert_xml (when,
2180
2435
                         "<?xml version='1.0' encoding='UTF-8'?>"
2181
2436
                         "<gd:when xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-06' "
2182
2437
                                "endTime='2005-06-08' valueString='This weekend'>"
2184
2439
                                "<gd:reminder absoluteTime='2005-06-06T00:00:00Z' method='alert'/>"
2185
2440
                                "<foobar/>"
2186
2441
                         "</gd:when>");
2187
 
        g_free (xml);
2188
2442
        g_object_unref (when);
2189
2443
}
2190
2444
 
2192
2446
test_gd_when_escaping (void)
2193
2447
{
2194
2448
        GDataGDWhen *when;
2195
 
        gchar *xml;
2196
2449
        GTimeVal start_time;
2197
2450
 
2198
2451
        g_time_val_from_iso8601 ("2005-06-07T01:00:00Z", &start_time);
2200
2453
        gdata_gd_when_set_value_string (when, "Value string & stuff!");
2201
2454
 
2202
2455
        /* Check the outputted XML is escaped properly */
2203
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (when));
2204
 
        g_assert_cmpstr (xml, ==,
 
2456
        gdata_test_assert_xml (when,
2205
2457
                         "<?xml version='1.0' encoding='UTF-8'?>"
2206
2458
                         "<gd:when xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2207
2459
                                  "startTime='2005-06-07T01:00:00Z' valueString='Value string &amp; stuff!'/>");
2208
 
        g_free (xml);
2209
2460
        g_object_unref (when);
2210
2461
}
2211
2462
 
2213
2464
test_gd_where (void)
2214
2465
{
2215
2466
        GDataGDWhere *where, *where2;
2216
 
        gchar *xml;
2217
2467
        GError *error = NULL;
2218
2468
 
2219
2469
        where = GDATA_GD_WHERE (gdata_parsable_new_from_xml (GDATA_TYPE_GD_WHERE,
2238
2488
        g_object_unref (where2);
2239
2489
 
2240
2490
        /* Check the outputted XML is the same */
2241
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (where));
2242
 
        g_assert_cmpstr (xml, ==,
 
2491
        gdata_test_assert_xml (where,
2243
2492
                         "<?xml version='1.0' encoding='UTF-8'?>"
2244
2493
                         "<gd:where xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2245
2494
                                "label='New York Location &lt;videoconference&gt;' rel='http://schemas.google.com/g/2005#event.alternate' "
2246
2495
                                "valueString='Metropolis'/>");
2247
 
        g_free (xml);
2248
2496
        g_object_unref (where);
2249
2497
 
2250
2498
        /* Now parse a place with less information available */
2260
2508
        g_assert (gdata_gd_where_get_label (where) == NULL);
2261
2509
 
2262
2510
        /* Check the outputted XML contains the unknown XML */
2263
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (where));
2264
 
        g_assert_cmpstr (xml, ==,
 
2511
        gdata_test_assert_xml (where,
2265
2512
                         "<?xml version='1.0' encoding='UTF-8'?>"
2266
2513
                         "<gd:where xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2267
2514
                                "valueString='Google Cafeteria &lt;Building 40&gt;'/>");
2268
 
        g_free (xml);
2269
2515
        g_object_unref (where);
2270
2516
}
2271
2517
 
2273
2519
test_gd_where_escaping (void)
2274
2520
{
2275
2521
        GDataGDWhere *where;
2276
 
        gchar *xml;
2277
2522
 
2278
2523
        where = gdata_gd_where_new (GDATA_GD_WHERE_EVENT "?foo&bar", "Value string & stuff!", "<label>");
2279
2524
 
2280
2525
        /* Check the outputted XML is escaped properly */
2281
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (where));
2282
 
        g_assert_cmpstr (xml, ==,
 
2526
        gdata_test_assert_xml (where,
2283
2527
                         "<?xml version='1.0' encoding='UTF-8'?>"
2284
2528
                         "<gd:where xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2285
2529
                                   "label='&lt;label&gt;' rel='http://schemas.google.com/g/2005#event?foo&amp;bar' "
2286
2530
                                   "valueString='Value string &amp; stuff!'/>");
2287
 
        g_free (xml);
2288
2531
        g_object_unref (where);
2289
2532
}
2290
2533
 
2292
2535
test_gd_who (void)
2293
2536
{
2294
2537
        GDataGDWho *who, *who2;
2295
 
        gchar *xml;
2296
2538
        GError *error = NULL;
2297
2539
 
2298
2540
        who = GDATA_GD_WHO (gdata_parsable_new_from_xml (GDATA_TYPE_GD_WHO,
2317
2559
        g_object_unref (who2);
2318
2560
 
2319
2561
        /* Check the outputted XML is the same */
2320
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (who));
2321
 
        g_assert_cmpstr (xml, ==,
 
2562
        gdata_test_assert_xml (who,
2322
2563
                         "<?xml version='1.0' encoding='UTF-8'?>"
2323
2564
                         "<gd:who xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' email='liz@example.com' "
2324
2565
                                "rel='http://schemas.google.com/g/2005#message.to' valueString='Elizabeth'/>");
2325
 
        g_free (xml);
2326
2566
        g_object_unref (who);
2327
2567
 
2328
2568
        /* Now parse a place with less information available */
2338
2578
        g_assert (gdata_gd_who_get_email_address (who) == NULL);
2339
2579
 
2340
2580
        /* Check the outputted XML contains the unknown XML */
2341
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (who));
2342
 
        g_assert_cmpstr (xml, ==,
 
2581
        gdata_test_assert_xml (who,
2343
2582
                         "<?xml version='1.0' encoding='UTF-8'?>"
2344
2583
                         "<gd:who xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'/>");
2345
 
        g_free (xml);
2346
2584
        g_object_unref (who);
2347
2585
}
2348
2586
 
2350
2588
test_gd_who_escaping (void)
2351
2589
{
2352
2590
        GDataGDWho *who;
2353
 
        gchar *xml;
2354
2591
 
2355
2592
        who = gdata_gd_who_new (GDATA_GD_WHO_EVENT_ATTENDEE "?foo&bar", "Value string & stuff!", "John Smith <john.smith@gmail.com>");
2356
2593
 
2357
2594
        /* Check the outputted XML is escaped properly */
2358
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (who));
2359
 
        g_assert_cmpstr (xml, ==,
 
2595
        gdata_test_assert_xml (who,
2360
2596
                         "<?xml version='1.0' encoding='UTF-8'?>"
2361
2597
                         "<gd:who xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2362
2598
                                 "email='John Smith &lt;john.smith@gmail.com&gt;' rel='http://schemas.google.com/g/2005#event.attendee?foo&amp;bar' "
2363
2599
                                 "valueString='Value string &amp; stuff!'/>");
2364
 
        g_free (xml);
2365
2600
        g_object_unref (who);
2366
2601
}
2367
2602
 
2369
2604
test_media_category (void)
2370
2605
{
2371
2606
        GDataMediaCategory *category;
2372
 
        gchar *xml;
2373
2607
        GError *error = NULL;
2374
2608
 
2375
2609
        category = GDATA_MEDIA_CATEGORY (gdata_parsable_new_from_xml (GDATA_TYPE_MEDIA_CATEGORY,
2386
2620
        g_assert_cmpstr (gdata_media_category_get_label (category), ==, "Ace Ventura - Pet & Detective");
2387
2621
 
2388
2622
        /* Check the outputted XML is the same */
2389
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (category));
2390
 
        g_assert_cmpstr (xml, ==,
 
2623
        gdata_test_assert_xml (category,
2391
2624
                         "<?xml version='1.0' encoding='UTF-8'?>"
2392
2625
                         "<media:category xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' "
2393
2626
                                "scheme='http://dmoz.org' "
2394
2627
                                "label='Ace Ventura - Pet &amp; Detective'>Arts/Movies/Titles/A/Ace_Ventura_Series/Ace_Ventura_-_Pet_Detective"
2395
2628
                                "</media:category>");
2396
 
        g_free (xml);
2397
2629
        g_object_unref (category);
2398
2630
 
2399
2631
        /* Now parse one with less information available */
2409
2641
        g_assert (gdata_media_category_get_label (category) == NULL);
2410
2642
 
2411
2643
        /* Check the outputted XML is the same */
2412
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (category));
2413
 
        g_assert_cmpstr (xml, ==,
 
2644
        gdata_test_assert_xml (category,
2414
2645
                         "<?xml version='1.0' encoding='UTF-8'?>"
2415
2646
                         "<media:category xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' "
2416
2647
                                "scheme='http://video.search.yahoo.com/mrss/category_schema'>foo</media:category>");
2417
 
        g_free (xml);
 
2648
        g_object_unref (category);
 
2649
}
 
2650
 
 
2651
static void
 
2652
test_media_category_escaping (void)
 
2653
{
 
2654
        GDataMediaCategory *category;
 
2655
 
 
2656
        category = gdata_media_category_new ("<category>", "http://foo.com?foo&bar", "Label & stuff");
 
2657
 
 
2658
        /* Check the outputted XML is escaped properly */
 
2659
        gdata_test_assert_xml (category,
 
2660
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
2661
                         "<media:category xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' "
 
2662
                                         "scheme='http://foo.com?foo&amp;bar' label='Label &amp; stuff'>&lt;category&gt;</media:category>");
2418
2663
        g_object_unref (category);
2419
2664
}
2420
2665
 
2510
2755
{
2511
2756
        GDataMediaGroup *group;
2512
2757
        GList *contents, *thumbnails;
2513
 
        gchar *xml;
2514
2758
        GError *error = NULL;
2515
2759
 
2516
2760
        group = GDATA_MEDIA_GROUP (gdata_parsable_new_from_xml (GDATA_TYPE_MEDIA_GROUP,
2559
2803
        g_assert (GDATA_IS_MEDIA_THUMBNAIL (thumbnails->next->data));
2560
2804
 
2561
2805
        /* Check the outputted XML is the same */
2562
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (group));
2563
 
        g_assert_cmpstr (xml, ==,
 
2806
        gdata_test_assert_xml (group,
2564
2807
                         "<?xml version='1.0' encoding='UTF-8'?>"
2565
2808
                         "<media:group xmlns:media='http://search.yahoo.com/mrss/'>"
2566
2809
                                "<media:title>Foobar — shizzle!</media:title>"
2578
2821
                                "<media:thumbnail url='http://www.foo.com/keyframe.jpg' width='75' height='50' time='12:05:01.123'/>"
2579
2822
                                "<media:thumbnail url='http://www.foo.com/keyframe0.jpg' time='00:00:00'/>"
2580
2823
                         "</media:group>");
2581
 
        g_free (xml);
2582
2824
 
2583
2825
        /* Check setting things works */
2584
2826
        gdata_media_group_set_title (group, "Test title");
2624
2866
        g_assert (gdata_media_group_get_thumbnails (group) == NULL);
2625
2867
 
2626
2868
        /* Check the outputted XML is the same */
2627
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (group));
2628
 
        g_assert_cmpstr (xml, ==, "<?xml version='1.0' encoding='UTF-8'?>"
 
2869
        gdata_test_assert_xml (group,
 
2870
                "<?xml version='1.0' encoding='UTF-8'?>"
2629
2871
                                  "<media:group xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'></media:group>");
2630
 
        g_free (xml);
2631
2872
        g_object_unref (group);
2632
2873
}
2633
2874
#endif
2674
2915
test_gcontact_calendar (void)
2675
2916
{
2676
2917
        GDataGContactCalendar *calendar, *calendar2;
2677
 
        gchar *xml;
2678
2918
        GError *error = NULL;
2679
2919
 
2680
2920
        calendar = GDATA_GCONTACT_CALENDAR (gdata_parsable_new_from_xml (GDATA_TYPE_GCONTACT_CALENDAR,
2700
2940
        g_object_unref (calendar2);
2701
2941
 
2702
2942
        /* Check the outputted XML is the same */
2703
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (calendar));
2704
 
        g_assert_cmpstr (xml, ==,
 
2943
        gdata_test_assert_xml (calendar,
2705
2944
                         "<?xml version='1.0' encoding='UTF-8'?>"
2706
2945
                         "<gContact:calendarLink xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
2707
2946
                                "href='http://calendar.com/' rel='work' primary='true'/>");
2708
 
        g_free (xml);
2709
2947
        g_object_unref (calendar);
2710
2948
 
2711
2949
        /* Now parse a calendar with less information available */
2723
2961
        g_assert (gdata_gcontact_calendar_is_primary (calendar) == FALSE);
2724
2962
 
2725
2963
        /* Check the outputted XML is still OK */
2726
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (calendar));
2727
 
        g_assert_cmpstr (xml, ==,
 
2964
        gdata_test_assert_xml (calendar,
2728
2965
                         "<?xml version='1.0' encoding='UTF-8'?>"
2729
2966
                         "<gContact:calendarLink xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
2730
2967
                                "href='http://example.com/' label='&lt;a&gt;' primary='false'/>");
2731
 
        g_free (xml);
2732
2968
        g_object_unref (calendar);
2733
2969
}
2734
2970
 
2758
2994
}
2759
2995
 
2760
2996
static void
 
2997
test_gcontact_calendar_escaping (void)
 
2998
{
 
2999
        GDataGContactCalendar *calendar;
 
3000
 
 
3001
        /* Test with rel */
 
3002
        calendar = gdata_gcontact_calendar_new ("http://foo.com?foo&bar", "http://foo.com?foo&relation=bar", NULL, TRUE);
 
3003
 
 
3004
        /* Check the outputted XML is escaped properly */
 
3005
        gdata_test_assert_xml (calendar,
 
3006
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3007
                         "<gContact:calendarLink xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3008
                                "href='http://foo.com?foo&amp;bar' rel='http://foo.com?foo&amp;relation=bar' primary='true'/>");
 
3009
        g_object_unref (calendar);
 
3010
 
 
3011
        /* Test with label */
 
3012
        calendar = gdata_gcontact_calendar_new ("http://foo.com?foo&bar", NULL, "Label & stuff", FALSE);
 
3013
 
 
3014
        /* Check the outputted XML is escaped properly */
 
3015
        gdata_test_assert_xml (calendar,
 
3016
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3017
                         "<gContact:calendarLink xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3018
                                "href='http://foo.com?foo&amp;bar' label='Label &amp; stuff' primary='false'/>");
 
3019
        g_object_unref (calendar);
 
3020
}
 
3021
 
 
3022
static void
2761
3023
test_gcontact_event (void)
2762
3024
{
2763
3025
        GDataGContactEvent *event, *event2;
2764
3026
        GDate date;
2765
 
        gchar *xml;
2766
3027
        GError *error = NULL;
2767
3028
 
2768
3029
        event = GDATA_GCONTACT_EVENT (gdata_parsable_new_from_xml (GDATA_TYPE_GCONTACT_EVENT,
2788
3049
        g_object_unref (event2);
2789
3050
 
2790
3051
        /* Check the outputted XML is the same */
2791
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (event));
2792
 
        g_assert_cmpstr (xml, ==,
 
3052
        gdata_test_assert_xml (event,
2793
3053
                         "<?xml version='1.0' encoding='UTF-8'?>"
2794
3054
                         "<gContact:event xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2795
3055
                           "xmlns:gContact='http://schemas.google.com/contact/2008' rel='other'>"
2796
3056
                                "<gd:when startTime='2004-03-12'/>"
2797
3057
                         "</gContact:event>");
2798
 
        g_free (xml);
2799
3058
        g_object_unref (event);
2800
3059
 
2801
3060
        /* Now parse an event with different information available */
2818
3077
        g_assert_cmpstr (gdata_gcontact_event_get_label (event), ==, "<a>");
2819
3078
 
2820
3079
        /* Check the outputted XML is still OK */
2821
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (event));
2822
 
        g_assert_cmpstr (xml, ==,
 
3080
        gdata_test_assert_xml (event,
2823
3081
                         "<?xml version='1.0' encoding='UTF-8'?>"
2824
3082
                         "<gContact:event xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
2825
3083
                           "xmlns:gContact='http://schemas.google.com/contact/2008' label='&lt;a&gt;'>"
2826
3084
                                "<gd:when startTime='2000-01-01'/>"
2827
3085
                         "</gContact:event>");
2828
 
        g_free (xml);
2829
3086
        g_object_unref (event);
2830
3087
}
2831
3088
 
2857
3114
}
2858
3115
 
2859
3116
static void
 
3117
test_gcontact_event_escaping (void)
 
3118
{
 
3119
        GDataGContactEvent *event;
 
3120
        GDate date;
 
3121
 
 
3122
        g_date_clear (&date, 1);
 
3123
        g_date_set_dmy (&date, 1, G_DATE_JANUARY, 2011);
 
3124
 
 
3125
        /* Test with rel */
 
3126
        event = gdata_gcontact_event_new (&date, "http://foo.com?foo&relation=bar", NULL);
 
3127
 
 
3128
        /* Check the outputted XML is escaped properly */
 
3129
        gdata_test_assert_xml (event,
 
3130
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3131
                         "<gContact:event xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
 
3132
                                "xmlns:gContact='http://schemas.google.com/contact/2008' rel='http://foo.com?foo&amp;relation=bar'>"
 
3133
                                "<gd:when startTime='2011-01-01'/>"
 
3134
                         "</gContact:event>");
 
3135
        g_object_unref (event);
 
3136
 
 
3137
        /* Test with label */
 
3138
        event = gdata_gcontact_event_new (&date, NULL, "Label & stuff");
 
3139
 
 
3140
        /* Check the outputted XML is escaped properly */
 
3141
        gdata_test_assert_xml (event,
 
3142
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3143
                         "<gContact:event xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
 
3144
                                "xmlns:gContact='http://schemas.google.com/contact/2008' label='Label &amp; stuff'>"
 
3145
                                "<gd:when startTime='2011-01-01'/>"
 
3146
                         "</gContact:event>");
 
3147
        g_object_unref (event);
 
3148
}
 
3149
 
 
3150
static void
2860
3151
test_gcontact_external_id (void)
2861
3152
{
2862
3153
        GDataGContactExternalID *id, *id2;
2863
 
        gchar *xml;
2864
3154
        GError *error = NULL;
2865
3155
 
2866
3156
        id = GDATA_GCONTACT_EXTERNAL_ID (gdata_parsable_new_from_xml (GDATA_TYPE_GCONTACT_EXTERNAL_ID,
2884
3174
        g_object_unref (id2);
2885
3175
 
2886
3176
        /* Check the outputted XML is the same */
2887
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (id));
2888
 
        g_assert_cmpstr (xml, ==,
 
3177
        gdata_test_assert_xml (id,
2889
3178
                         "<?xml version='1.0' encoding='UTF-8'?>"
2890
3179
                         "<gContact:externalId xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
2891
3180
                                "value='5' rel='account'/>");
2892
 
        g_free (xml);
2893
3181
        g_object_unref (id);
2894
3182
 
2895
3183
        /* Now parse an ID with less information available */
2905
3193
        g_assert_cmpstr (gdata_gcontact_external_id_get_label (id), ==, "<a>");
2906
3194
 
2907
3195
        /* Check the outputted XML is still OK */
2908
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (id));
2909
 
        g_assert_cmpstr (xml, ==,
 
3196
        gdata_test_assert_xml (id,
2910
3197
                         "<?xml version='1.0' encoding='UTF-8'?>"
2911
3198
                         "<gContact:externalId xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
2912
3199
                                "value='' label='&lt;a&gt;'/>");
2913
 
        g_free (xml);
2914
3200
        g_object_unref (id);
2915
3201
}
2916
3202
 
2938
3224
}
2939
3225
 
2940
3226
static void
 
3227
test_gcontact_external_id_escaping (void)
 
3228
{
 
3229
        GDataGContactExternalID *id;
 
3230
 
 
3231
        /* Test with rel */
 
3232
        id = gdata_gcontact_external_id_new ("<id>", "http://foo.com?foo&relation=bar", NULL);
 
3233
 
 
3234
        /* Check the outputted XML is escaped properly */
 
3235
        gdata_test_assert_xml (id,
 
3236
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3237
                         "<gContact:externalId xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3238
                                "value='&lt;id&gt;' rel='http://foo.com?foo&amp;relation=bar'/>");
 
3239
        g_object_unref (id);
 
3240
 
 
3241
        /* Test with label */
 
3242
        id = gdata_gcontact_external_id_new ("<id>", NULL, "Label & stuff");
 
3243
 
 
3244
        /* Check the outputted XML is escaped properly */
 
3245
        gdata_test_assert_xml (id,
 
3246
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3247
                         "<gContact:externalId xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3248
                                "value='&lt;id&gt;' label='Label &amp; stuff'/>");
 
3249
        g_object_unref (id);
 
3250
}
 
3251
 
 
3252
static void
2941
3253
test_gcontact_jot (void)
2942
3254
{
2943
3255
        GDataGContactJot *jot, *jot2;
2944
 
        gchar *xml;
2945
3256
        GError *error = NULL;
2946
3257
 
2947
3258
        jot = GDATA_GCONTACT_JOT (gdata_parsable_new_from_xml (GDATA_TYPE_GCONTACT_JOT,
2961
3272
        g_object_unref (jot2);
2962
3273
 
2963
3274
        /* Check the outputted XML is the same */
2964
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (jot));
2965
 
        g_assert_cmpstr (xml, ==,
 
3275
        gdata_test_assert_xml (jot,
2966
3276
                         "<?xml version='1.0' encoding='UTF-8'?>"
2967
3277
                         "<gContact:jot xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' rel='user'>"
2968
3278
                                "They like &lt;angles&gt;.</gContact:jot>");
2969
 
        g_free (xml);
2970
3279
        g_object_unref (jot);
2971
3280
 
2972
3281
        /* Now parse a jot with different information available */
2981
3290
        g_assert (gdata_gcontact_jot_get_content (jot) == NULL);
2982
3291
 
2983
3292
        /* Check the outputted XML is still OK */
2984
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (jot));
2985
 
        g_assert_cmpstr (xml, ==,
 
3293
        gdata_test_assert_xml (jot,
2986
3294
                         "<?xml version='1.0' encoding='UTF-8'?>"
2987
3295
                         "<gContact:jot xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' rel='other'/>");
2988
 
        g_free (xml);
2989
3296
        g_object_unref (jot);
2990
3297
}
2991
3298
 
3010
3317
}
3011
3318
 
3012
3319
static void
 
3320
test_gcontact_jot_escaping (void)
 
3321
{
 
3322
        GDataGContactJot *jot;
 
3323
 
 
3324
        jot = gdata_gcontact_jot_new ("Content & stuff", "http://foo.com?foo&relation=bar");
 
3325
 
 
3326
        /* Check the outputted XML is escaped properly */
 
3327
        gdata_test_assert_xml (jot,
 
3328
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3329
                         "<gContact:jot xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3330
                                "rel='http://foo.com?foo&amp;relation=bar'>Content &amp; stuff</gContact:jot>");
 
3331
        g_object_unref (jot);
 
3332
}
 
3333
 
 
3334
static void
3013
3335
test_gcontact_language (void)
3014
3336
{
3015
3337
        GDataGContactLanguage *language, *language2;
3016
 
        gchar *xml;
3017
3338
        GError *error = NULL;
3018
3339
 
3019
3340
        language = GDATA_GCONTACT_LANGUAGE (gdata_parsable_new_from_xml (GDATA_TYPE_GCONTACT_LANGUAGE,
3036
3357
        g_object_unref (language2);
3037
3358
 
3038
3359
        /* Check the outputted XML is the same */
3039
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (language));
3040
 
        g_assert_cmpstr (xml, ==,
 
3360
        gdata_test_assert_xml (language,
3041
3361
                         "<?xml version='1.0' encoding='UTF-8'?>"
3042
3362
                         "<gContact:language xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
3043
3363
                                "code='en-GB'/>");
3044
 
        g_free (xml);
3045
3364
        g_object_unref (language);
3046
3365
 
3047
3366
        /* Now parse a language with less information available */
3057
3376
        g_assert_cmpstr (gdata_gcontact_language_get_label (language), ==, "Gobbledegook");
3058
3377
 
3059
3378
        /* Check the outputted XML is still OK */
3060
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (language));
3061
 
        g_assert_cmpstr (xml, ==,
 
3379
        gdata_test_assert_xml (language,
3062
3380
                         "<?xml version='1.0' encoding='UTF-8'?>"
3063
3381
                         "<gContact:language xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
3064
3382
                                "label='Gobbledegook'/>");
3065
 
        g_free (xml);
3066
3383
        g_object_unref (language);
3067
3384
}
3068
3385
 
3089
3406
}
3090
3407
 
3091
3408
static void
 
3409
test_gcontact_language_escaping (void)
 
3410
{
 
3411
        GDataGContactLanguage *language;
 
3412
 
 
3413
        /* Test with code */
 
3414
        language = gdata_gcontact_language_new ("<code>", NULL);
 
3415
 
 
3416
        /* Check the outputted XML is escaped properly */
 
3417
        gdata_test_assert_xml (language,
 
3418
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3419
                         "<gContact:language xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3420
                                "code='&lt;code&gt;'/>");
 
3421
        g_object_unref (language);
 
3422
 
 
3423
        /* Test with label */
 
3424
        language = gdata_gcontact_language_new (NULL, "Label & stuff");
 
3425
 
 
3426
        /* Check the outputted XML is escaped properly */
 
3427
        gdata_test_assert_xml (language,
 
3428
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3429
                         "<gContact:language xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3430
                                "label='Label &amp; stuff'/>");
 
3431
        g_object_unref (language);
 
3432
}
 
3433
 
 
3434
static void
3092
3435
test_gcontact_relation (void)
3093
3436
{
3094
3437
        GDataGContactRelation *relation, *relation2;
3095
 
        gchar *xml;
3096
3438
        GError *error = NULL;
3097
3439
 
3098
3440
        relation = GDATA_GCONTACT_RELATION (gdata_parsable_new_from_xml (GDATA_TYPE_GCONTACT_RELATION,
3112
3454
        g_object_unref (relation2);
3113
3455
 
3114
3456
        /* Check the outputted XML is the same */
3115
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (relation));
3116
 
        g_assert_cmpstr (xml, ==,
 
3457
        gdata_test_assert_xml (relation,
3117
3458
                         "<?xml version='1.0' encoding='UTF-8'?>"
3118
3459
                         "<gContact:relation xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' rel='child'>"
3119
3460
                                "Fred</gContact:relation>");
3120
 
        g_free (xml);
3121
3461
        g_object_unref (relation);
3122
3462
 
3123
3463
        /* Now parse a relation with different information available */
3133
3473
        g_assert_cmpstr (gdata_gcontact_relation_get_label (relation), ==, "<a>");
3134
3474
 
3135
3475
        /* Check the outputted XML is still OK */
3136
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (relation));
3137
 
        g_assert_cmpstr (xml, ==,
 
3476
        gdata_test_assert_xml (relation,
3138
3477
                         "<?xml version='1.0' encoding='UTF-8'?>"
3139
3478
                         "<gContact:relation xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
3140
3479
                           "label='&lt;a&gt;'>Sid</gContact:relation>");
3141
 
        g_free (xml);
3142
3480
        g_object_unref (relation);
3143
3481
}
3144
3482
 
3166
3504
}
3167
3505
 
3168
3506
static void
 
3507
test_gcontact_relation_escaping (void)
 
3508
{
 
3509
        GDataGContactRelation *relation;
 
3510
 
 
3511
        /* Test with rel */
 
3512
        relation = gdata_gcontact_relation_new ("First & Last Name", "http://foo.com?foo&relation=bar", NULL);
 
3513
 
 
3514
        /* Check the outputted XML is escaped properly */
 
3515
        gdata_test_assert_xml (relation,
 
3516
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3517
                         "<gContact:relation xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3518
                                "rel='http://foo.com?foo&amp;relation=bar'>First &amp; Last Name</gContact:relation>");
 
3519
        g_object_unref (relation);
 
3520
 
 
3521
        /* Test with label */
 
3522
        relation = gdata_gcontact_relation_new ("First & Last Name", NULL, "Label & stuff");
 
3523
 
 
3524
        /* Check the outputted XML is escaped properly */
 
3525
        gdata_test_assert_xml (relation,
 
3526
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3527
                         "<gContact:relation xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3528
                                "label='Label &amp; stuff'>First &amp; Last Name</gContact:relation>");
 
3529
        g_object_unref (relation);
 
3530
}
 
3531
 
 
3532
static void
3169
3533
test_gcontact_website (void)
3170
3534
{
3171
3535
        GDataGContactWebsite *website, *website2;
3172
 
        gchar *xml;
3173
3536
        GError *error = NULL;
3174
3537
 
3175
3538
        website = GDATA_GCONTACT_WEBSITE (gdata_parsable_new_from_xml (GDATA_TYPE_GCONTACT_WEBSITE,
3195
3558
        g_object_unref (website2);
3196
3559
 
3197
3560
        /* Check the outputted XML is the same */
3198
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (website));
3199
 
        g_assert_cmpstr (xml, ==,
 
3561
        gdata_test_assert_xml (website,
3200
3562
                         "<?xml version='1.0' encoding='UTF-8'?>"
3201
3563
                         "<gContact:website xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
3202
3564
                                "href='http://example.com/' rel='work' label='&lt;Markup&gt; blog' primary='true'/>");
3203
 
        g_free (xml);
3204
3565
        g_object_unref (website);
3205
3566
 
3206
3567
        /* Now parse a website with less information available */
3217
3578
        g_assert (gdata_gcontact_website_is_primary (website) == FALSE);
3218
3579
 
3219
3580
        /* Check the outputted XML is still OK */
3220
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (website));
3221
 
        g_assert_cmpstr (xml, ==,
 
3581
        gdata_test_assert_xml (website,
3222
3582
                         "<?xml version='1.0' encoding='UTF-8'?>"
3223
3583
                         "<gContact:website xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
3224
3584
                                "href='http://test.com/' rel='ftp' primary='false'/>");
3225
 
        g_free (xml);
3226
3585
        g_object_unref (website);
3227
3586
}
3228
3587
 
3249
3608
#undef TEST_XML_ERROR_HANDLING
3250
3609
}
3251
3610
 
 
3611
static void
 
3612
test_gcontact_website_escaping (void)
 
3613
{
 
3614
        GDataGContactWebsite *website;
 
3615
 
 
3616
        website = gdata_gcontact_website_new ("http://foo.com?foo&bar", "http://foo.com?foo&relation=bar", "Label & stuff", TRUE);
 
3617
 
 
3618
        /* Check the outputted XML is escaped properly */
 
3619
        gdata_test_assert_xml (website,
 
3620
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
3621
                         "<gContact:website xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
 
3622
                                "href='http://foo.com?foo&amp;bar' rel='http://foo.com?foo&amp;relation=bar' label='Label &amp; stuff' "
 
3623
                                "primary='true'/>");
 
3624
        g_object_unref (website);
 
3625
}
 
3626
 
3252
3627
int
3253
3628
main (int argc, char *argv[])
3254
3629
{
3255
3630
        gdata_test_init (argc, argv);
3256
3631
 
 
3632
        g_test_add_func ("/tests/xml_comparison", test_xml_comparison);
 
3633
 
3257
3634
        g_test_add_func ("/service/network_error", test_service_network_error);
3258
3635
        g_test_add_func ("/service/locale", test_service_locale);
3259
3636
 
3260
3637
        g_test_add_func ("/entry/get_xml", test_entry_get_xml);
3261
3638
        g_test_add_func ("/entry/parse_xml", test_entry_parse_xml);
3262
3639
        g_test_add_func ("/entry/error_handling", test_entry_error_handling);
 
3640
        g_test_add_func ("/entry/escaping", test_entry_escaping);
3263
3641
 
3264
3642
        g_test_add_func ("/feed/parse_xml", test_feed_parse_xml);
3265
3643
        g_test_add_func ("/feed/error_handling", test_feed_error_handling);
 
3644
        g_test_add_func ("/feed/escaping", test_feed_escaping);
3266
3645
 
3267
3646
        g_test_add_func ("/query/categories", test_query_categories);
3268
3647
        g_test_add_func ("/query/unicode", test_query_unicode);
3270
3649
 
3271
3650
        g_test_add_func ("/access-rule/get_xml", test_access_rule_get_xml);
3272
3651
        g_test_add_func ("/access-rule/error_handling", test_access_rule_error_handling);
 
3652
        g_test_add_func ("/access-rule/escaping", test_access_rule_escaping);
3273
3653
 
3274
3654
        g_test_add_func ("/comparable", test_comparable);
3275
3655
 
3278
3658
 
3279
3659
        g_test_add_func ("/atom/author", test_atom_author);
3280
3660
        g_test_add_func ("/atom/author/error_handling", test_atom_author_error_handling);
 
3661
        g_test_add_func ("/atom/author/escaping", test_atom_author_escaping);
3281
3662
        g_test_add_func ("/atom/category", test_atom_category);
3282
3663
        g_test_add_func ("/atom/category/error_handling", test_atom_category_error_handling);
 
3664
        g_test_add_func ("/atom/category/escaping", test_atom_category_escaping);
3283
3665
        g_test_add_func ("/atom/generator", test_atom_generator);
3284
3666
        g_test_add_func ("/atom/generator/error_handling", test_atom_generator_error_handling);
3285
3667
        g_test_add_func ("/atom/link", test_atom_link);
3286
3668
        g_test_add_func ("/atom/link/error_handling", test_atom_link_error_handling);
 
3669
        g_test_add_func ("/atom/link/escaping", test_atom_link_escaping);
3287
3670
 
3288
3671
        g_test_add_func ("/app/categories", test_app_categories);
3289
3672
 
3308
3691
        g_test_add_func ("/gd/who/escaping", test_gd_who_escaping);
3309
3692
 
3310
3693
        g_test_add_func ("/media/category", test_media_category);
 
3694
        g_test_add_func ("/media/category/escaping", test_media_category_escaping);
3311
3695
        g_test_add_func ("/media/content", test_media_content);
3312
3696
        g_test_add_func ("/media/credit", test_media_credit);
3313
3697
        /* g_test_add_func ("/media/group", test_media_group); */
3317
3701
 
3318
3702
        g_test_add_func ("/gcontact/calendar", test_gcontact_calendar);
3319
3703
        g_test_add_func ("/gcontact/calendar/error_handling", test_gcontact_calendar_error_handling);
 
3704
        g_test_add_func ("/gcontact/calendar/escaping", test_gcontact_calendar_escaping);
3320
3705
        g_test_add_func ("/gcontact/event", test_gcontact_event);
3321
3706
        g_test_add_func ("/gcontact/event/error_handling", test_gcontact_event_error_handling);
 
3707
        g_test_add_func ("/gcontact/event/escaping", test_gcontact_event_escaping);
3322
3708
        g_test_add_func ("/gcontact/external_id", test_gcontact_external_id);
3323
3709
        g_test_add_func ("/gcontact/external_id/error_handling", test_gcontact_external_id_error_handling);
 
3710
        g_test_add_func ("/gcontact/external_id/escaping", test_gcontact_external_id_escaping);
3324
3711
        g_test_add_func ("/gcontact/jot", test_gcontact_jot);
3325
3712
        g_test_add_func ("/gcontact/jot/error_handling", test_gcontact_jot_error_handling);
 
3713
        g_test_add_func ("/gcontact/jot/escaping", test_gcontact_jot_escaping);
3326
3714
        g_test_add_func ("/gcontact/language", test_gcontact_language);
3327
3715
        g_test_add_func ("/gcontact/language/error_handling", test_gcontact_language_error_handling);
 
3716
        g_test_add_func ("/gcontact/language/escaping", test_gcontact_language_escaping);
3328
3717
        g_test_add_func ("/gcontact/relation", test_gcontact_relation);
3329
3718
        g_test_add_func ("/gcontact/relation/error_handling", test_gcontact_relation_error_handling);
 
3719
        g_test_add_func ("/gcontact/relation/escaping", test_gcontact_relation_escaping);
3330
3720
        g_test_add_func ("/gcontact/website", test_gcontact_website);
3331
3721
        g_test_add_func ("/gcontact/website/error_handling", test_gcontact_website_error_handling);
 
3722
        g_test_add_func ("/gcontact/website/escaping", test_gcontact_website_escaping);
3332
3723
 
3333
3724
        return g_test_run ();
3334
3725
}