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

« back to all changes in this revision

Viewing changes to gdata/tests/youtube.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
#define DEVELOPER_KEY "AI39si7Me3Q7zYs6hmkFvpRBD2nrkVjYYsUO5lh_3HdOkGRc9g6Z4nzxZatk_aAo2EsA21k7vrda0OO6oFg2rnhMedZXPyXoEw"
27
 
#define YT_USERNAME "GDataTest"
28
27
 
29
28
static void
30
29
test_authentication (void)
51
50
        g_assert (gdata_service_is_authenticated (service) == TRUE);
52
51
        g_assert_cmpstr (gdata_service_get_username (service), ==, USERNAME);
53
52
        g_assert_cmpstr (gdata_service_get_password (service), ==, PASSWORD);
54
 
        g_assert_cmpstr (gdata_youtube_service_get_youtube_user (GDATA_YOUTUBE_SERVICE (service)), ==, YT_USERNAME);
55
53
 
56
54
        g_object_unref (service);
57
55
}
73
71
        g_assert (gdata_service_is_authenticated (service) == TRUE);
74
72
        g_assert_cmpstr (gdata_service_get_username (service), ==, USERNAME);
75
73
        g_assert_cmpstr (gdata_service_get_password (service), ==, PASSWORD);
76
 
        g_assert_cmpstr (gdata_youtube_service_get_youtube_user (GDATA_YOUTUBE_SERVICE (service)), ==, YT_USERNAME);
77
74
}
78
75
 
79
76
static void
261
258
        g_main_loop_unref (main_loop);
262
259
}
263
260
 
 
261
typedef struct {
 
262
        GDataYouTubeService *service;
 
263
        GDataYouTubeVideo *video;
 
264
        GDataYouTubeVideo *updated_video;
 
265
        GFile *video_file;
 
266
        gchar *slug;
 
267
        gchar *content_type;
 
268
        GFileInputStream *file_stream;
 
269
} UploadData;
 
270
 
264
271
static void
265
 
test_upload_simple (gconstpointer service)
 
272
setup_upload (UploadData *data, gconstpointer service)
266
273
{
267
 
        GDataYouTubeVideo *video, *new_video;
268
274
        GDataMediaCategory *category;
269
 
        GFile *video_file;
270
 
        gchar *xml;
 
275
        GFileInfo *file_info;
271
276
        const gchar * const tags[] = { "toast", "wedding", NULL };
272
277
        GError *error = NULL;
273
278
 
274
 
        video = gdata_youtube_video_new (NULL);
275
 
 
276
 
        gdata_entry_set_title (GDATA_ENTRY (video), "Bad Wedding Toast");
277
 
        gdata_youtube_video_set_description (video, "I gave a bad toast at my friend's wedding.");
 
279
        data->service = g_object_ref ((gpointer) service);
 
280
 
 
281
        /* Create the metadata for the video being uploaded */
 
282
        data->video = gdata_youtube_video_new (NULL);
 
283
 
 
284
        gdata_entry_set_title (GDATA_ENTRY (data->video), "Bad Wedding Toast");
 
285
        gdata_youtube_video_set_description (data->video, "I gave a bad toast at my friend's wedding.");
278
286
        category = gdata_media_category_new ("People", "http://gdata.youtube.com/schemas/2007/categories.cat", NULL);
279
 
        gdata_youtube_video_set_category (video, category);
 
287
        gdata_youtube_video_set_category (data->video, category);
280
288
        g_object_unref (category);
281
 
        gdata_youtube_video_set_keywords (video, tags);
282
 
 
283
 
        /* Check the XML */
284
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (video));
285
 
        g_assert_cmpstr (xml, ==,
286
 
                         "<?xml version='1.0' encoding='UTF-8'?>"
287
 
                         "<entry xmlns='http://www.w3.org/2005/Atom' "
288
 
                                "xmlns:media='http://search.yahoo.com/mrss/' "
289
 
                                "xmlns:gd='http://schemas.google.com/g/2005' "
290
 
                                "xmlns:yt='http://gdata.youtube.com/schemas/2007' "
291
 
                                "xmlns:app='http://www.w3.org/2007/app'>"
292
 
                                "<title type='text'>Bad Wedding Toast</title>"
293
 
                                "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>"
294
 
                                "<media:group>"
295
 
                                        "<media:category scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>People</media:category>"
296
 
                                        "<media:title type='plain'>Bad Wedding Toast</media:title>"
297
 
                                        "<media:description type='plain'>I gave a bad toast at my friend&apos;s wedding.</media:description>"
298
 
                                        "<media:keywords>toast,wedding</media:keywords>"
299
 
                                "</media:group>"
300
 
                                "<app:control>"
301
 
                                        "<app:draft>no</app:draft>"
302
 
                                "</app:control>"
303
 
                         "</entry>");
