Commit c30fa308 authored by Christian Kellner's avatar Christian Kellner

test: exported: check flags property get/set

Test that getting and setting flag properties works; this involves
auto converting them in BoltExported from and to strings, because
flags are transmitted as strings over the wire.
parent f43360da
Pipeline #8780 passed with stage
in 8 minutes and 26 seconds
......@@ -371,7 +371,8 @@ test_enums = gnome.mkenums_simple(
tests = [
['test-auth', [libdaemon]],
['test-common', [], test_enums],
['test-exported', [libdaemon], [test_resources]],
['test-exported', [libdaemon], [test_resources,
test_enums]],
['test-logging', [libdaemon]],
['test-store', [libdaemon]],
['test-journal', [libdaemon]]
......
......@@ -10,6 +10,7 @@
<property name='Bool' type='b' access='readwrite' />
<property name='Object' type='s' access='read' />
<property name='Security' type='s' access='readwrite' />
<property name='KittMode' type='s' access='readwrite' />
<method name='Ping'>
<arg type='s' name='result' direction='out' />
</method>
......
......@@ -26,6 +26,7 @@
#include "bolt-error.h"
#include "bolt-str.h"
#include "test-enums.h"
#include "bolt-test-resources.h"
#include <glib.h>
......@@ -143,23 +144,29 @@ static gboolean handle_set_security (BoltExported *obj,
const GValue *value,
GError **error);
static gboolean handle_set_kitt (BoltExported *obj,
const char *name,
const GValue *value,
GError **error);
struct _BtExported
{
BoltExported parent;
BoltExported parent;
char *object_id;
char *object_id;
char *str;
GError *setter_err;
char *str;
GError *setter_err;
gboolean prop_bool;
gboolean prop_bool;
BtId *prop_obj;
BtId *prop_obj;
gboolean authorize_methods;
gboolean authorize_properties;
gboolean authorize_methods;
gboolean authorize_properties;
BoltSecurity security;
BoltSecurity security;
BoltKittFlags kitt;
};
G_DEFINE_TYPE (BtExported, bt_exported, BOLT_TYPE_EXPORTED);
......@@ -177,6 +184,7 @@ enum {
PROP_OBJECT,
PROP_SECURITY,
PROP_KITT,
PROP_LAST
};
......@@ -237,6 +245,10 @@ bt_exported_get_property (GObject *object,
g_value_set_enum (value, be->security);
break;
case PROP_KITT:
g_value_set_flags (value, be->kitt);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -267,6 +279,10 @@ bt_exported_set_property (GObject *object,
be->security = g_value_get_enum (value);
break;
case PROP_KITT:
be->kitt = g_value_get_flags (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -333,6 +349,14 @@ bt_exported_class_init (BtExportedClass *klass)
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
props[PROP_KITT] =
g_param_spec_flags ("kitt", "KittMode", NULL,
BOLT_TYPE_KITT_FLAGS,
BOLT_KITT_DISABLED,
G_PARAM_READWRITE |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
g_object_class_install_properties (gobject_class,
PROP_LAST,
props);
......@@ -348,6 +372,10 @@ bt_exported_class_init (BtExportedClass *klass)
bolt_exported_class_property_setter (exported_class,
props[PROP_SECURITY],
handle_set_security);
bolt_exported_class_property_setter (exported_class,
props[PROP_KITT],
handle_set_kitt);
}
static gboolean
......@@ -473,6 +501,17 @@ handle_set_security (BoltExported *obj,
return TRUE;
}
static gboolean
handle_set_kitt (BoltExported *obj,
const char *name,
const GValue *value,
GError **error)
{
BtExported *be = BT_EXPORTED (obj);
be->kitt = g_value_get_flags (value);
return TRUE;
}
/* *********** */
......@@ -1102,6 +1141,94 @@ test_exported_props_enums (TestExported *tt, gconstpointer data)
g_assert_cmpint (tt->obj->security, ==, BOLT_SECURITY_USER);
}
static void
test_exported_props_flags (TestExported *tt, gconstpointer data)
{
g_autoptr(CallCtx) ctx = NULL;
g_autoptr(GVariant) v = NULL;
g_autofree char *want = NULL;
g_autofree char *ref = NULL;
const char *have = NULL;
BoltKittFlags kf = BOLT_KITT_ENABLED | BOLT_KITT_TURBO_BOOST;
ctx = call_ctx_new ();
tt->obj->kitt = BOLT_KITT_DEFAULT;
/* valid property value, should be converted to string */
g_dbus_connection_call (tt->bus,
tt->bus_name,
tt->obj_path,
"org.freedesktop.DBus.Properties",
"Get",
g_variant_new ("(ss)",
DBUS_IFACE,
"KittMode"),
G_VARIANT_TYPE ("(v)"),
G_DBUS_CALL_FLAGS_NONE,
2000,
NULL,
dbus_call_done,
ctx);
call_ctx_run (ctx);
g_assert_no_error (ctx->error);
g_assert_nonnull (ctx->data);
g_variant_get (ctx->data, "(v)", &v);
have = g_variant_get_string (v, NULL);
want = bolt_flags_to_string (BOLT_TYPE_KITT_FLAGS,
tt->obj->kitt,
NULL);
g_assert_cmpstr (have, ==, want);
/* setter */
bt_exported_install_property_authorizer (tt->obj);
tt->obj->authorize_properties = TRUE;
ref = bolt_flags_to_string (BOLT_TYPE_KITT_FLAGS, kf, NULL);
g_dbus_connection_call (tt->bus,
tt->bus_name,
tt->obj_path,
"org.freedesktop.DBus.Properties",
"Set",
g_variant_new ("(ssv)",
DBUS_IFACE,
"KittMode",
g_variant_new ("s", ref)),
NULL,
G_DBUS_CALL_FLAGS_NONE,
2000,
NULL,
dbus_call_done,
ctx);
call_ctx_run (ctx);
g_assert_no_error (ctx->error);
g_assert_cmpint (tt->obj->kitt, ==, kf);
/* setter with invalid argument */
g_dbus_connection_call (tt->bus,
tt->bus_name,
tt->obj_path,
"org.freedesktop.DBus.Properties",
"Set",
g_variant_new ("(ssv)",
DBUS_IFACE,
"KittMode",
g_variant_new ("s", "invalid | foobar")),
NULL,
G_DBUS_CALL_FLAGS_NONE,
2000,
NULL,
dbus_call_done,
ctx);
call_ctx_run (ctx);
g_assert_error (ctx->error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
}
static void
test_exported_props_object (TestExported *tt, gconstpointer data)
{
......@@ -1209,6 +1336,13 @@ main (int argc, char **argv)
test_exported_props_enums,
test_exported_teardown);
g_test_add ("/exported/props/flags",
TestExported,
NULL,
test_exported_setup,
test_exported_props_flags,
test_exported_teardown);
g_test_add ("/exported/props/object",
TestExported,
NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment