diff options
author | Milan Crha <mcrha@redhat.com> | 2018-12-03 22:13:15 +0100 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2018-12-03 22:13:15 +0100 |
commit | 5f1d2650d7e49683424782cc41facf28a4e45100 (patch) | |
tree | f2597b1c5f8696a795feeb26ae9adad65184007d /tests | |
parent | 68838b59885d4174270a09cce9b0cd06d94c9e3b (diff) | |
download | evolution-data-server-5f1d2650d7e49683424782cc41facf28a4e45100.tar.gz |
[test-cal-client-get-free-busy] Enhance the test execution
Couple changes in the test:
1) add also a component into the calendar, thus the returned
Free/Busy component is not empty
2) let the sync variant wait for the D-Bus signal with Free/Busy
data again
3) wait for the D-Bus signal in case it's not received in time
of the method execution finish.
Especially the 3) is important, because the D-Bus signal can be delivered
after the method invocation is received, which could break the test.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libecal/client/test-cal-client-get-free-busy.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/libecal/client/test-cal-client-get-free-busy.c b/tests/libecal/client/test-cal-client-get-free-busy.c index c611f1c47..d3949ea83 100644 --- a/tests/libecal/client/test-cal-client-get-free-busy.c +++ b/tests/libecal/client/test-cal-client-get-free-busy.c @@ -94,6 +94,49 @@ teardown_fixture (ETestServerFixture *fixture, } static void +add_component_sync (ECalClient *cal_client) +{ + const gchar *comp_str = + "BEGIN:VEVENT\r\n" + "UID:test-fb-event-1\r\n" + "DTSTAMP:20040212T000000Z\r\n" + "DTSTART:20040213T060000Z\r\n" + "DTEND:20040213T080000Z\r\n" + "SUMMARY:Test event\r\n" + "TRANSP:OPAQUE\r\n" + "CLASS:PUBLIC\r\n" + "CREATED:20040211T080000Z\r\n" + "LAST-MODIFIED:20040211T080000Z\r\n" + "END:VEVENT\r\n"; + icalcomponent *icalcomp; + GError *error = NULL; + + icalcomp = icalcomponent_new_from_string (comp_str); + g_assert_nonnull (icalcomp); + + if (!e_cal_client_create_object_sync (cal_client, icalcomp, NULL, NULL, &error)) + g_error ("Failed to add component: %s", error ? error->message : "Unknown error"); + + icalcomponent_free (icalcomp); + g_clear_error (&error); +} + +static void +wait_for_dbus_signal (GMainLoop *loop) +{ + GMainContext *main_context; + gint retries = 0; + + main_context = g_main_loop_get_context (loop); + + while (!received_free_busy_data && retries < 5) { + retries++; + + g_main_context_iteration (main_context, TRUE); + } +} + +static void free_busy_data_cb (ECalClient *client, const GSList *free_busy, const gchar *func_name) @@ -114,9 +157,13 @@ test_get_free_busy_sync (ETestServerFixture *fixture, cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient); + add_component_sync (cal_client); + /* This is set by the free-busy-data callback */ received_free_busy_data = FALSE; + g_signal_connect (cal_client, "free-busy-data", G_CALLBACK (free_busy_data_cb), (gpointer) G_STRFUNC); + utc = icaltimezone_get_utc_timezone (); start = time_from_isodate ("20040212T000000Z"); end = time_add_day_with_zone (start, 2, utc); @@ -127,6 +174,9 @@ test_get_free_busy_sync (ETestServerFixture *fixture, g_slist_free (users); + wait_for_dbus_signal (fixture->loop); + + g_assert (received_free_busy_data); g_assert (freebusy_data); g_slist_free_full (freebusy_data, g_object_unref); @@ -147,6 +197,8 @@ async_get_free_busy_result_ready (GObject *source_object, if (!e_cal_client_get_free_busy_finish (cal_client, result, &freebusy_data, &error)) g_error ("create object finish: %s", error->message); + wait_for_dbus_signal (loop); + g_assert (received_free_busy_data); g_assert (freebusy_data); @@ -166,6 +218,8 @@ test_get_free_busy_async (ETestServerFixture *fixture, cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient); + add_component_sync (cal_client); + /* This is set by the free-busy-data callback */ received_free_busy_data = FALSE; |