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

« back to all changes in this revision

Viewing changes to gdata/tests/calendar.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:
227
227
}
228
228
 
229
229
static void
 
230
test_query_events_async_cb (GDataService *service, GAsyncResult *async_result, GMainLoop *main_loop)
 
231
{
 
232
        GDataFeed *feed;
 
233
        GError *error = NULL;
 
234
 
 
235
        feed = gdata_service_query_finish (service, async_result, &error);
 
236
        g_assert_no_error (error);
 
237
        g_assert (GDATA_IS_CALENDAR_FEED (feed));
 
238
 
 
239
        /* TODO: Tests? */
 
240
        g_main_loop_quit (main_loop);
 
241
 
 
242
        g_object_unref (feed);
 
243
}
 
244
 
 
245
static void
 
246
test_query_events_async (gconstpointer service)
 
247
{
 
248
        GDataCalendarCalendar *calendar;
 
249
        GMainLoop *main_loop;
 
250
        GError *error = NULL;
 
251
 
 
252
        calendar = get_calendar (service, &error);
 
253
        main_loop = g_main_loop_new (NULL, TRUE);
 
254
 
 
255
        gdata_calendar_service_query_events_async (GDATA_CALENDAR_SERVICE (service), calendar, NULL, NULL, NULL, NULL,
 
256
                                                   (GAsyncReadyCallback) test_query_events_async_cb, main_loop);
 
257
        g_main_loop_run (main_loop);
 
258
 
 
259
        g_main_loop_unref (main_loop);
 
260
        g_object_unref (calendar);
 
261
}
 
262
 
 
263
static void
230
264
test_insert_simple (gconstpointer service)
231
265
{
232
266
        GDataCalendarEvent *event, *new_event;
234
268
        GDataGDWho *who;
235
269
        GDataGDWhen *when;
236
270
        GTimeVal start_time, end_time;
237
 
        gchar *xml;
238
271
        GError *error = NULL;
239
272
 
240
273
        event = gdata_calendar_event_new (NULL);
256
289
        g_object_unref (when);
257
290
 
258
291
        /* Check the XML */
259
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (event));
260
 
        g_assert_cmpstr (xml, ==,
 
292
        gdata_test_assert_xml (event,
261
293
                         "<?xml version='1.0' encoding='UTF-8'?>"
262
294
                         "<entry xmlns='http://www.w3.org/2005/Atom' "
263
295
                                "xmlns:gd='http://schemas.google.com/g/2005' "
278
310
                                        "valueString='John Smith\342\200\275'/>"
279
311
                                "<gd:where valueString='Rolling Lawn Courts'/>"
280
312
                         "</entry>");
281
 
        g_free (xml);
282
313
 
283
314
        /* Insert the event */
284
315
        new_event = gdata_calendar_service_insert_event (GDATA_CALENDAR_SERVICE (service), event, NULL, &error);
293
324
}
294
325
 
295
326
static void
 
327
test_insert_simple_async_cb (GDataService *service, GAsyncResult *result, GMainLoop *main_loop)
 
328
{
 
329
        GDataEntry *event;
 
330
        GError *error = NULL;
 
331
 
 
332
        event = gdata_service_insert_entry_finish (service, result, &error);
 
333
        g_assert_no_error (error);
 
334
        g_assert (GDATA_IS_CALENDAR_EVENT (event));
 
335
 
 
336
        /* Check the event is correct */
 
337
        g_assert_cmpstr (gdata_entry_get_title (event), ==, "Tennis with Beth");
 
338
 
 
339
        g_main_loop_quit (main_loop);
 
340
 
 
341
        g_object_unref (event);
 
342
}
 
343
 
 
344
static void
 
345
test_insert_simple_async (gconstpointer service)
 
