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.
This commit is contained in:
Georges Basile Stavracas Neto
2019-05-04 12:05:39 -03:00
parent 28c5a41639
commit 7811b90730
4 changed files with 137 additions and 13 deletions
+74
View File
@@ -0,0 +1,74 @@
/* gcal-stub-calendar.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 "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);
}
+33
View File
@@ -0,0 +1,33 @@
/* gcal-stub-calendar.h
*
* 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
*/
#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
+25 -9
View File
@@ -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)
+5 -4
View File
@@ -18,8 +18,9 @@
#include <glib.h>
#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;
}