tests: Add comprehensive tests for libeos-parental-controls

These test get/set behaviour of EpcAppFilter, GAppInfo support, and
various error handling paths and corner cases.

With these tests, coverage of app-filter.c is:
 • Lines: 97%
 • Functions: 100%
 • Branches: 57.5%

The branch coverage is not correctly reported, as it factors in the
failure branches for g_return_if_fail() precondition assertions, which
we deliberately do not test. With those branches manually excluded,
branch coverage is around 89% instead.

This adds libglib-testing as a subproject dependency, for its
GtDBusQueue. It adds gio-unix-2.0 as a dependency of the app-filter
tests, in order to be able to construct GDesktopAppInfos.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://phabricator.endlessm.com/T24004
This commit is contained in:
Philip Withnall 2018-12-10 15:09:51 +00:00
parent b932f443d5
commit a2c2965d25
6 changed files with 1205 additions and 1 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "subprojects/libglib-testing"]
path = subprojects/libglib-testing
url = https://gitlab.gnome.org/pwithnall/libglib-testing.git

View File

@ -0,0 +1,138 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2018 Endless Mobile, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
* - Philip Withnall <withnall@endlessm.com>
*/
#pragma once
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
G_BEGIN_DECLS
/* Static definition of the AppFilter interface on org.freedesktop.Accounts.
* FIXME: Once we can depend on a new enough version of GLib, generate this
* from introspection XML using `gdbus-codegen --interface-info-{header,body}`. */
static const GDBusPropertyInfo app_filter_property_app_filter =
{
.ref_count = -1, /* static */
.name = (gchar *) "AppFilter",
.signature = (gchar *) "(bas)",
.flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
.annotations = NULL,
};
static const GDBusPropertyInfo app_filter_property_oars_filter =
{
.ref_count = -1, /* static */
.name = (gchar *) "OarsFilter",
.signature = (gchar *) "(sa{ss})",
.flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
.annotations = NULL,
};
static const GDBusPropertyInfo app_filter_property_allow_user_installation =
{
.ref_count = -1, /* static */
.name = (gchar *) "AllowUserInstallation",
.signature = (gchar *) "b",
.flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
.annotations = NULL,
};
static const GDBusPropertyInfo app_filter_property_allow_system_installation =
{
.ref_count = -1, /* static */
.name = (gchar *) "AllowSystemInstallation",
.signature = (gchar *) "b",
.flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
.annotations = NULL,
};
static const GDBusPropertyInfo *app_filter_properties[] =
{
(GDBusPropertyInfo *) &app_filter_property_app_filter,
(GDBusPropertyInfo *) &app_filter_property_oars_filter,
(GDBusPropertyInfo *) &app_filter_property_allow_user_installation,
(GDBusPropertyInfo *) &app_filter_property_allow_system_installation,
NULL,
};
static const GDBusInterfaceInfo app_filter_interface_info =
{
.ref_count = -1, /* static */
.name = (gchar *) "com.endlessm.ParentalControls.AppFilter",
.methods = NULL,
.signals = NULL,
.properties = (GDBusPropertyInfo **) &app_filter_properties,
.annotations = NULL,
};
static const GDBusArgInfo accounts_method_find_user_by_id_arg_user_id =
{
.ref_count = -1, /* static */
.name = (gchar *) "UserId",
.signature = (gchar *) "x",
.annotations = NULL,
};
static const GDBusArgInfo accounts_method_find_user_by_id_arg_object_path =
{
.ref_count = -1, /* static */
.name = (gchar *) "ObjectPath",
.signature = (gchar *) "o",
.annotations = NULL,
};
static const GDBusArgInfo *accounts_method_find_user_by_id_in_args[] =
{
(GDBusArgInfo *) &accounts_method_find_user_by_id_arg_user_id,
NULL,
};
static const GDBusArgInfo *accounts_method_find_user_by_id_out_args[] =
{
(GDBusArgInfo *) &accounts_method_find_user_by_id_arg_object_path,
NULL,
};
static const GDBusMethodInfo accounts_method_find_user_by_id =
{
.ref_count = -1, /* static */
.name = (gchar *) "FindUserById",
.in_args = (GDBusArgInfo **) &accounts_method_find_user_by_id_in_args,
.out_args = (GDBusArgInfo **) &accounts_method_find_user_by_id_out_args,
.annotations = NULL,
};
static const GDBusMethodInfo *accounts_methods[] =
{
(GDBusMethodInfo *) &accounts_method_find_user_by_id,
NULL,
};
static const GDBusInterfaceInfo accounts_interface_info =
{
.ref_count = -1, /* static */
.name = (gchar *) "org.freedesktop.Accounts",
.methods = (GDBusMethodInfo **) &accounts_methods,
.signals = NULL,
.properties = NULL,
.annotations = NULL,
};
G_END_DECLS

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,10 @@
deps = [
dependency('gio-2.0', version: '>= 2.44'),
dependency('gio-unix-2.0', version: '>= 2.44'),
dependency('glib-2.0', version: '>= 2.54.2'),
dependency('gobject-2.0', version: '>= 2.44'),
libeos_parental_controls_dep,
libglib_testing_dep,
]
envs = test_env + [
@ -11,7 +13,7 @@ envs = test_env + [
]
test_programs = [
['app-filter', [], deps],
['app-filter', ['accounts-service-iface.h'], deps],
]
installed_tests_metadir = join_paths(datadir, 'installed-tests',

View File

@ -33,6 +33,9 @@ polkit_gobject = dependency('polkit-gobject-1')
polkitpolicydir = polkit_gobject.get_pkgconfig_variable('policydir',
define_variable: ['prefix', prefix])
libglib_testing = subproject('libglib-testing')
libglib_testing_dep = libglib_testing.get_variable('libglib_testing_dep')
config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name())
configure_file(

@ -0,0 +1 @@
Subproject commit a2ec2038047588fe5fe722e5e27e9551c1c6d753