346
{
 
347
        GDataCalendarEvent *event;
 
348
        GDataGDWhere *where;
 
349
        GDataGDWho *who;
 
350
        GDataGDWhen *when;
 
351
        GTimeVal start_time, end_time;
 
352
        GMainLoop *main_loop;
 
353
 
 
354
        event = gdata_calendar_event_new (NULL);
 
355
 
 
356
        gdata_entry_set_title (GDATA_ENTRY (event), "Tennis with Beth");
 
357
        gdata_entry_set_content (GDATA_ENTRY (event), "Meet for a quick lesson.");
 
358
        gdata_calendar_event_set_transparency (event, GDATA_GD_EVENT_TRANSPARENCY_OPAQUE);
 
359
        gdata_calendar_event_set_status (event, GDATA_GD_EVENT_STATUS_CONFIRMED);
 
360
        where = gdata_gd_where_new (NULL, "Rolling Lawn Courts", NULL);
 
361
        gdata_calendar_event_add_place (event, where);
 
362
        g_object_unref (where);
 
363
        who = gdata_gd_who_new (GDATA_GD_WHO_EVENT_ORGANIZER, "John Smith‽", "john.smith@example.com");
 
364
        gdata_calendar_event_add_person (event, who);
 
365
        g_object_unref (who);
 
366
        g_time_val_from_iso8601 ("2009-04-17T15:00:00.000Z", &start_time);
 
367
        g_time_val_from_iso8601 ("2009-04-17T17:00:00.000Z", &end_time);
 
368
        when = gdata_gd_when_new (start_time.tv_sec, end_time.tv_sec, FALSE);
 
369
        gdata_calendar_event_add_time (event, when);
 
370
        g_object_unref (when);
 
371
 
 
372
        main_loop = g_main_loop_new (NULL, TRUE);
 
373
 
 
374
        /* Insert the event */
 
375
        gdata_calendar_service_insert_event_async (GDATA_CALENDAR_SERVICE (service), event, NULL, (GAsyncReadyCallback) test_insert_simple_async_cb,
 
376
                                                   main_loop);
 
377
        g_main_loop_run (main_loop);
 
378
 
 
379
        g_main_loop_unref (main_loop);
 
380
        g_object_unref (event);
 
381
}
 