304
 
        g_free (xml);
305
 
 
 
289
        gdata_youtube_video_set_keywords (data->video, tags);
 
290
 
 
291
        /* Get a file to upload */
306
292
        /* TODO: fix the path */
307
 
        video_file = g_file_new_for_path (TEST_FILE_DIR "sample.ogg");
 
293
        data->video_file = g_file_new_for_path (TEST_FILE_DIR "sample.ogg");
 
294
 
 
295
        /* Get the file's info */
 
296
        file_info = g_file_query_info (data->video_file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
 
297
                                       G_FILE_QUERY_INFO_NONE, NULL, &error);
 
298
        g_assert_no_error (error);
 
299
        g_assert (G_IS_FILE_INFO (file_info));
 
300
 
 
301
        data->slug = g_strdup (g_file_info_get_display_name (file_info));
 
302
        data->content_type = g_strdup (g_file_info_get_content_type (file_info));
 
303
 
 
304
        g_object_unref (file_info);
 
305
 
 
306
        /* Get an input stream for the file */
 
307
        data->file_stream = g_file_read (data->video_file, NULL, &error);
 
308
        g_assert_no_error (error);
 
309
        g_assert (G_IS_FILE_INPUT_STREAM (data->file_stream));
 
310
}
 
311
 
 
312
static void
 
313
teardown_upload (UploadData *data, gconstpointer service)
 
314
{
 
315
        /* Delete the uploaded video, if possible */
 
316
        if (data->updated_video != NULL) {
 
317
                gdata_service_delete_entry (GDATA_SERVICE (service), GDATA_ENTRY (data->updated_video), NULL, NULL);
 
318
                g_object_unref (data->updated_video);
 
319
        }
 
320
 
 
321
        g_object_unref (data->video);
 
322
        g_object_unref (data->video_file);
 
323
        g_free (data->slug);
 
324
        g_free (data->content_type);
 
325
        g_object_unref (data->file_stream);
 
326
        g_object_unref (data->service);
 
327
}
 
328
 
 
329
static void
 
330
test_upload_simple (UploadData *data, gconstpointer service)
 
331
{
 
332
        GDataUploadStream *upload_stream;
 
333
        const gchar * const *tags, * const *tags2;
 
334
        gssize transfer_size;
 
335
        GError *error = NULL;
 
336
 
 
337
        /* Prepare the upload stream */
 
338
        upload_stream = gdata_youtube_service_upload_video (GDATA_YOUTUBE_SERVICE (service), data->video, data->slug, data->content_type, NULL,
 
339
                                                            &error);
 
340
        g_assert_no_error (error);
 
341
        g_assert (GDATA_IS_UPLOAD_STREAM (upload_stream));
308
342
 
309
343
        /* Upload the video */
310
 
        new_video = gdata_youtube_service_upload_video (GDATA_YOUTUBE_SERVICE (service), video, video_file, NULL, &error);
311
 
        g_assert_no_error (error);
312
 
        g_assert (GDATA_IS_YOUTUBE_VIDEO (new_video));
313
 
        g_clear_error (&error);
314
 
 
315
 
        /* TODO: check entries and feed properties */
316
 
 
317
 
        g_object_unref (video);
318
 
        g_object_unref (new_video);
319
 
        g_object_unref (video_file);
 
344
        transfer_size = g_output_stream_splice (G_OUTPUT_STREAM (upload_stream), G_INPUT_STREAM (data->file_stream),
 
345
                                                G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, &error);
 
346
        g_assert_no_error (error);
 
347
        g_assert_cmpint (transfer_size, >, 0);
 
348
 
 
349
        /* Finish off the upload */
 
350
        data->updated_video = gdata_youtube_service_finish_video_upload (GDATA_YOUTUBE_SERVICE (service), upload_stream, &error);
 
351
        g_assert_no_error (error);
 
352
        g_assert (GDATA_IS_YOUTUBE_VIDEO (data->updated_video));
 
353
 
 
354
        /* Check the video's properties */
 
355
        g_assert (gdata_entry_is_inserted (GDATA_ENTRY (data->updated_video)));
 
356
        g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (data->updated_video)), ==, gdata_entry_get_title (GDATA_ENTRY (data->video)));
 
