Adapt libecal to the new ESource API.
[platform/upstream/evolution-data-server.git] / tests / libecal / test-ecal-modify-object.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 #include <stdlib.h>
4 #include <libecal/e-cal.h>
5 #include <libical/ical.h>
6
7 #include "ecal-test-utils.h"
8
9 #define EVENT_SUMMARY "Creation of new test event"
10 #define INITIAL_BEGIN_TIME     "20040109T090000Z"
11 #define INITIAL_BEGIN_TIMEZONE "UTC"
12 #define INITIAL_END_TIME       "20040109T103000"
13 #define INITIAL_END_TIMEZONE   "UTC"
14 #define FINAL_BEGIN_TIME       "20091221T090000Z"
15 #define FINAL_BEGIN_TIMEZONE   "UTC"
16
17 gint
18 main (gint argc,
19       gchar **argv)
20 {
21         ECal *cal;
22         gchar *uri = NULL;
23         ECalComponent *e_component;
24         ECalComponent *e_component_final;
25         icalcomponent *component;
26         icalcomponent *component_final;
27         struct icaltimetype icaltime;
28         gchar *uid;
29
30         g_type_init ();
31
32         cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
33         ecal_test_utils_cal_open (cal, FALSE);
34
35         ecal_test_utils_create_component (cal, INITIAL_BEGIN_TIME,
36                         INITIAL_BEGIN_TIMEZONE, INITIAL_END_TIME,
37                         INITIAL_END_TIMEZONE, EVENT_SUMMARY, &e_component,
38                         &uid);
39         component = e_cal_component_get_icalcomponent (e_component);
40
41         component_final = ecal_test_utils_cal_get_object (cal, uid);
42         ecal_test_utils_cal_assert_objects_equal_shallow (component,
43                         component_final);
44         icalcomponent_free (component_final);
45
46         /* make and commit changes */
47         icaltime = icaltime_from_string (FINAL_BEGIN_TIME);
48         icalcomponent_set_dtstart (component, icaltime);
49         ecal_test_utils_cal_component_set_icalcomponent (e_component,
50                         component);
51         ecal_test_utils_cal_modify_object (cal, component, CALOBJ_MOD_ALL);
52
53         /* verify */
54         component_final = ecal_test_utils_cal_get_object (cal, uid);
55         e_component_final = e_cal_component_new ();
56         ecal_test_utils_cal_component_set_icalcomponent (e_component_final,
57                                 component_final);
58
59         ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
60                         e_component_final);
61
62         g_object_unref (e_component_final);
63         g_free (uid);
64         icalcomponent_free (component);
65
66         return 0;
67 }