261
258
g_main_loop_unref (main_loop);
262
GDataYouTubeService *service;
263
GDataYouTubeVideo *video;
264
GDataYouTubeVideo *updated_video;
268
GFileInputStream *file_stream;
265
test_upload_simple (gconstpointer service)
272
setup_upload (UploadData *data, gconstpointer service)
267
GDataYouTubeVideo *video, *new_video;
268
274
GDataMediaCategory *category;
275
GFileInfo *file_info;
271
276
const gchar * const tags[] = { "toast", "wedding", NULL };
272
277
GError *error = NULL;
274
video = gdata_youtube_video_new (NULL);
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);
281
/* Create the metadata for the video being uploaded */
282
data->video = gdata_youtube_video_new (NULL);
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);
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'/>"
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's wedding.</media:description>"
298
"<media:keywords>toast,wedding</media:keywords>"
301
"<app:draft>no</app:draft>"
289
gdata_youtube_video_set_keywords (data->video, tags);
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");
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));
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));
304
g_object_unref (file_info);
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));
313
teardown_upload (UploadData *data, gconstpointer service)
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);
321
g_object_unref (data->video);
322
g_object_unref (data->video_file);
324
g_free (data->content_type);
325
g_object_unref (data->file_stream);
326
g_object_unref (data->service);
330
test_upload_simple (UploadData *data, gconstpointer service)
332
GDataUploadStream *upload_stream;
333
const gchar * const *tags, * const *tags2;
334
gssize transfer_size;
335
GError *error = NULL;
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,
340
g_assert_no_error (error);
341
g_assert (GDATA_IS_UPLOAD_STREAM (upload_stream));
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);
315
/* TODO: check entries and feed properties */
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);
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));
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)));
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]);
371
GMainLoop *main_loop;
375
setup_upload_async (UploadAsyncData *data, gconstpointer service)
377
setup_upload ((UploadData*) data, service);
378
data->main_loop = g_main_loop_new (NULL, TRUE);
382
teardown_upload_async (UploadAsyncData *data, gconstpointer service)
384
teardown_upload ((UploadData*) data, service);
385
g_main_loop_unref (data->main_loop);
389
test_upload_async_cb (GOutputStream *stream, GAsyncResult *result, UploadAsyncData *data)
391
const gchar * const *tags, * const *tags2;
392
gssize transfer_size;
393
GError *error = NULL;
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);
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));
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)));
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]);
419
g_main_loop_quit (data->main_loop);
423
test_upload_async (UploadAsyncData *data, gconstpointer service)
425
GDataUploadStream *upload_stream;
426
GError *error = NULL;
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));
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);
440
g_object_unref (upload_stream);
772
test_parsing_georss_where (void)
774
GDataYouTubeVideo *video;
775
gdouble latitude, longitude;
776
GError *error = NULL;
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'/>"
794
"<uri>http://gdata.youtube.com/feeds/api/users/Foo</uri>"
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>"
803
"<gml:pos>41.14556884765625 -8.63525390625</gml:pos>"
806
"</entry>", -1, &error));
807
g_assert_no_error (error);
808
g_assert (GDATA_IS_YOUTUBE_VIDEO (video));
809
g_clear_error (&error);
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);
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);
819
g_object_get (G_OBJECT (video),
820
"latitude", &latitude,
821
"longitude", &longitude,
824
g_assert_cmpfloat (latitude, ==, 5.5);
825
g_assert_cmpfloat (longitude, ==, 6.5);
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'/>"
846
"<uri>http://gdata.youtube.com/feeds/api/users/Foo</uri>"
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>"
852
"<app:control><app:draft>no</app:draft></app:control>"
855
"<gml:pos>5.5 6.5</gml:pos>"
860
/* Unset the properties and ensure they're removed from the XML */
861
gdata_youtube_video_set_coordinates (video, G_MAXDOUBLE, G_MAXDOUBLE);
863
gdata_youtube_video_get_coordinates (video, &latitude, &longitude);
864
g_assert_cmpfloat (latitude, ==, G_MAXDOUBLE);
865
g_assert_cmpfloat (longitude, ==, G_MAXDOUBLE);
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'/>"
886
"<uri>http://gdata.youtube.com/feeds/api/users/Foo</uri>"
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>"
892
"<app:control><app:draft>no</app:draft></app:control>"
895
g_object_unref (video);
899
test_video_escaping (void)
901
GDataYouTubeVideo *video;
902
const gchar * const keywords[] = { "<keyword1>", "keyword2 & stuff, things", NULL };
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");
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'/>"
921
"<media:description type='plain'>Description & stuff.</media:description>"
922
"<media:keywords><keyword1>,keyword2 & stuff%2C things</media:keywords>"
923
"<yt:aspectratio>4 & 3</yt:aspectratio>"
925
"<yt:location>Here & there</yt:location>"
926
"<yt:accessControl action='<action>' permission='allowed'/>"
927
"<app:control><app:draft>no</app:draft></app:control>"
929
g_object_unref (video);
653
933
test_query_uri (void)
655
935
gdouble latitude, longitude, radius;