2020-08-31 16:16:07 +03:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2020 Collabora Ltd.
|
|
|
|
|
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "../common/base-test-fixture.h"
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
WpBaseTestFixture base;
|
|
|
|
|
|
|
|
|
|
WpObjectManager *export_om;
|
|
|
|
|
WpObjectManager *proxy_om;
|
|
|
|
|
|
|
|
|
|
WpMetadata *impl_metadata;
|
|
|
|
|
WpMetadata *proxy_metadata;
|
|
|
|
|
|
|
|
|
|
gint n_events;
|
|
|
|
|
|
|
|
|
|
} TestFixture;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_setup (TestFixture *self, gconstpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
wp_base_test_fixture_setup (&self->base, WP_BASE_TEST_FLAG_CLIENT_CORE);
|
|
|
|
|
self->export_om = wp_object_manager_new ();
|
|
|
|
|
self->proxy_om = wp_object_manager_new ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_teardown (TestFixture *self, gconstpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
g_clear_object (&self->proxy_om);
|
|
|
|
|
g_clear_object (&self->export_om);
|
|
|
|
|
wp_base_test_fixture_teardown (&self->base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_basic_exported_object_added (WpObjectManager *om,
|
|
|
|
|
WpMetadata *metadata, TestFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("exported object added");
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_IMPL_METADATA (metadata));
|
|
|
|
|
|
|
|
|
|
g_assert_null (fixture->impl_metadata);
|
|
|
|
|
fixture->impl_metadata = WP_METADATA (metadata);
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 3)
|
|
|
|
|
g_main_loop_quit (fixture->base.loop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_basic_exported_object_removed (WpObjectManager *om,
|
|
|
|
|
WpMetadata *metadata, TestFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("exported object removed");
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_IMPL_METADATA (metadata));
|
|
|
|
|
|
|
|
|
|
g_assert_nonnull (fixture->impl_metadata);
|
|
|
|
|
fixture->impl_metadata = NULL;
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 2)
|
|
|
|
|
g_main_loop_quit (fixture->base.loop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_basic_proxy_object_added (WpObjectManager *om,
|
|
|
|
|
WpMetadata *metadata, TestFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("proxy object added");
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_METADATA (metadata));
|
|
|
|
|
|
|
|
|
|
g_assert_null (fixture->proxy_metadata);
|
|
|
|
|
fixture->proxy_metadata = WP_METADATA (metadata);
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 3)
|
|
|
|
|
g_main_loop_quit (fixture->base.loop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_basic_proxy_object_removed (WpObjectManager *om,
|
|
|
|
|
WpMetadata *metadata, TestFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("proxy object removed");
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_METADATA (metadata));
|
|
|
|
|
|
|
|
|
|
g_assert_nonnull (fixture->proxy_metadata);
|
|
|
|
|
fixture->proxy_metadata = NULL;
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 2)
|
|
|
|
|
g_main_loop_quit (fixture->base.loop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-11-13 13:40:11 +02:00
|
|
|
test_metadata_basic_export_done (WpObject * metadata, GAsyncResult * res,
|
2020-08-31 16:16:07 +03:00
|
|
|
TestFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
|
|
|
|
|
g_debug ("export done");
|
|
|
|
|
|
2020-11-13 13:40:11 +02:00
|
|
|
g_assert_true (wp_object_activate_finish (metadata, res, &error));
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_IMPL_METADATA (metadata));
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 3)
|
|
|
|
|
g_main_loop_quit (fixture->base.loop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_basic_changed (WpMetadata *metadata, guint32 subject,
|
|
|
|
|
const gchar *key, const gchar *type, const gchar *value,
|
|
|
|
|
TestFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("changed: %u %s", subject, key);
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_METADATA (metadata));
|
|
|
|
|
g_assert_cmpuint (subject, !=, PW_ID_ANY);
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 4)
|
|
|
|
|
g_main_loop_quit (fixture->base.loop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_metadata_basic (TestFixture *fixture, gconstpointer data)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpMetadata) metadata = NULL;
|
|
|
|
|
|
|
|
|
|
/* set up the export side */
|
|
|
|
|
g_signal_connect (fixture->export_om, "object_added",
|
|
|
|
|
(GCallback) test_metadata_basic_exported_object_added, fixture);
|
|
|
|
|
g_signal_connect (fixture->export_om, "object-removed",
|
|
|
|
|
(GCallback) test_metadata_basic_exported_object_removed, fixture);
|
2021-06-18 15:30:55 +03:00
|
|
|
wp_object_manager_add_interest (fixture->export_om, WP_TYPE_IMPL_METADATA,
|
|
|
|
|
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "metadata.name", "=s", "default",
|
|
|
|
|
NULL);
|
2020-11-13 13:40:11 +02:00
|
|
|
wp_object_manager_request_object_features (fixture->export_om,
|
|
|
|
|
WP_TYPE_IMPL_METADATA, WP_OBJECT_FEATURES_ALL);
|
2020-08-31 16:16:07 +03:00
|
|
|
wp_core_install_object_manager (fixture->base.core, fixture->export_om);
|
|
|
|
|
|
|
|
|
|
/* set up the proxy side */
|
|
|
|
|
g_signal_connect (fixture->proxy_om, "object_added",
|
|
|
|
|
(GCallback) test_metadata_basic_proxy_object_added, fixture);
|
|
|
|
|
g_signal_connect (fixture->proxy_om, "object-removed",
|
|
|
|
|
(GCallback) test_metadata_basic_proxy_object_removed, fixture);
|
2021-06-18 15:30:55 +03:00
|
|
|
wp_object_manager_add_interest (fixture->proxy_om, WP_TYPE_METADATA,
|
|
|
|
|
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "metadata.name", "=s", "default",
|
|
|
|
|
NULL);
|
2020-11-13 13:40:11 +02:00
|
|
|
wp_object_manager_request_object_features (fixture->proxy_om,
|
|
|
|
|
WP_TYPE_METADATA, WP_OBJECT_FEATURES_ALL);
|
2020-08-31 16:16:07 +03:00
|
|
|
wp_core_install_object_manager (fixture->base.client_core, fixture->proxy_om);
|
|
|
|
|
|
|
|
|
|
/* create metadata */
|
|
|
|
|
metadata = WP_METADATA (wp_impl_metadata_new (fixture->base.core));
|
|
|
|
|
wp_metadata_set (metadata, 0, "test-key", NULL, "test-value");
|
|
|
|
|
wp_metadata_set (metadata, 15, "toast", "Spa:Int", "15");
|
|
|
|
|
|
|
|
|
|
/* verify properties are set before export */
|
|
|
|
|
{
|
2021-02-05 10:20:33 -05:00
|
|
|
g_autoptr (WpIterator) iter = wp_metadata_new_iterator (metadata, PW_ID_ANY);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
guint subject = -1;
|
|
|
|
|
const gchar *key = NULL, *type = NULL, *value = NULL;
|
2024-02-23 13:41:46 -05:00
|
|
|
WpMetadataItem *mi;
|
2020-08-31 16:16:07 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "test-key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "test-value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
|
|
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 15);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "toast");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "Spa:Int");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "15");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_false (wp_iterator_next (iter, &val));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* do export */
|
2020-11-13 13:40:11 +02:00
|
|
|
wp_object_activate (WP_OBJECT (metadata), WP_OBJECT_FEATURES_ALL, NULL,
|
2020-08-31 16:16:07 +03:00
|
|
|
(GAsyncReadyCallback) test_metadata_basic_export_done, fixture);
|
|
|
|
|
|
|
|
|
|
/* run until objects are created and features are cached */
|
|
|
|
|
fixture->n_events = 0;
|
|
|
|
|
g_main_loop_run (fixture->base.loop);
|
|
|
|
|
g_assert_cmpint (fixture->n_events, ==, 3);
|
|
|
|
|
g_assert_nonnull (fixture->impl_metadata);
|
|
|
|
|
g_assert_nonnull (fixture->proxy_metadata);
|
|
|
|
|
g_assert_true (fixture->impl_metadata == metadata);
|
|
|
|
|
|
|
|
|
|
/* test round 1: verify the values on the proxy */
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpIterator) iter =
|
2021-02-05 10:20:33 -05:00
|
|
|
wp_metadata_new_iterator (fixture->proxy_metadata, PW_ID_ANY);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
guint subject = -1;
|
|
|
|
|
const gchar *key = NULL, *type = NULL, *value = NULL;
|
2024-02-23 13:41:46 -05:00
|
|
|
WpMetadataItem *mi;
|
2020-08-31 16:16:07 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "test-key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "test-value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 15);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "toast");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "Spa:Int");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "15");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_false (wp_iterator_next (iter, &val));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* setup change signals */
|
|
|
|
|
g_signal_connect (fixture->proxy_metadata, "changed",
|
|
|
|
|
(GCallback) test_metadata_basic_changed, fixture);
|
|
|
|
|
g_signal_connect (metadata, "changed",
|
|
|
|
|
(GCallback) test_metadata_basic_changed, fixture);
|
|
|
|
|
|
|
|
|
|
/* change properties on the proxy */
|
|
|
|
|
wp_metadata_set (fixture->proxy_metadata, 15, "toast", "Spa:Int", "20");
|
|
|
|
|
wp_metadata_set (fixture->proxy_metadata, 0, "3rd.key", NULL, "3rd.value");
|
|
|
|
|
|
|
|
|
|
/* run until the change is on both sides */
|
|
|
|
|
fixture->n_events = 0;
|
|
|
|
|
g_main_loop_run (fixture->base.loop);
|
|
|
|
|
g_assert_cmpint (fixture->n_events, ==, 4);
|
|
|
|
|
|
|
|
|
|
/* test round 2: verify the value change on both sides */
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpIterator) iter =
|
2021-02-05 10:20:33 -05:00
|
|
|
wp_metadata_new_iterator (fixture->proxy_metadata, PW_ID_ANY);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
guint subject = -1;
|
|
|
|
|
const gchar *key = NULL, *type = NULL, *value = NULL;
|
2024-02-23 13:41:46 -05:00
|
|
|
WpMetadataItem *mi;
|
2020-08-31 16:16:07 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "test-key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "test-value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 15);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "toast");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "Spa:Int");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "20");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "3rd.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "3rd.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_false (wp_iterator_next (iter, &val));
|
|
|
|
|
}
|
|
|
|
|
{
|
2021-02-05 10:20:33 -05:00
|
|
|
g_autoptr (WpIterator) iter =
|
|
|
|
|
wp_metadata_new_iterator (metadata, PW_ID_ANY);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
guint subject = -1;
|
|
|
|
|
const gchar *key = NULL, *type = NULL, *value = NULL;
|
2024-02-23 13:41:46 -05:00
|
|
|
WpMetadataItem *mi;
|
2020-08-31 16:16:07 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "test-key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "test-value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 15);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "toast");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "Spa:Int");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "20");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "3rd.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "3rd.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_false (wp_iterator_next (iter, &val));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* change properties on the exported */
|
|
|
|
|
fixture->n_events = 0;
|
|
|
|
|
wp_metadata_set (metadata, 0, "4th.key", NULL, "4th.value");
|
|
|
|
|
wp_metadata_set (metadata, 0, "test-key", NULL, "new.value");
|
|
|
|
|
|
|
|
|
|
/* run until the change is on both sides */
|
|
|
|
|
g_main_loop_run (fixture->base.loop);
|
|
|
|
|
g_assert_cmpint (fixture->n_events, ==, 4);
|
|
|
|
|
|
|
|
|
|
/* test round 3: verify the value change on both sides */
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpIterator) iter =
|
2021-02-05 10:20:33 -05:00
|
|
|
wp_metadata_new_iterator (fixture->proxy_metadata, PW_ID_ANY);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
guint subject = -1;
|
|
|
|
|
const gchar *key = NULL, *type = NULL, *value = NULL;
|
2024-02-23 13:41:46 -05:00
|
|
|
WpMetadataItem *mi;
|
2020-08-31 16:16:07 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "test-key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "new.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 15);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "toast");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "Spa:Int");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "20");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "3rd.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "3rd.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "4th.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "4th.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_false (wp_iterator_next (iter, &val));
|
|
|
|
|
}
|
|
|
|
|
{
|
2021-02-05 10:20:33 -05:00
|
|
|
g_autoptr (WpIterator) iter =
|
|
|
|
|
wp_metadata_new_iterator (metadata, PW_ID_ANY);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
guint subject = -1;
|
|
|
|
|
const gchar *key = NULL, *type = NULL, *value = NULL;
|
2024-02-23 13:41:46 -05:00
|
|
|
WpMetadataItem *mi;
|
2020-08-31 16:16:07 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "test-key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "new.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 15);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "toast");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "Spa:Int");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "20");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "3rd.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "3rd.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "4th.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "4th.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_false (wp_iterator_next (iter, &val));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* find with constraints */
|
|
|
|
|
{
|
2021-02-05 10:20:33 -05:00
|
|
|
g_autoptr (WpIterator) iter = wp_metadata_new_iterator (metadata, 0);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_auto (GValue) val = G_VALUE_INIT;
|
|
|
|
|
guint subject = -1;
|
|
|
|
|
const gchar *key = NULL, *type = NULL, *value = NULL;
|
2024-02-23 13:41:46 -05:00
|
|
|
WpMetadataItem *mi;
|
2020-08-31 16:16:07 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "test-key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "new.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "3rd.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "3rd.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_true (wp_iterator_next (iter, &val));
|
2024-02-23 13:41:46 -05:00
|
|
|
mi = g_value_get_boxed (&val);
|
|
|
|
|
subject = wp_metadata_item_get_subject (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpint (subject, ==, 0);
|
2024-02-23 13:41:46 -05:00
|
|
|
key = wp_metadata_item_get_key (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (key, ==, "4th.key");
|
2024-02-23 13:41:46 -05:00
|
|
|
type = wp_metadata_item_get_value_type (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
2024-02-23 13:41:46 -05:00
|
|
|
value = wp_metadata_item_get_value (mi);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (value, ==, "4th.value");
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
|
|
g_assert_false (wp_iterator_next (iter, &val));
|
|
|
|
|
}
|
|
|
|
|
{
|
2021-01-11 13:09:23 -05:00
|
|
|
const gchar *value = NULL, *type = NULL;
|
|
|
|
|
value = wp_metadata_find (metadata, 0, "3rd.key", &type);
|
2020-08-31 16:16:07 +03:00
|
|
|
g_assert_cmpstr (type, ==, "string");
|
|
|
|
|
g_assert_cmpstr (value, ==, "3rd.value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* destroy impl metadata */
|
|
|
|
|
fixture->n_events = 0;
|
|
|
|
|
g_clear_object (&metadata);
|
|
|
|
|
|
|
|
|
|
/* run until objects are destroyed */
|
|
|
|
|
g_main_loop_run (fixture->base.loop);
|
|
|
|
|
g_assert_cmpint (fixture->n_events, ==, 2);
|
|
|
|
|
g_assert_null (fixture->impl_metadata);
|
|
|
|
|
g_assert_null (fixture->proxy_metadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
main (gint argc, gchar *argv[])
|
|
|
|
|
{
|
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
wp_init (WP_INIT_ALL);
|
|
|
|
|
|
|
|
|
|
g_test_add ("/wp/metadata/basic", TestFixture, NULL,
|
|
|
|
|
test_metadata_setup, test_metadata_basic, test_metadata_teardown);
|
|
|
|
|
|
|
|
|
|
return g_test_run ();
|
|
|
|
|
}
|