382
 
 
383
static void
296
384
test_xml_dates (void)
297
385
{
298
386
        GDataCalendarEvent *event;
299
387
        GList *times, *i;
300
388
        GDataGDWhen *when;
301
389
        gint64 _time;
302
 
        gchar *xml;
303
390
        GError *error = NULL;
304
391
 
305
392
        event = GDATA_CALENDAR_EVENT (gdata_parsable_new_from_xml (GDATA_TYPE_CALENDAR_EVENT,
357
444
        g_assert (gdata_gd_when_get_reminders (when) == NULL);
358
445
 
359
446
        /* Check the XML */
360
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (event));
361
 
        g_assert_cmpstr (xml, ==,
 
447
        gdata_test_assert_xml (event,
362
448
                         "<?xml version='1.0' encoding='UTF-8'?>"
363
449
                         "<entry xmlns='http://www.w3.org/2005/Atom' "
364
450
                                "xmlns:gd='http://schemas.google.com/g/2005' "
375
461
                                "<gd:when startTime='2009-04-17T15:00:00Z'/>"
376
462
                                "<gd:when startTime='2009-04-27' endTime='2009-05-06'/>"
377
463
                         "</entry>");
378
 
        g_free (xml);
379
464
 
380
465
        g_object_unref (event);
381
466
}
445
530
}
446
531
 
447
532
static void
 
533
test_calendar_escaping (void)
 
534
{
 
535
        GDataCalendarCalendar *calendar;
 
536
 
 
537
        calendar = gdata_calendar_calendar_new (NULL);
 
538
        gdata_calendar_calendar_set_timezone (calendar, "<timezone>");
 
539
 
 
540
        /* Check the outputted XML is escaped properly */
 
541
        gdata_test_assert_xml (calendar,
 
542
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
543
                         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
 
544
                                "xmlns:gCal='http://schemas.google.com/gCal/2005' xmlns:app='http://www.w3.org/2007/app'>"
 
545
                                "<title type='text'></title>"
 
546
                                "<category term='http://schemas.google.com/gCal/2005#calendarmeta' scheme='http://schemas.google.com/g/2005#kind'/>"
 
547
                                "<gCal:timezone value='&lt;timezone&gt;'/>"
 
548
                                "<gCal:hidden value='false'/>"
 
549
                                "<gCal:color value='#000000'/>"
 
550
                                "<gCal:selected value='false'/>"
 
551
                         "</entry>");
 
552
        g_object_unref (calendar);
 
553
}
 
554
 
 
555
static void
 
556
test_event_escaping (void)
 
557
{
 
558
        GDataCalendarEvent *event;
 
559
 
 
560
        event = gdata_calendar_event_new (NULL);
 
561
        gdata_calendar_event_set_status (event, "<status>");
 
562
        gdata_calendar_event_set_visibility (event, "<visibility>");
 
563
        gdata_calendar_event_set_transparency (event, "<transparency>");
 
564
        gdata_calendar_event_set_uid (event, "<uid>");
 
565
        gdata_calendar_event_set_recurrence (event, "<recurrence>");
 
566
 
 
567
        /* Check the outputted XML is escaped properly */
 
568
        gdata_test_assert_xml (event,
 
569
                         "<?xml version='1.0' encoding='UTF-8'?>"
 
570
                         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
 
571
                                "xmlns:gCal='http://schemas.google.com/gCal/2005' xmlns:app='http://www.w3.org/2007/app'>"
 
572
                                "<title type='text'></title>"
 
573
                                "<category term='http://schemas.google.com/g/2005#event' scheme='http://schemas.google.com/g/2005#kind'/>"
 
574
                                "<gd:eventStatus value='&lt;status&gt;'/>"
 
575
                                "<gd:visibility value='&lt;visibility&gt;'/>"
 
576
                                "<gd:transparency value='&lt;transparency&gt;'/>"
 
577
                                "<gCal:uid value='&lt;uid&gt;'/>"
 
578
                                "<gCal:guestsCanModify value='false'/>"
 
579
                                "<gCal:guestsCanInviteOthers value='false'/>"
 
580
                                "<gCal:guestsCanSeeGuests value='false'/>"
 
581
                                "<gCal:anyoneCanAddSelf value='false'/>"
 
582
                                "<gd:recurrence>&lt;recurrence&gt;</gd:recurrence>"
 
583
                         "</entry>");
 
584
        g_object_unref (event);
 
585
}
 
586
 
 
587
static void
448
588
test_query_uri (void)
449
589
{
450
590
        gint64 _time;
570
710
        GDataCategory *category;
571
711
        GDataLink *_link;
572
712
        GList *categories;
573
 
        gchar *xml;
574
713
        gint64 edited;
575
714
        GError *error = NULL;
576
715
 
587
726
        g_assert_cmpstr (scope_value, ==, "darcy@gmail.com");
588
727
 
589
728
        /* Check the XML */
590
 
        xml = gdata_parsable_get_xml (GDATA_PARSABLE (rule));
591
 
        g_assert_cmpstr (xml, ==,
 
729
        gdata_test_assert_xml (rule,
592
730
                         "<?xml version='1.0' encoding='UTF-8'?>"
593
731
                         "<entry xmlns='http://www.w3.org/2005/Atom' "
594
732
                                "xmlns:gd='http://schemas.google.com/g/2005' "
598
736
                                "<gAcl:role value='http://schemas.google.com/gCal/2005#editor'/>"
599
737
                                "<gAcl:scope type='user' value='darcy@gmail.com'/>"
600
738
                         "</entry>");
601
 
        g_free (xml);
602
739
 
603
740
        /* Insert the rule */
604
741
        _link = gdata_entry_look_up_link (GDATA_ENTRY (calendar), GDATA_LINK_ACCESS_CONTROL_LIST);
769
906
        gdata_entry_set_title (GDATA_ENTRY (event), "Fooish Bar");
770
907
 
771
908
        gdata_test_batch_operation_insertion (operation, GDATA_ENTRY (event), &inserted_entry, NULL);
772
 
        g_assert (gdata_batch_operation_run (operation, NULL, &error) == TRUE);
 
909
        g_assert (gdata_test_batch_operation_run (operation, NULL, &error) == TRUE);
773
910
        g_assert_no_error (error);
774
911
 
775
912
        g_clear_error (&error);
786
923
                                                   NULL);
787
924
        g_assert_cmpuint (op_id, !=, op_id2);
788
925
 
789
 
        g_assert (gdata_batch_operation_run (operation, NULL, &error) == TRUE);
 
926
        g_assert (gdata_test_batch_operation_run (operation, NULL, &error) == TRUE);
790
927
        g_assert_no_error (error);
791
928
 
792
929
        g_clear_error (&error);
805
942
        g_assert_cmpuint (op_id, !=, op_id3);
806
943
        g_assert_cmpuint (op_id2, !=, op_id3);
807
944
 
808
 
        g_assert (gdata_batch_operation_run (operation, NULL, &error) == TRUE);
 
945
        g_assert (gdata_test_batch_operation_run (operation, NULL, &error) == TRUE);
809
946
        g_assert_no_error (error);
810
947
 
811
948
        g_assert_error (entry_error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);
821
958
        /* Turns out that we can't run this test, because the Calendar service sucks with ETags and doesn't error. */
822
959
        /*operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), "https://www.google.com/calendar/feeds/default/private/full/batch");
823
960
        gdata_test_batch_operation_update (operation, inserted_entry2, NULL, &entry_error);
824
 
        g_assert (gdata_batch_operation_run (operation, NULL, &error) == TRUE);
 
961
        g_assert (gdata_test_batch_operation_run (operation, NULL, &error) == TRUE);
825
962
        g_assert_no_error (error);
826
963
 
827
964
        g_assert_error (entry_error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_CONFLICT);
834
971
        /* Run a final batch operation to delete the second entry */
835
972
        operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), "https://www.google.com/calendar/feeds/default/private/full/batch");