357
        g_assert_cmpstr (gdata_youtube_video_get_description (data->updated_video), ==, gdata_youtube_video_get_description (data->video));
 
358
        g_assert_cmpstr (gdata_media_category_get_category (gdata_youtube_video_get_category (data->updated_video)), ==,
 
359
                         gdata_media_category_get_category (gdata_youtube_video_get_category (data->video)));
 
360
 
 
361
        tags = gdata_youtube_video_get_keywords (data->video);
 
362
        tags2 = gdata_youtube_video_get_keywords (data->updated_video);
 
363
        g_assert_cmpuint (g_strv_length ((gchar**) tags2), ==, g_strv_length ((gchar**) tags));
 
364
        g_assert_cmpstr (tags2[0], ==, tags[0]);
 
365
        g_assert_cmpstr (tags2[1], ==, tags[1]);
 
366
        g_assert_cmpstr (tags2[2], ==, tags[2]);
 
367
}
 
368
 
 
369
typedef struct {
 
370
        UploadData data;
 
371
        GMainLoop *main_loop;
 
372
} UploadAsyncData;
 
373
 
 
374
static void
 
375
setup_upload_async (UploadAsyncData *data, gconstpointer service)
 
376
{
 
377
        setup_upload ((UploadData*) data, service);
 
378
        data->main_loop = g_main_loop_new (NULL, TRUE);
 
379
}
 
380
 
 
381
static void
 
382
teardown_upload_async (UploadAsyncData *data, gconstpointer service)
 
383
{
 
384
        teardown_upload ((UploadData*) data, service);
 
385
        g_main_loop_unref (data->main_loop);
 
386
}
 
387
 
 
388
static void
 
389
test_upload_async_cb (GOutputStream *stream, GAsyncResult *result, UploadAsyncData *data)
 
390
{
 
391
        const gchar * const *tags, * const *tags2;
 
392
        gssize transfer_size;
 
393
        GError *error = NULL;
 
394
 
 
395
        /* Finish off the transfer */
 
396
        transfer_size = g_output_stream_splice_finish (stream, result, &error);
 
397
        g_assert_no_error (error);
 
398
        g_assert_cmpint (transfer_size, >, 0);
 
399
 
 
400
        /* Finish off the upload */
 
401
        data->data.updated_video = gdata_youtube_service_finish_video_upload (data->data.service, GDATA_UPLOAD_STREAM (stream), &error);
 
402
        g_assert_no_error (error);
 
403
        g_assert (GDATA_IS_YOUTUBE_VIDEO (data->data.updated_video));
 
404
 
 
405
        /* Check the video's properties */
 
406
        g_assert (gdata_entry_is_inserted (GDATA_ENTRY (data->data.updated_video)));
 
407
        g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (data->data.updated_video)), ==, gdata_entry_get_title (GDATA_ENTRY (data->data.video)));
 
408
        g_assert_cmpstr (gdata_youtube_video_get_description (data->data.updated_video), ==, gdata_youtube_video_get_description (data->data.video));
 
409
        g_assert_cmpstr (gdata_media_category_get_category (gdata_youtube_video_get_category (data->data.updated_video)), ==,
 
410
                         gdata_media_category_get_category (gdata_youtube_video_get_category (data->data.video)));
 
411
 
 
412
        tags = gdata_youtube_video_get_keywords (data->data.video);
 
413
        tags2 = gdata_youtube_video_get_keywords (data->data.updated_video);
 
414
        g_assert_cmpuint (g_strv_length ((gchar**) tags2), ==, g_strv_length ((gchar**) tags));
 
415
        g_assert_cmpstr (tags2[0], ==, tags[0]);
 
416
        g_assert_cmpstr (tags2[1], ==, tags[1]);
 
