mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-04 20:07:36 +00:00
Add initial unit tests for Provider
Largely cribbed from libhandy, thanks due to Guido.
This commit is contained in:
parent
0a7330a7de
commit
b17ee0c16e
6 changed files with 187 additions and 19 deletions
5
debian/rules
vendored
5
debian/rules
vendored
|
@ -4,3 +4,8 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
|||
|
||||
%:
|
||||
dh $@ -- -B_build
|
||||
|
||||
override_dh_auto_test:
|
||||
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
|
||||
xvfb-run ninja -C _build test
|
||||
endif
|
||||
|
|
|
@ -31,3 +31,4 @@ subdir('libgdbofono')
|
|||
subdir('src')
|
||||
subdir('doc')
|
||||
subdir('data')
|
||||
subdir('tests')
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
option('gtk_doc',
|
||||
type: 'boolean', value: false,
|
||||
description: 'Whether to generate the API reference for Calls')
|
||||
|
||||
option('tests',
|
||||
type: 'boolean', value: true,
|
||||
description: 'Whether to compile unit tests')
|
||||
|
|
|
@ -28,25 +28,30 @@ calls_deps = [ dependency('gobject-2.0'),
|
|||
dependency('libhandy-0.0'),
|
||||
]
|
||||
|
||||
enum_headers = ['calls-call.h']
|
||||
sources = ['calls-message-source.c', 'calls-message-source.h',
|
||||
'calls-call.c',
|
||||
'calls-origin.c', 'calls-origin.h',
|
||||
'calls-provider.c', 'calls-provider.h',
|
||||
'calls-ofono-call.c', 'calls-ofono-call.h',
|
||||
'calls-ofono-origin.c', 'calls-ofono-origin.h',
|
||||
'calls-ofono-provider.c', 'calls-ofono-provider.h',
|
||||
'calls-party.c', 'calls-party.h',
|
||||
'calls-call-data.c', 'calls-call-data.h',
|
||||
'calls-call-holder.c', 'calls-call-holder.h',
|
||||
'calls-call-display.c', 'calls-call-display.h',
|
||||
'calls-call-selector-item.c', 'calls-call-selector-item.h',
|
||||
'calls-main-window.c', 'calls-main-window.h',
|
||||
'util.c', 'util.h',
|
||||
'main.c'
|
||||
]
|
||||
calls_sources = ['calls-message-source.c', 'calls-message-source.h',
|
||||
'calls-call.c',
|
||||
'calls-origin.c', 'calls-origin.h',
|
||||
'calls-provider.c', 'calls-provider.h',
|
||||
'calls-ofono-call.c', 'calls-ofono-call.h',
|
||||
'calls-ofono-origin.c', 'calls-ofono-origin.h',
|
||||
'calls-ofono-provider.c', 'calls-ofono-provider.h',
|
||||
'calls-party.c', 'calls-party.h',
|
||||
'calls-call-data.c', 'calls-call-data.h',
|
||||
'calls-call-holder.c', 'calls-call-holder.h',
|
||||
'calls-call-display.c', 'calls-call-display.h',
|
||||
'calls-call-selector-item.c', 'calls-call-selector-item.h',
|
||||
'calls-main-window.c', 'calls-main-window.h',
|
||||
'util.c', 'util.h',
|
||||
]
|
||||
|
||||
enum_sources = gnome.mkenums_simple('enum-types', sources : enum_headers)
|
||||
calls_dummy_sources = ['calls-dummy-call.c', 'calls-dummy-call.h',
|
||||
'calls-dummy-origin.c', 'calls-dummy-origin.h',
|
||||
'calls-dummy-provider.c', 'calls-dummy-provider.h',
|
||||
]
|
||||
|
||||
calls_enum_headers = ['calls-call.h']
|
||||
calls_enum_sources = gnome.mkenums_simple('enum-types',
|
||||
sources : calls_enum_headers)
|
||||
|
||||
calls_resources = gnome.compile_resources(
|
||||
'calls-resources',
|
||||
|
@ -55,7 +60,8 @@ calls_resources = gnome.compile_resources(
|
|||
c_name: 'call',
|
||||
)
|
||||
|
||||
executable('calls', sources, enum_sources, calls_resources,
|
||||
executable('calls',
|
||||
calls_sources, calls_enum_sources, calls_resources, 'main.c',
|
||||
dependencies : calls_deps,
|
||||
link_with : gdbofono_lib,
|
||||
include_directories : include_directories('..'),
|
||||
|
|
46
tests/meson.build
Normal file
46
tests/meson.build
Normal file
|
@ -0,0 +1,46 @@
|
|||
if get_option('tests')
|
||||
|
||||
test_env = [
|
||||
'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
|
||||
'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
|
||||
'G_DEBUG=gc-friendly,fatal-warnings',
|
||||
'GSETTINGS_BACKEND=memory',
|
||||
'PYTHONDONTWRITEBYTECODE=yes',
|
||||
'MALLOC_CHECK_=2',
|
||||
]
|
||||
|
||||
test_cflags = [
|
||||
'-fPIE',
|
||||
]
|
||||
|
||||
test_link_args = [
|
||||
'-fPIC',
|
||||
]
|
||||
|
||||
test_names = [
|
||||
'test-provider',
|
||||
]
|
||||
|
||||
test_calls_source_arrays = [ calls_sources, calls_dummy_sources ]
|
||||
|
||||
test_calls_sources = []
|
||||
foreach source_array : test_calls_source_arrays
|
||||
foreach source : source_array
|
||||
test_calls_sources += join_paths('..', 'src', source)
|
||||
endforeach
|
||||
endforeach
|
||||
|
||||
foreach test_name : test_names
|
||||
t = executable(test_name, test_name + '.c',
|
||||
test_calls_sources, calls_enum_sources, calls_resources,
|
||||
c_args : test_cflags,
|
||||
link_args: test_link_args,
|
||||
link_with : gdbofono_lib,
|
||||
dependencies: calls_deps,
|
||||
include_directories : include_directories('..',
|
||||
join_paths('..', 'src')),
|
||||
)
|
||||
test(test_name, t, env: test_env)
|
||||
endforeach
|
||||
|
||||
endif
|
106
tests/test-provider.c
Normal file
106
tests/test-provider.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Purism SPC
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*/
|
||||
|
||||
#include "calls-dummy-provider.h"
|
||||
#include "calls-provider.h"
|
||||
#include "calls-origin.h"
|
||||
#include "calls-message-source.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
CallsDummyProvider *dummy_provider;
|
||||
} Fixture;
|
||||
|
||||
|
||||
static void
|
||||
test_dummy_provider_set_up (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
fixture->dummy_provider = calls_dummy_provider_new ();
|
||||
calls_dummy_provider_add_origin (fixture->dummy_provider,
|
||||
"Test origin 1");
|
||||
calls_dummy_provider_add_origin (fixture->dummy_provider,
|
||||
"Test origin 2");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_dummy_provider_tear_down (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
g_clear_object (&fixture->dummy_provider);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_dummy_provider_object (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
g_assert_true (G_IS_OBJECT (fixture->dummy_provider));
|
||||
g_assert_true (CALLS_IS_MESSAGE_SOURCE (fixture->dummy_provider));
|
||||
g_assert_true (CALLS_IS_PROVIDER (fixture->dummy_provider));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_dummy_provider_get_name (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
CallsProvider *provider;
|
||||
const gchar *name;
|
||||
|
||||
provider = CALLS_PROVIDER (fixture->dummy_provider);
|
||||
|
||||
name = calls_provider_get_name (provider);
|
||||
g_assert_nonnull (name);
|
||||
g_assert_cmpuint (strlen (name), >, 0U);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_dummy_provider_get_origins (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
GList *origins, *node;
|
||||
|
||||
origins = calls_provider_get_origins
|
||||
(CALLS_PROVIDER (fixture->dummy_provider));
|
||||
|
||||
g_assert_cmpuint (g_list_length (origins), ==, 2);
|
||||
|
||||
for (node = origins; node; node = node->next)
|
||||
{
|
||||
g_assert_true (G_IS_OBJECT (node->data));
|
||||
g_assert_true (CALLS_IS_ORIGIN (node->data));
|
||||
}
|
||||
|
||||
g_list_free (origins);
|
||||
}
|
||||
|
||||
|
||||
gint
|
||||
main (gint argc,
|
||||
gchar *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
|
||||
#define add_test(name) \
|
||||
g_test_add ("/Calls/Provider/" #name, Fixture, NULL, \
|
||||
test_dummy_provider_set_up, \
|
||||
test_dummy_provider_##name, \
|
||||
test_dummy_provider_tear_down); \
|
||||
|
||||
add_test(object);
|
||||
add_test(get_name);
|
||||
add_test(get_origins);
|
||||
|
||||
#undef add_test
|
||||
|
||||
return g_test_run();
|
||||
}
|
Loading…
Reference in a new issue