836
973
        gdata_test_batch_operation_deletion (operation, inserted_entry3, NULL);
837
 
        g_assert (gdata_batch_operation_run (operation, NULL, &error) == TRUE);
 
974
        g_assert (gdata_test_batch_operation_run (operation, NULL, &error) == TRUE);
838
975
        g_assert_no_error (error);
839
976
 
840
977
        g_clear_error (&error);
870
1007
{
871
1008
        GError *error = NULL;
872
1009
 
873
 
        g_assert (gdata_batch_operation_run_finish (operation, async_result, &error) == TRUE);
 
1010
        /* Clear all pending events (such as callbacks for the operations) */
 
1011
        while (g_main_context_iteration (NULL, FALSE) == TRUE);
 
1012
 
 
1013
        g_assert (gdata_test_batch_operation_run_finish (operation, async_result, &error) == TRUE);
874
1014
        g_assert_no_error (error);
875
1015
        g_clear_error (&error);
876
1016
 
903
1043
{
904
1044
        GError *error = NULL;
905
1045
 
906
 
        g_assert (gdata_batch_operation_run_finish (operation, async_result, &error) == FALSE);
 
1046
        /* Clear all pending events (such as callbacks for the operations) */
 
1047
        while (g_main_context_iteration (NULL, FALSE) == TRUE);
 
1048
 
 
1049
        g_assert (gdata_test_batch_operation_run_finish (operation, async_result, &error) == FALSE);
907
1050
        g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
908
1051
        g_clear_error (&error);
909
1052
 
917
1060
        guint op_id;
918
1061
        GMainLoop *main_loop;
919
1062
        GCancellable *cancellable;
 
1063
        GError *error = NULL;
920
1064
 
921
1065
        /* Run an async query operation on the event */
922
1066
        operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), "https://www.google.com/calendar/feeds/default/private/full/batch");
923
1067
        op_id = gdata_test_batch_operation_query (operation, gdata_entry_get_id (GDATA_ENTRY (data->new_event)), GDATA_TYPE_CALENDAR_EVENT,
924
 
                                                  GDATA_ENTRY (data->new_event), NULL, NULL);
 
1068
                                                  GDATA_ENTRY (data->new_event), NULL, &error);
925
1069
 
926
1070
        main_loop = g_main_loop_new (NULL, TRUE);
927
1071
        cancellable = g_cancellable_new ();
930
1074
        g_cancellable_cancel (cancellable); /* this should cancel the operation before it even starts, as we haven't run the main loop yet */
931
1075
 
932
1076
        g_main_loop_run (main_loop);
 
1077
 
 
1078
        g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
 
1079
        g_clear_error (&error);
 
1080
 
933
1081
        g_main_loop_unref (main_loop);
934
1082
        g_object_unref (cancellable);
935
1083
        g_object_unref (operation);
968
1116
                g_test_add_data_func ("/calendar/query/own_calendars", service, test_query_own_calendars);
969
1117
                g_test_add_data_func ("/calendar/query/own_calendars_async", service, test_query_own_calendars_async);
970
1118
                g_test_add_data_func ("/calendar/query/events", service, test_query_events);
 
1119
                g_test_add_data_func ("/calendar/query/events_async", service, test_query_events_async);
971
1120
 
972
1121
                g_test_add_data_func ("/calendar/insert/simple", service, test_insert_simple);
 
1122
                g_test_add_data_func ("/calendar/insert/simple/async", service, test_insert_simple_async);
973
1123
 
974
1124
                g_test_add_data_func ("/calendar/acls/get_rules", service, test_acls_get_rules);
975
1125
                g_test_add_data_func ("/calendar/acls/insert_rule", service, test_acls_insert_rule);
985
1135
        g_test_add_func ("/calendar/xml/dates", test_xml_dates);
986
1136
        g_test_add_func ("/calendar/xml/recurrence", test_xml_recurrence);
987
1137
 
 
1138
        g_test_add_func ("/calendar/calendar/escaping", test_calendar_escaping);
 
1139
        g_test_add_func ("/calendar/event/escaping", test_event_escaping);
 
1140
 
988
1141
        g_test_add_func ("/calendar/query/uri", test_query_uri);
989
1142
        g_test_add_func ("/calendar/query/etag", test_query_etag);
990
1143