static void local_record_from_uid (EMemoLocalRecord *local, const char *uid, EMemoConduitContext *ctxt) { ECalComponent *comp; icalcomponent *icalcomp; GError *error = NULL; g_assert(local!=NULL); LOG(g_message("local_record_from_uid\n")); if (e_cal_get_object (ctxt->client, uid, NULL, &icalcomp, &error)) { comp = e_cal_component_new (); if (!e_cal_component_set_icalcomponent (comp, icalcomp)) { g_object_unref (comp); icalcomponent_free (icalcomp); return; } local_record_from_comp (local, comp, ctxt); g_object_unref (comp); } else if (error->code == E_CALENDAR_STATUS_OBJECT_NOT_FOUND) { comp = e_cal_component_new (); e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL); e_cal_component_set_uid (comp, uid); local_record_from_comp (local, comp, ctxt); g_object_unref (comp); } else { INFO ("Object did not exist"); } g_clear_error (&error); }
static const gchar * test_object_modification (ECal *client, gchar *uid) { const gchar *summary = "This summary was modified"; icalcomponent *icalcomp, *icalcomp_modified; gboolean compare; GError *error = NULL; if (!e_cal_get_object (client, uid, NULL, &icalcomp, &error)) { cl_printf (client, "Test Modify object : Could not get the object: %s\n", error->message); g_free (uid); return error->message; } /* Modify one property of the icalcomp and save it. * Now retrieve it and check the field. */ icalcomponent_set_summary (icalcomp, summary); if (!e_cal_modify_object (client, icalcomp, CALOBJ_MOD_THIS, &error)) { cl_printf (client, "Test Modify object : Could not modify the object: %s\n", error->message); g_free (uid); g_free (icalcomp); return error->message; } if (!e_cal_get_object (client, uid, NULL, &icalcomp_modified, &error)) { cl_printf (client, "Test Modify object : Could not get the modified object: %s\n", error->message); g_free (uid); g_free (icalcomp); return "Test Object Creation failed"; } compare = !strcmp ( icalcomponent_get_summary (icalcomp_modified), summary); g_free (uid); g_free (icalcomp); g_free (icalcomp_modified); mu_assert ("Test Modify object : Modification failed\n", compare); return NULL; }
ECalComponent * evo_cal_source_get_object(ECal *ecal, const char *uid, const char *rid) { ECalComponent *comp = NULL; icalcomponent *icalcomp = NULL; GError *error = NULL; if (e_cal_get_object (ecal, uid, rid, &icalcomp, &error)) { comp = e_cal_component_new (); if (!e_cal_component_set_icalcomponent (comp, icalcomp)) { g_object_unref (comp); icalcomponent_free (icalcomp); } } else { g_warning("Could not find object (uid: %s): %s\n", uid, error ? error->message : "None"); g_clear_error (&error); } return comp; }
static const gchar * test_get_object (ECal *client) { const gchar *uid = "20040213T055519Z-15802-500-1-3@testcal"; gchar *actual; icalcomponent *icalcomp; gboolean compare; GError *error = NULL; if (!e_cal_get_object (client, uid, NULL, &icalcomp, &error)) { cl_printf (client, "Test Get object : Could not get the object: %s\n", error->message); return error->message; } actual = icalcomponent_as_ical_string_r (icalcomp); compare = !strcmp (actual, EXPECTED); g_free (actual); mu_assert ("Test : get_object does not match the expected output", compare); return NULL; }
static gchar * test_object_removal (ECal *client) { gchar *uid; ECalComponent *comp; icalcomponent *icalcomp; gboolean compare = 1; GError *error = NULL; comp = e_cal_component_new (); e_cal_component_commit_sequence (comp); icalcomp = e_cal_component_get_icalcomponent (comp); if (!e_cal_create_object (client, icalcomp, &uid, &error)) { cl_printf (client, "Test object removal - Object creation: %s\n", error->message); g_object_unref (comp); g_object_unref (icalcomp); return "Test Object Removal failed\n"; } if (!e_cal_remove_object (client, uid, &error)) { cl_printf (client, "Test object removal - Could not remove the object\n"); g_free (uid); g_object_unref (comp); g_object_unref (icalcomp); return "Test Object Removal failed\n"; } compare = e_cal_get_object (client, uid, NULL, &icalcomp, &error); g_free (uid); g_object_unref (comp); g_object_unref (icalcomp); mu_assert ("Test object removal - Failed\n", compare); return NULL; }
static const gchar * test_object_creation (ECal *client, gchar **uid) { ECalComponent *comp, *comp_retrieved; icalcomponent *icalcomp, *icalcomp_retrieved; struct icaltimetype tt; ECalComponentText text; ECalComponentDateTime dt; ECalComponentTransparency transp; gboolean compare; GError *error = NULL; comp = e_cal_component_new (); /* set fields */ e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT); text.value = "Creation of new test event"; text.altrep = NULL; e_cal_component_set_summary (comp, &text); tt = icaltime_from_string ("20040109T090000Z"); dt.value = &tt; dt.tzid ="UTC"; e_cal_component_set_dtstart (comp, &dt); tt = icaltime_from_string ("20040109T103000"); dt.value = &tt; dt.tzid ="UTC"; e_cal_component_set_dtend (comp, &dt); e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE); e_cal_component_commit_sequence (comp); icalcomp = e_cal_component_get_icalcomponent (comp); if (!e_cal_create_object (client, icalcomp, uid, &error)) { cl_printf (client, "Object creation: %s\n", error->message); g_free (comp); g_free (icalcomp); return "Test Object Creation failed"; } e_cal_component_commit_sequence (comp); if (!e_cal_get_object (client, *uid, NULL, &icalcomp_retrieved, &error)) { cl_printf (client, "Object retrieval: %s\n", error->message); g_free (uid); g_free (comp); g_free (icalcomp); return "Test Object Creation failed"; } comp_retrieved = e_cal_component_new (); if (!e_cal_component_set_icalcomponent (comp_retrieved, icalcomp_retrieved)) { cl_printf (client, "Could not set icalcomponent\n"); g_free (uid); g_free (comp); g_free (icalcomp); g_free (icalcomp_retrieved); return "Test Object Creation failed"; } /* Dumping icalcomp into a string is not useful as the retrieved object * has some generated information like timestamps. We compare * member values we set during creation*/ compare = e_cal_component_event_dates_match (comp, comp_retrieved); if (compare) { e_cal_component_get_transparency (comp_retrieved, &transp); compare = (transp == E_CAL_COMPONENT_TRANSP_OPAQUE); } g_free (comp_retrieved); g_free (comp); g_free (icalcomp); g_free (icalcomp_retrieved); mu_assert ("Test Object creation : Created object does not match retrieved data\n", compare); return NULL; }