diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2019-07-10 19:04:50 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2019-07-13 16:04:30 -0300 |
commit | 371fdbc881e5e92d85a64989eac6a824b151dc52 (patch) | |
tree | ebbed3985bd508a9a4180b6e2ab1d934848cbe6d /tests | |
parent | 2aa9bc1f61c4abbea9735878d3c7ff49be0b3786 (diff) | |
download | gnome-calendar-371fdbc881e5e92d85a64989eac6a824b151dc52.tar.gz |
Introduce new source discoverer
The new source discoverer is a complete overhaul of
the current code. It is async-only, correctly threaded,
and easier to maintain.
A major new feature of this web source discoverer is
that it now pings the server to see if the URL feeds
us back with an iCalendar file.
Furthermore, it continues to use E-D-S WebDAV discovery
functions as a fallback mechanism.
Fixes #380
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gcal-simple-server.c | 2 | ||||
-rw-r--r-- | tests/meson.build | 1 | ||||
-rw-r--r-- | tests/test-discoverer.c | 190 |
3 files changed, 192 insertions, 1 deletions
diff --git a/tests/gcal-simple-server.c b/tests/gcal-simple-server.c index 21ad7db8..15b3f010 100644 --- a/tests/gcal-simple-server.c +++ b/tests/gcal-simple-server.c @@ -88,7 +88,7 @@ static void process_caldav (SoupMessage *message, const gchar *path) { - g_message ("Processing CalDAV"); + g_debug ("Processing CalDAV request"); } diff --git a/tests/meson.build b/tests/meson.build index a45a00ef..ec704dfd 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -33,6 +33,7 @@ libgcal_test_dep = declare_dependency( tests = [ 'server', + 'discoverer', 'event', 'manager', ] diff --git a/tests/test-discoverer.c b/tests/test-discoverer.c new file mode 100644 index 00000000..73ce1016 --- /dev/null +++ b/tests/test-discoverer.c @@ -0,0 +1,190 @@ +/* test-discoverer.c + * + * Copyright 2019 Georges Basile Stavracas Neto <georges.stavracas@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + + +#include <glib.h> +#include <libecal/libecal.h> + +#include "gcal-simple-server.h" +#include "gcal-source-discoverer.h" + +static GcalSimpleServer* +init_server (void) +{ + g_autoptr (GcalSimpleServer) server = NULL; + + server = gcal_simple_server_new (); + gcal_simple_server_start (server); + + return g_steal_pointer (&server); +} + +/*********************************************************************************************************************/ + +static void +discovered_file_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr (GPtrArray) sources = NULL; + g_autoptr (GError) error = NULL; + GMainLoop *mainloop = user_data; + + sources = gcal_discover_sources_from_uri_finish (result, &error); + g_assert_no_error (error); + g_assert_cmpuint (sources->len, ==, 1); + + g_main_loop_quit (mainloop); +} + +static void +discoverer_file (void) +{ + g_autoptr (GcalSimpleServer) server = NULL; + g_autoptr (GMainLoop) mainloop = NULL; + g_autoptr (SoupURI) uri = NULL; + g_autofree gchar *uri_str = NULL; + + server = init_server (); + uri = gcal_simple_server_get_uri (server); + soup_uri_set_path (uri, "/public/calendar"); + + uri_str = soup_uri_to_string (uri, FALSE); + + mainloop = g_main_loop_new (NULL, FALSE); + + gcal_discover_sources_from_uri (uri_str, + NULL, + NULL, + NULL, + discovered_file_cb, + mainloop); + + g_main_loop_run (mainloop); +} + +/*********************************************************************************************************************/ + +static void +discovered_webdav_no_auth_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr (GPtrArray) sources = NULL; + g_autoptr (GError) error = NULL; + GMainLoop *mainloop = user_data; + + sources = gcal_discover_sources_from_uri_finish (result, &error); + g_assert_error (error, GCAL_SOURCE_DISCOVERER_ERROR, GCAL_SOURCE_DISCOVERER_ERROR_UNAUTHORIZED); + + g_main_loop_quit (mainloop); +} + +static void +discoverer_webdav_no_auth (void) +{ + g_autoptr (GcalSimpleServer) server = NULL; + g_autoptr (GMainLoop) mainloop = NULL; + g_autoptr (SoupURI) uri = NULL; + g_autofree gchar *uri_str = NULL; + + server = init_server (); + uri = gcal_simple_server_get_uri (server); + soup_uri_set_path (uri, "/secret-area/calendar"); + + uri_str = soup_uri_to_string (uri, FALSE); + + mainloop = g_main_loop_new (NULL, FALSE); + + gcal_discover_sources_from_uri (uri_str, + NULL, + NULL, + NULL, + discovered_webdav_no_auth_cb, + mainloop); + + g_main_loop_run (mainloop); +} + +/*********************************************************************************************************************/ + +#if 0 + +// TODO: Implement raw CalDAV server in GcalSimpleServer + +static void +discoverer_webdav_auth_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr (GPtrArray) sources = NULL; + g_autoptr (GError) error = NULL; + GMainLoop *mainloop = user_data; + + sources = gcal_discover_sources_from_uri_finish (result, &error); + g_assert_no_error (error); + + g_main_loop_quit (mainloop); +} + +static void +discoverer_webdav_auth (void) +{ + g_autoptr (GcalSimpleServer) server = NULL; + g_autoptr (GMainLoop) mainloop = NULL; + g_autoptr (SoupURI) uri = NULL; + g_autofree gchar *uri_str = NULL; + + server = init_server (); + uri = gcal_simple_server_get_uri (server); + soup_uri_set_path (uri, "/secret-area/dav"); + + uri_str = soup_uri_to_string (uri, FALSE); + + mainloop = g_main_loop_new (NULL, FALSE); + + gcal_discover_sources_from_uri (uri_str, + "feaneron", + "idonotmaintainanything", + NULL, + discoverer_webdav_auth_cb, + mainloop); + + g_main_loop_run (mainloop); +} + +#endif + +/*********************************************************************************************************************/ + +gint +main (gint argc, + gchar *argv[]) +{ + g_setenv ("TZ", "UTC", TRUE); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/discoverer/file", discoverer_file); + g_test_add_func ("/discoverer/webdav/no-auth", discoverer_webdav_no_auth); + + return g_test_run (); +} + |