417
        g_assert_cmpstr (tags2[2], ==, tags[2]);
 
418
 
 
419
        g_main_loop_quit (data->main_loop);
 
420
}
 
421
 
 
422
static void
 
423
test_upload_async (UploadAsyncData *data, gconstpointer service)
 
424
{
 
425
        GDataUploadStream *upload_stream;
 
426
        GError *error = NULL;
 
427
 
 
428
        /* Prepare the upload stream */
 
429
        upload_stream = gdata_youtube_service_upload_video (GDATA_YOUTUBE_SERVICE (service), data->data.video, data->data.slug,
 
430
                                                            data->data.content_type, NULL, &error);
 
431
        g_assert_no_error (error);
 
432
        g_assert (GDATA_IS_UPLOAD_STREAM (upload_stream));
 
433
 
 
434
        /* Upload the video asynchronously */
 
435
        g_output_stream_splice_async (G_OUTPUT_STREAM (upload_stream), G_INPUT_STREAM (data->data.file_stream),
 
436
                                      G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, G_PRIORITY_DEFAULT, NULL,
 
437
                                      (GAsyncReadyCallback) test_upload_async_cb, data);
 
438
        g_main_loop_run (data->main_loop);
 
439
 
 
440
        g_object_unref (upload_stream);
320
441
}
321
442
 
