From 7811b90730bc70a7eda6fe5f7f6142f180c89bcd Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sat, 4 May 2019 11:36:53 -0300 Subject: [PATCH] tests: Fix test suite Introduce a new GcalStubCalendar class that essentially removes the ECalClient initialization from GcalCalendar, and use it as part of a new private library consumed by the tests. --- tests/gcal-stub-calendar.c | 74 ++++++++++++++++++++++++++++++++++++++ tests/gcal-stub-calendar.h | 33 +++++++++++++++++ tests/meson.build | 34 +++++++++++++----- tests/test-event.c | 9 ++--- 4 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 tests/gcal-stub-calendar.c create mode 100644 tests/gcal-stub-calendar.h diff --git a/tests/gcal-stub-calendar.c b/tests/gcal-stub-calendar.c new file mode 100644 index 00000000..45ef73ea --- /dev/null +++ b/tests/gcal-stub-calendar.c @@ -0,0 +1,74 @@ +/* gcal-stub-calendar.c + * + * Copyright 2019 Georges Basile Stavracas Neto + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "gcal-stub-calendar.h" + +struct _GcalStubCalendar +{ + GcalCalendar parent; +}; + +static void g_initable_iface_init (GInitableIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GcalStubCalendar, gcal_stub_calendar, GCAL_TYPE_CALENDAR, + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, g_initable_iface_init)) + +/* + * GInitable iface + */ + +static gboolean +gcal_stub_calendar_initable_init (GInitable *initable, + GCancellable *cancellable, + GError **error) +{ + return TRUE; +} + +static void +g_initable_iface_init (GInitableIface *iface) +{ + iface->init = gcal_stub_calendar_initable_init; +} + +static void +gcal_stub_calendar_class_init (GcalStubCalendarClass *klass) +{ +} + +static void +gcal_stub_calendar_init (GcalStubCalendar *self) +{ +} + +GcalCalendar* +gcal_stub_calendar_new (GCancellable *cancellable, + GError **error) +{ + g_autoptr (ESource) source = NULL; + + source = e_source_new_with_uid ("stub", NULL, error); + + return g_initable_new (GCAL_TYPE_STUB_CALENDAR, + cancellable, + error, + "source", source, + NULL); +} diff --git a/tests/gcal-stub-calendar.h b/tests/gcal-stub-calendar.h new file mode 100644 index 00000000..36c2517d --- /dev/null +++ b/tests/gcal-stub-calendar.h @@ -0,0 +1,33 @@ +/* gcal-stub-calendar.h + * + * Copyright 2019 Georges Basile Stavracas Neto + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "gcal-calendar.h" + +G_BEGIN_DECLS + +#define GCAL_TYPE_STUB_CALENDAR (gcal_stub_calendar_get_type()) +G_DECLARE_FINAL_TYPE (GcalStubCalendar, gcal_stub_calendar, GCAL, STUB_CALENDAR, GcalCalendar) + +GcalCalendar* gcal_stub_calendar_new (GCancellable *cancellable, + GError **error); + +G_END_DECLS diff --git a/tests/meson.build b/tests/meson.build index 32bec10a..f0d6cb74 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,6 +1,3 @@ -test_deps = gcal_deps + [ libgcal_dep ] - - test_env = [ 'G_TEST_SRCDIR=' + meson.current_source_dir(), 'G_TEST_BUILDDIR=' + meson.current_build_dir(), @@ -11,6 +8,27 @@ test_env = [ test_cflags = '-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.source_root(), 'data')) +################ +# libgcal-test # +################ + +sources = files( + 'gcal-stub-calendar.c', +) + +libgcal_test = shared_library( + 'gcal-test-private', + sources: sources, + include_directories: calendar_incs, + dependencies: libgcal_dep, + install: false, +) + +libgcal_test_dep = declare_dependency( + link_with: libgcal_test, + dependencies: libgcal_dep, + include_directories: calendar_incs, +) ######### # Event # @@ -19,9 +37,8 @@ test_cflags = '-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.source_root(), 'da test_event = executable( 'test-event', ['test-event.c', compiled_schemas], - c_args: test_cflags, - dependencies: test_deps, - include_directories: calendar_incs, + c_args: test_cflags, + dependencies: libgcal_test_dep, ) test('test-event', test_event, env: test_env) @@ -34,9 +51,8 @@ test('test-event', test_event, env: test_env) test_manager = executable( 'test-manager', ['test-manager.c', compiled_schemas], - c_args: test_cflags, - dependencies: test_deps, - include_directories: calendar_incs, + c_args: test_cflags, + dependencies: libgcal_test_dep, ) test('test-manager', test_manager, env: test_env) diff --git a/tests/test-event.c b/tests/test-event.c index 53fcd0bf..45c35f60 100644 --- a/tests/test-event.c +++ b/tests/test-event.c @@ -18,8 +18,9 @@ #include -#include "utils/gcal-utils.h" #include "gcal-event.h" +#include "gcal-stub-calendar.h" +#include "gcal-utils.h" #define STUB_EVENT "BEGIN:VEVENT\n" \ "SUMMARY:Stub event\n" \ @@ -55,12 +56,12 @@ create_event_for_string (const gchar *string, GError **error) { g_autoptr (ECalComponent) component = NULL; - g_autoptr (ESource) source = NULL; + g_autoptr (GcalCalendar) calendar = NULL; - source = e_source_new_with_uid ("stub", NULL, error); component = e_cal_component_new_from_string (string); + calendar = gcal_stub_calendar_new (NULL, error); - return component ? gcal_event_new (source, component, error) : NULL; + return component ? gcal_event_new (calendar, component, error) : NULL; }