24
24
#include "common.h"
27
test_xml_comparison (void)
29
GDataAccessRule *rule;
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");
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>"
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'/>"
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>"
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'/>"
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'>"
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'/>"
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>"
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);
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>"
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);
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'>"
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);
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>"
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);
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>"
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);
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);
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>"
162
"<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
164
"<gAcl:scope type='user' value='foo@example.com'/>"
165
"</entry>", FALSE) == FALSE);
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>"
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);
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>"
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);
193
g_object_unref (rule);
27
197
test_entry_get_xml (void)
29
199
gint64 updated, published, updated2, published2, updated3, published3;
527
test_entry_escaping (void)
530
GError *error = NULL;
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 & stuff</title>"
537
"<id>http://foo.com/?foo&bar</id>"
538
"<updated>2010-12-10T17:21:24Z</updated>"
539
"<published>2010-12-10T17:21:24Z</published>"
540
"<summary type='text'>Summary & stuff</summary>"
541
"<rights>Free & open source</rights>"
542
"<content type='text'>Content & things.</content>"
543
"</entry>", -1, &error));
544
g_assert_no_error (error);
545
g_assert (GDATA_IS_ENTRY (entry));
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 & stuff</title>"
552
"<id>http://foo.com/?foo&bar</id>"
553
"<updated>2010-12-10T17:21:24Z</updated>"
554
"<published>2010-12-10T17:21:24Z</published>"
555
"<summary type='text'>Summary & stuff</summary>"
556
"<rights>Free & open source</rights>"
557
"<content type='text'>Content & things.</content>"
559
g_object_unref (entry);
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 & stuff</title>"
566
"<content type='text/plain' src='http://foo.com?foo&bar'/>"
567
"</entry>", -1, &error));
568
g_assert_no_error (error);
569
g_assert (GDATA_IS_ENTRY (entry));
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 & stuff</title>"
576
"<content type='text/plain' src='http://foo.com?foo&bar'/>"
578
g_object_unref (entry);
362
582
test_feed_parse_xml (void)
3249
3608
#undef TEST_XML_ERROR_HANDLING
3612
test_gcontact_website_escaping (void)
3614
GDataGContactWebsite *website;
3616
website = gdata_gcontact_website_new ("http://foo.com?foo&bar", "http://foo.com?foo&relation=bar", "Label & stuff", TRUE);
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&bar' rel='http://foo.com?foo&relation=bar' label='Label & stuff' "
3623
"primary='true'/>");
3624
g_object_unref (website);
3253
3628
main (int argc, char *argv[])
3255
3630
gdata_test_init (argc, argv);
3632
g_test_add_func ("/tests/xml_comparison", test_xml_comparison);
3257
3634
g_test_add_func ("/service/network_error", test_service_network_error);
3258
3635
g_test_add_func ("/service/locale", test_service_locale);
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);
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);
3267
3646
g_test_add_func ("/query/categories", test_query_categories);
3268
3647
g_test_add_func ("/query/unicode", test_query_unicode);
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);
3333
3724
return g_test_run ();