322
443
static void
376
497
{
377
498
        GDataYouTubeVideo *video;
378
499
        gint64 recorded;
379
 
        gchar *xml;
380
500
        GError *error = NULL;
381
501
 
382
502
        video = GDATA_YOUTUBE_VIDEO (gdata_parsable_new_from_xml (GDATA_TYPE_YOUTUBE_VIDEO,
416
536
        gdata_youtube_video_set_recorded (video, recorded);
417
537
 
418
538
        /* Check the XML */
419
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (video));
420
 
        g_assert_cmpstr (xml, ==,
 
539
        gdata_test_assert_xml (video,
421
540
                         "<?xml version='1.0' encoding='UTF-8'?>"
422
541
                         "<entry xmlns='http://www.w3.org/2005/Atom' "
423
542
                                "xmlns:media='http://search.yahoo.com/mrss/' "
424
543
                                "xmlns:gd='http://schemas.google.com/g/2005' "
425
544
                                "xmlns:yt='http://gdata.youtube.com/schemas/2007' "
426
545
                                "xmlns:app='http://www.w3.org/2007/app' "
 
546
                                "xmlns:georss='http://www.georss.org/georss' "
 
547
                                "xmlns:gml='http://www.opengis.net/gml' "
427
548
                                "gd:etag='W/\"CEMFSX47eCp7ImA9WxVUGEw.\"'>"
428
549
                                "<title type='text'>Judas Priest - Painkiller</title>"
429
550
                                "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>"
445
566
                                        "<app:draft>no</app:draft>"
446
567
                                "</app:control>"
447
568
                         "</entry>");
448
 
        g_free (xml);
449
569
 
450
570
        /* TODO: more tests on entry properties */
451
571
 
456
576
test_parsing_yt_access_control (void)
457
577
{
458
578
        GDataYouTubeVideo *video;
459
 
        gchar *xml;
460
579
        GError *error = NULL;
461
580
 
462
581
        video = GDATA_YOUTUBE_VIDEO (gdata_parsable_new_from_xml (GDATA_TYPE_YOUTUBE_VIDEO,
505
624
        gdata_youtube_video_set_access_control (video, GDATA_YOUTUBE_ACTION_EMBED, GDATA_YOUTUBE_PERMISSION_DENIED);
506
625
 
507
626
        /* Check the XML */
508
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (video));
509
 
        g_assert_cmpstr (xml, ==,
 
627
        gdata_test_assert_xml (video,
510
628
                         "<?xml version='1.0' encoding='UTF-8'?>"
511
629
                         "<entry xmlns='http://www.w3.org/2005/Atom' "
512
630
                                "xmlns:media='http://search.yahoo.com/mrss/' "
513
631
                                "xmlns:gd='http://schemas.google.com/g/2005' "
514
632
                                "xmlns:yt='http://gdata.youtube.com/schemas/2007' "
515
633
                                "xmlns:app='http://www.w3.org/2007/app' "
 
634
                                "xmlns:georss='http://www.georss.org/georss' "
 
635
                                "xmlns:gml='http://www.opengis.net/gml' "
516
636
                                "gd:etag='W/\"CEMFSX47eCp7ImA9WxVUGEw.\"'>"
517
637
                                "<title type='text'>Judas Priest - Painkiller</title>"
518
638
                                "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>"
540
660
                                        "<app:draft>no</app:draft>"
541
661
                                "</app:control>"
542
662
                         "</entry>");
543
 
        g_free (xml);
544
663
 
545
664
        g_object_unref (video);
546
665
}
650
769
}*/
651
770
 
652
771
static void
 
772
test_parsing_georss_where (void)
 
773
{
 
774
        GDataYouTubeVideo *video;
 
775
        gdouble latitude, longitude;
 
776
        GError *error = NULL;
 
777
 
 
778
        video = GDATA_YOUTUBE_VIDEO (gdata_parsable_new_from_xml (GDATA_TYPE_YOUTUBE_VIDEO,
 
779
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
780
                       "xmlns:media='http://search.yahoo.com/mrss/' "
 
781
                       "xmlns:yt='http://gdata.youtube.com/schemas/2007' "
 
782
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
783
                       "xmlns:georss='http://www.georss.org/georss' "
 
784
                       "xmlns:gml='http://www.opengis.net/gml'>"
 
785
                        "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>"
 
786
                        "<published>2006-05-16T14:06:37.000Z</published>"
 
787
                        "<updated>2009-03-23T12:46:58.000Z</updated>"
 
788
                        "<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>"
 
789
                        "<title>Some video somewhere</title>"
 
790
                        "<link rel='http://www.iana.org/assignments/relation/alternate' type='text/html' href='http://www.youtube.com/watch?v=JAagedeKdcQ'/>"
 
791
                        "<link rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo'/>"
 
792
                        "<author>"
 
793
                                "<name>Foo</name>"
 
794
                                "<uri>http://gdata.youtube.com/feeds/api/users/Foo</uri>"
 
795
                        "</author>"
 
796
                        "<media:group>"
 
797
                                "<media:title type='plain'>Some video somewhere</media:title>"
 
798
                                "<media:credit role='uploader' scheme='urn:youtube'>Foo</media:credit>"
 
799
                                "<media:category label='Music' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Music</media:category>"
 
800
                        "</media:group>"
 
801
                        "<georss:where>"
 
802
                                "<gml:Point>"
 
803
                                        "<gml:pos>41.14556884765625 -8.63525390625</gml:pos>"
 
804
                                "</gml:Point>"
 
805
                        "</georss:where>"
 
806
                "</entry>", -1, &error));
 
807
        g_assert_no_error (error);
 
808
        g_assert (GDATA_IS_YOUTUBE_VIDEO (video));
 
809
        g_clear_error (&error);
 
810
 
 
811
        /* Test the coordinates */
 
812
        gdata_youtube_video_get_coordinates (video, &latitude, &longitude);
 
813
        g_assert_cmpfloat (latitude, ==, 41.14556884765625);
 
814
        g_assert_cmpfloat (longitude, ==, -8.63525390625);
 
815
 
 
816
        /* Update them and see if they're set OK and the XML's written out OK */
 
817
        gdata_youtube_video_set_coordinates (video, 5.5, 6.5);
 
818
 
 
819
        g_object_get (G_OBJECT (video),
 
820
                      "latitude", &latitude,
 
821
                      "longitude", &longitude,
 
822
                      NULL);
 
823
 
 
824
        g_assert_cmpfloat (latitude, ==, 5.5);
 
825
        g_assert_cmpfloat (longitude, ==, 6.5);
 
826
 
 
827
        /* Check the XML */
 
828
        gdata_test_assert_xml (video,
 
829
                "<?xml version='1.0' encoding='UTF-8'?>"
 
830
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
831
                       "xmlns:app='http://www.w3.org/2007/app' "
 
832
                       "xmlns:media='http://search.yahoo.com/mrss/' "
 
833
                       "xmlns:yt='http://gdata.youtube.com/schemas/2007' "
 
834
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
835
                       "xmlns:georss='http://www.georss.org/georss' "
 
836
                       "xmlns:gml='http://www.opengis.net/gml'>"
 
837
                        "<title type='text'>Some video somewhere</title>"
 
838
                        "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>"
 
839
                        "<updated>2009-03-23T12:46:58Z</updated>"
 
840
                        "<published>2006-05-16T14:06:37Z</published>"
 
841
                        "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>"
 
842
                        "<link href='http://www.youtube.com/watch?v=JAagedeKdcQ' rel='http://www.iana.org/assignments/relation/alternate' type='text/html'/>"
 
843
                        "<link href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo' rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml'/>"
 
844
                        "<author>"
 
845
                                "<name>Foo</name>"
 
846
                                "<uri>http://gdata.youtube.com/feeds/api/users/Foo</uri>"
 
847
                        "</author>"
 
848
                        "<media:group>"
 
849
                                "<media:category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' label='Music'>Music</media:category>"
 
850
                                "<media:title type='plain'>Some video somewhere</media:title>"
 
851
                        "</media:group>"
 
852
                        "<app:control><app:draft>no</app:draft></app:control>"
 
853
                        "<georss:where>"
 
854
                                "<gml:Point>"
 
855
                                        "<gml:pos>5.5 6.5</gml:pos>"
 
856
                                "</gml:Point>"
 
857
                        "</georss:where>"
 
858
                "</entry>");
 
859
 
 
860
        /* Unset the properties and ensure they're removed from the XML */
 
861
        gdata_youtube_video_set_coordinates (video, G_MAXDOUBLE, G_MAXDOUBLE);
 
862
 
 
863
        gdata_youtube_video_get_coordinates (video, &latitude, &longitude);
 
864
        g_assert_cmpfloat (latitude, ==, G_MAXDOUBLE);
 
865
        g_assert_cmpfloat (longitude, ==, G_MAXDOUBLE);
 
866
 
 
867
        /* Check the XML */
 
868
        gdata_test_assert_xml (video,
 
869
                "<?xml version='1.0' encoding='UTF-8'?>"
 
870
                "<entry xmlns='http://www.w3.org/2005/Atom' "
 
871
                       "xmlns:app='http://www.w3.org/2007/app' "
 
872
                       "xmlns:media='http://search.yahoo.com/mrss/' "
 
873
                       "xmlns:yt='http://gdata.youtube.com/schemas/2007' "
 
874
                       "xmlns:gd='http://schemas.google.com/g/2005' "
 
875
                       "xmlns:georss='http://www.georss.org/georss' "
 
876
                       "xmlns:gml='http://www.opengis.net/gml'>"
 
877
                        "<title type='text'>Some video somewhere</title>"
 
878
                        "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>"
 
879
                        "<updated>2009-03-23T12:46:58Z</updated>"
 
880
                        "<published>2006-05-16T14:06:37Z</published>"
 
881
                        "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>"
 
882
                        "<link href='http://www.youtube.com/watch?v=JAagedeKdcQ' rel='http://www.iana.org/assignments/relation/alternate' type='text/html'/>"
 
883
                        "<link href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo' rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml'/>"
 
884
                        "<author>"
 
885
                                "<name>Foo</name>"
 
886
                                "<uri>http://gdata.youtube.com/feeds/api/users/Foo</uri>"
 
887
                        "</author>"
 
888
                        "<media:group>"
 
889
                                "<media:category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' label='Music'>Music</media:category>"
 
890
                                "<media:title type='plain'>Some video somewhere</media:title>"
 
891
                        "</media:group>"
 
892
                        "<app:control><app:draft>no</app:draft></app:control>"
 
893
                "</entry>");
 
894
 
 
895
        g_object_unref (video);
 
896
}
 
897
 
 
898
static void
 
899
test_video_escaping (void)
 
900
{
 
901
        GDataYouTubeVideo *video;
 
902
        const gchar * const keywords[] = { "<keyword1>", "keyword2 & stuff, things", NULL };
 
903
 
 
904
        video = gdata_youtube_video_new (NULL);
 
905
        gdata_youtube_video_set_location (video, "Here & there");
 
906
        gdata_youtube_video_set_access_control (video, "<action>", GDATA_YOUTUBE_PERMISSION_ALLOWED);
 
907
        gdata_youtube_video_set_keywords (video, keywords);
 
908
        gdata_youtube_video_set_description (video, "Description & stuff.");
 
909
        gdata_youtube_video_set_aspect_ratio (video, "4 & 3");
 
910
 
 
911
        /* Check the outputted XML is escaped properly */
 
912
        gdata_test_assert_xml (video,
 
913
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
914
                         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' "
 
915
                                "xmlns:gd='http://schemas.google.com/g/2005' "
 
916
                                "xmlns:yt='http://gdata.youtube.com/schemas/2007' xmlns:app='http://www.w3.org/2007/app' "
 
917
                                "xmlns:georss='http://www.georss.org/georss' xmlns:gml='http://www.opengis.net/gml'>"
 
918
                                "<title type='text'></title>"
 
919
                                "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>"
 
920
                                "<media:group>"
 
921
                                        "<media:description type='plain'>Description &amp; stuff.</media:description>"
 
922
                                        "<media:keywords>&lt;keyword1&gt;,keyword2 &amp; stuff%2C things</media:keywords>"
 
923
                                        "<yt:aspectratio>4 &amp; 3</yt:aspectratio>"
 
924
                                "</media:group>"
 
925
                                "<yt:location>Here &amp; there</yt:location>"
 
926
                                "<yt:accessControl action='&lt;action&gt;' permission='allowed'/>"
 
927
                                "<app:control><app:draft>no</app:draft></app:control>"
 
928
                         "</entry>");
 
929
        g_object_unref (video);
 
930
}
 
931
 
 
932
static void
653
933
test_query_uri (void)
654
934
{
655
935
        gdouble latitude, longitude, radius;
1047
1327
        guint op_id;
1048
1328
        GMainLoop *main_loop;
1049
1329
        GCancellable *cancellable;
 
1330
        GError *error = NULL;
1050
1331
 
1051
1332
        /* Run an async query operation on the video */
1052
1333
        operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), "http://gdata.youtube.com/feeds/api/videos/batch");
1053
1334
        op_id = gdata_test_batch_operation_query (operation, gdata_entry_get_id (data->new_video), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL,
1054
 
                                                  NULL);
 
1335
                                                  &error);
1055
1336
 
1056
1337
        main_loop = g_main_loop_new (NULL, TRUE);
1057
1338
        cancellable = g_cancellable_new ();
1060
1341
        g_cancellable_cancel (cancellable); /* this should cancel the operation before it even starts, as we haven't run the main loop yet */
1061
1342
 
1062
1343
        g_main_loop_run (main_loop);
 
1344
 
 
1345
        g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
 
1346
        g_clear_error (&error);
 
1347
 
1063
1348
        g_main_loop_unref (main_loop);
1064
1349
        g_object_unref (cancellable);
 
1350
        g_object_unref (operation);
1065
1351
}
1066
1352
 
1067
1353
static void
1091
1377
                g_test_add_data_func ("/youtube/query/related", service, test_query_related);
1092
1378
                g_test_add_data_func ("/youtube/query/related_async", service, test_query_related_async);
1093
1379
 
1094
 
                g_test_add_data_func ("/youtube/upload/simple", service, test_upload_simple);
 
1380
                g_test_add ("/youtube/upload/simple", UploadData, service, setup_upload, test_upload_simple, teardown_upload);
 
1381
                g_test_add ("/youtube/upload/async", UploadAsyncData, service, setup_upload_async, test_upload_async, teardown_upload_async);
1095
1382
 
1096
1383
                g_test_add_data_func ("/youtube/query/single", service, test_query_single);
1097
1384
                g_test_add_data_func ("/youtube/query/single_async", service, test_query_single_async);
1110
1397
        g_test_add_func ("/youtube/parsing/yt:accessControl", test_parsing_yt_access_control);
1111
1398
        g_test_add_func ("/youtube/parsing/yt:category", test_parsing_yt_category);
1112
1399
        g_test_add_func ("/youtube/parsing/video_id_from_uri", test_parsing_video_id_from_uri);
 
1400
        g_test_add_func ("/youtube/parsing/georss:where", test_parsing_georss_where);
 
1401
 
 
1402
        g_test_add_func ("/youtube/video/escaping", test_video_escaping);
1113
1403
 
1114
1404
        g_test_add_func ("/youtube/query/uri", test_query_uri);
1115
1405
        g_test_add_func ("/youtube/query/etag", test_query_etag);