metadata: remove wp_metadata_iterator_item_extract() API

Similar to WpPropertiesItem, this implements a new WpMetadataItem type that is
returned when iterating metadata
This commit is contained in:
Julian Bouzas
2024-02-23 13:41:46 -05:00
parent bebfc07d84
commit a23248847a
9 changed files with 308 additions and 79 deletions

View File

@@ -14,6 +14,8 @@ PipeWire Metadata
WpMetadata-> WpImplMetadata; WpMetadata-> WpImplMetadata;
} }
.. doxygenstruct:: WpMetadataItem
.. doxygenstruct:: WpMetadata .. doxygenstruct:: WpMetadata
.. doxygenstruct:: WpImplMetadata .. doxygenstruct:: WpImplMetadata

View File

@@ -319,6 +319,124 @@ wp_metadata_class_init (WpMetadataClass * klass)
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
} }
struct _WpMetadataItem
{
WpMetadata *metadata;
guint32 subject;
const gchar *key;
const gchar *type;
const gchar *value;
};
G_DEFINE_BOXED_TYPE (WpMetadataItem, wp_metadata_item,
wp_metadata_item_ref, wp_metadata_item_unref)
static WpMetadataItem *
wp_metadata_item_new (WpMetadata *metadata, guint32 subject, const gchar *key,
const gchar *type, const gchar *value)
{
WpMetadataItem *self = g_rc_box_new0 (WpMetadataItem);
self->metadata = g_object_ref (metadata);
self->subject = subject;
self->key = key;
self->type = type;
self->value = value;
return self;
}
static void
wp_metadata_item_free (gpointer p)
{
WpMetadataItem *self = p;
g_clear_object (&self->metadata);
}
/*!
* \brief Increases the reference count of a metadata item object
* \ingroup wpmetadata
* \param self a metadata item object
* \returns (transfer full): \a self with an additional reference count on it
* \since 0.5.0
*/
WpMetadataItem *
wp_metadata_item_ref (WpMetadataItem *self)
{
return g_rc_box_acquire (self);
}
/*!
* \brief Decreases the reference count on \a self and frees it when the ref
* count reaches zero.
* \ingroup wpmetadata
* \param self (transfer full): a metadata item object
* \since 0.5.0
*/
void
wp_metadata_item_unref (WpMetadataItem *self)
{
g_rc_box_release_full (self, wp_metadata_item_free);
}
/*!
* \brief Gets the subject from a metadata item
*
* \ingroup wpmetadata
* \param self the item held by the GValue that was returned from the WpIterator
* of wp_metadata_new_iterator()
* \returns (transfer none): the metadata subject of the \a item
* \since 0.5.0
*/
guint32
wp_metadata_item_get_subject (WpMetadataItem * self)
{
return self->subject;
}
/*!
* \brief Gets the key from a metadata item
*
* \ingroup wpmetadata
* \param self the item held by the GValue that was returned from the WpIterator
* of wp_metadata_new_iterator()
* \returns (transfer none): the metadata key of the \a item
* \since 0.5.0
*/
const gchar *
wp_metadata_item_get_key (WpMetadataItem * self)
{
return self->key;
}
/*!
* \brief Gets the value type from a metadata item
*
* \ingroup wpmetadata
* \param self the item held by the GValue that was returned from the WpIterator
* of wp_metadata_new_iterator()
* \returns (transfer none): the metadata value type of the \a item
* \since 0.5.0
*/
const gchar *
wp_metadata_item_get_value_type (WpMetadataItem * self)
{
return self->type;
}
/*!
* \brief Gets the value from a metadata item
*
* \ingroup wpmetadata
* \param self the item held by the GValue that was returned from the WpIterator
* of wp_metadata_new_iterator()
* \returns (transfer none): the metadata value of the \a item
* \since 0.5.0
*/
const gchar *
wp_metadata_item_get_value (WpMetadataItem * self)
{
return self->value;
}
struct metadata_iterator_data struct metadata_iterator_data
{ {
WpMetadata *metadata; WpMetadata *metadata;
@@ -346,8 +464,11 @@ metadata_iterator_next (WpIterator *it, GValue *item)
while (pw_array_check (&priv->metadata, it_data->item)) { while (pw_array_check (&priv->metadata, it_data->item)) {
if ((it_data->subject == PW_ID_ANY || if ((it_data->subject == PW_ID_ANY ||
it_data->subject == it_data->item->subject)) { it_data->subject == it_data->item->subject)) {
g_value_init (item, G_TYPE_POINTER); g_autoptr (WpMetadataItem) mi = wp_metadata_item_new (it_data->metadata,
g_value_set_pointer (item, (gpointer) it_data->item); it_data->item->subject, it_data->item->key, it_data->item->type,
it_data->item->value);
g_value_init (item, WP_TYPE_METADATA_ITEM);
g_value_take_boxed (item, g_steal_pointer (&mi));
it_data->item++; it_data->item++;
return TRUE; return TRUE;
} }
@@ -369,8 +490,11 @@ metadata_iterator_fold (WpIterator *it, WpIteratorFoldFunc func, GValue *ret,
if ((it_data->subject == PW_ID_ANY || if ((it_data->subject == PW_ID_ANY ||
it_data->subject == it_data->item->subject)) { it_data->subject == it_data->item->subject)) {
g_auto (GValue) item = G_VALUE_INIT; g_auto (GValue) item = G_VALUE_INIT;
g_value_init (&item, G_TYPE_POINTER); g_autoptr (WpMetadataItem) mi = wp_metadata_item_new (it_data->metadata,
g_value_set_pointer (&item, (gpointer) i); it_data->item->subject, it_data->item->key, it_data->item->type,
it_data->item->value);
g_value_init (&item, WP_TYPE_METADATA_ITEM);
g_value_take_boxed (&item, g_steal_pointer (&mi));
if (!func (&item, ret, data)) if (!func (&item, ret, data))
return FALSE; return FALSE;
} }
@@ -407,8 +531,7 @@ static const WpIteratorMethods metadata_iterator_methods = {
* \param self a metadata object * \param self a metadata object
* \param subject the metadata subject id, or -1 (PW_ID_ANY) * \param subject the metadata subject id, or -1 (PW_ID_ANY)
* \returns (transfer full): an iterator that iterates over the found metadata. * \returns (transfer full): an iterator that iterates over the found metadata.
* Use wp_metadata_iterator_item_extract() to parse the items returned by * The type of the iterator item is WpMetadataItem.
* this iterator.
*/ */
WpIterator * WpIterator *
wp_metadata_new_iterator (WpMetadata * self, guint32 subject) wp_metadata_new_iterator (WpMetadata * self, guint32 subject)
@@ -429,33 +552,6 @@ wp_metadata_new_iterator (WpMetadata * self, guint32 subject)
return g_steal_pointer (&it); return g_steal_pointer (&it);
} }
/*!
* \brief Extracts the metadata subject, key, type and value out of a
* GValue that was returned from the WpIterator of wp_metadata_find()
*
* \ingroup wpmetadata
* \param item a GValue that was returned from the WpIterator of wp_metadata_find()
* \param subject (out)(optional): the subject id of the current item
* \param key (out)(optional)(transfer none): the key of the current item
* \param type (out)(optional)(transfer none): the type of the current item
* \param value (out)(optional)(transfer none): the value of the current item
*/
void
wp_metadata_iterator_item_extract (const GValue * item, guint32 * subject,
const gchar ** key, const gchar ** type, const gchar ** value)
{
const struct item *i = g_value_get_pointer (item);
g_return_if_fail (i != NULL);
if (subject)
*subject = i->subject;
if (key)
*key = i->key;
if (type)
*type = i->type;
if (value)
*value = i->value;
}
/*! /*!
* \brief Finds the metadata value given its \a subject and \a key. * \brief Finds the metadata value given its \a subject and \a key.
* *
@@ -474,8 +570,10 @@ wp_metadata_find (WpMetadata * self, guint32 subject, const gchar * key,
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
it = wp_metadata_new_iterator (self, subject); it = wp_metadata_new_iterator (self, subject);
for (; wp_iterator_next (it, &val); g_value_unset (&val)) { for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
const gchar *k = NULL, *t = NULL, *v = NULL; WpMetadataItem *mi = g_value_get_boxed (&val);
wp_metadata_iterator_item_extract (&val, NULL, &k, &t, &v); const gchar *k = wp_metadata_item_get_key (mi);
const gchar *t = wp_metadata_item_get_value_type (mi);
const gchar *v = wp_metadata_item_get_value (mi);
if (g_strcmp0 (k, key) == 0) { if (g_strcmp0 (k, key) == 0) {
if (type) if (type)
*type = t; *type = t;

View File

@@ -13,6 +13,36 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/*!
* \brief The WpMetadataItem GType
* \ingroup wpmetadata
*/
#define WP_TYPE_METADATA_ITEM (wp_metadata_item_get_type ())
WP_API
GType wp_metadata_item_get_type (void);
typedef struct _WpMetadataItem WpMetadataItem;
WP_API
WpMetadataItem *wp_metadata_item_ref (WpMetadataItem *self);
WP_API
void wp_metadata_item_unref (WpMetadataItem *self);
WP_API
guint32 wp_metadata_item_get_subject (WpMetadataItem * self);
WP_API
const gchar * wp_metadata_item_get_key (WpMetadataItem * self);
WP_API
const gchar * wp_metadata_item_get_value_type (WpMetadataItem * self);
WP_API
const gchar * wp_metadata_item_get_value (WpMetadataItem * self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpMetadataItem, wp_metadata_item_unref)
/*! /*!
* \brief An extension of WpProxyFeatures for WpMetadata objects * \brief An extension of WpProxyFeatures for WpMetadata objects
* \ingroup wpmetadata * \ingroup wpmetadata
@@ -42,10 +72,6 @@ struct _WpMetadataClass
WP_API WP_API
WpIterator * wp_metadata_new_iterator (WpMetadata * self, guint32 subject); WpIterator * wp_metadata_new_iterator (WpMetadata * self, guint32 subject);
WP_API
void wp_metadata_iterator_item_extract (const GValue * item, guint32 * subject,
const gchar ** key, const gchar ** type, const gchar ** value);
WP_API WP_API
const gchar * wp_metadata_find (WpMetadata * self, guint32 subject, const gchar * wp_metadata_find (WpMetadata * self, guint32 subject,
const gchar * key, const gchar ** type); const gchar * key, const gchar ** type);

View File

@@ -174,9 +174,10 @@ on_metadata_added (WpObjectManager *om, WpMetadata *m, gpointer d)
/* traverse through all settings */ /* traverse through all settings */
for (; wp_iterator_next (it, &val); g_value_unset (&val)) { for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
const gchar *setting, *value; WpMetadataItem *mi = g_value_get_boxed (&val);
wp_metadata_iterator_item_extract (&val, NULL, &setting, NULL, &value); const gchar *key = wp_metadata_item_get_key (mi);
wp_properties_set (self->settings, setting, value); const gchar *value = wp_metadata_item_get_value (mi);
wp_properties_set (self->settings, key, value);
} }
wp_info_object (self, "loaded %d settings and from metadata \"%s\"", wp_info_object (self, "loaded %d settings and from metadata \"%s\"",

View File

@@ -152,9 +152,11 @@ on_metadata_added (WpObjectManager *om, WpObject *obj, WpDefaultNodesApi * self)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
for (; wp_iterator_next (it, &val); g_value_unset (&val)) { for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
guint32 subject; WpMetadataItem *mi = g_value_get_boxed (&val);
const gchar *key, *type, *value; guint32 subject = wp_metadata_item_get_subject (mi);
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); const gchar *key = wp_metadata_item_get_key (mi);
const gchar *type = wp_metadata_item_get_value_type (mi);
const gchar *value = wp_metadata_item_get_value (mi);
on_metadata_changed (WP_METADATA (obj), subject, key, type, value, self); on_metadata_changed (WP_METADATA (obj), subject, key, type, value, self);
} }

View File

@@ -596,9 +596,11 @@ metadata_iterator_next (lua_State *L)
WpIterator *it = wplua_checkboxed (L, 1, WP_TYPE_ITERATOR); WpIterator *it = wplua_checkboxed (L, 1, WP_TYPE_ITERATOR);
g_auto (GValue) item = G_VALUE_INIT; g_auto (GValue) item = G_VALUE_INIT;
if (wp_iterator_next (it, &item)) { if (wp_iterator_next (it, &item)) {
guint32 s = 0; WpMetadataItem *mi = g_value_get_boxed (&item);
const gchar *k = NULL, *t = NULL, *v = NULL; guint32 s = wp_metadata_item_get_subject (mi);
wp_metadata_iterator_item_extract (&item, &s, &k, &t, &v); const gchar *k = wp_metadata_item_get_key (mi);
const gchar *t = wp_metadata_item_get_value_type (mi);
const gchar *v = wp_metadata_item_get_value (mi);
lua_pushinteger (L, s); lua_pushinteger (L, s);
lua_pushstring (L, k); lua_pushstring (L, k);
lua_pushstring (L, t); lua_pushstring (L, t);

View File

@@ -1402,7 +1402,8 @@ settings_run (WpCtl * self)
} }
persistent_settings = wp_object_manager_lookup (self->om, WP_TYPE_METADATA, persistent_settings = wp_object_manager_lookup (self->om, WP_TYPE_METADATA,
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY,
"metadata.name", "=s", "persistent-sm-settings", "metadata.name", "=s",
WP_SETTINGS_PERSISTENT_METADATA_NAME_PREFIX "sm-settings",
NULL); NULL);
if (!persistent_settings) { if (!persistent_settings) {
fprintf (stderr, "Persistent settings metadata not found\n"); fprintf (stderr, "Persistent settings metadata not found\n");
@@ -1416,9 +1417,11 @@ settings_run (WpCtl * self)
printf ("Settings:\n"); printf ("Settings:\n");
it = wp_metadata_new_iterator (settings, 0); it = wp_metadata_new_iterator (settings, 0);
for (; wp_iterator_next (it, &val); g_value_unset (&val)) { for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
const gchar *key, *value, *saved_value; WpMetadataItem *mi = g_value_get_boxed (&val);
wp_metadata_iterator_item_extract (&val, 0, &key, NULL, &value); const gchar *key = wp_metadata_item_get_key (mi);
saved_value = wp_metadata_find (persistent_settings, 0, key, NULL); const gchar *value = wp_metadata_item_get_value (mi);
const gchar *saved_value = wp_metadata_find (persistent_settings, 0,
key, NULL);
if (saved_value) if (saved_value)
printf (" - %s: %s (saved: %s)\n", key, value, saved_value); printf (" - %s: %s (saved: %s)\n", key, value, saved_value);
else else
@@ -1429,8 +1432,10 @@ settings_run (WpCtl * self)
/* Save all current settings */ /* Save all current settings */
it = wp_metadata_new_iterator (settings, 0); it = wp_metadata_new_iterator (settings, 0);
for (; wp_iterator_next (it, &val); g_value_unset (&val)) { for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
const gchar *key, *type, *value; WpMetadataItem *mi = g_value_get_boxed (&val);
wp_metadata_iterator_item_extract (&val, 0, &key, &type, &value); const gchar *key = wp_metadata_item_get_key (mi);
const gchar *type = wp_metadata_item_get_value_type (mi);
const gchar *value = wp_metadata_item_get_value (mi);
wp_metadata_set (persistent_settings, 0, key, type, value); wp_metadata_set (persistent_settings, 0, key, type, value);
fprintf (stderr, "Saved setting %s with value %s\n", key, value); fprintf (stderr, "Saved setting %s with value %s\n", key, value);
} }

View File

@@ -168,20 +168,30 @@ test_metadata_basic (TestFixture *fixture, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
guint subject = -1; guint subject = -1;
const gchar *key = NULL, *type = NULL, *value = NULL; const gchar *key = NULL, *type = NULL, *value = NULL;
WpMetadataItem *mi;
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "test-key"); g_assert_cmpstr (key, ==, "test-key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "test-value"); g_assert_cmpstr (value, ==, "test-value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value);
mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 15); g_assert_cmpint (subject, ==, 15);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "toast"); g_assert_cmpstr (key, ==, "toast");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "Spa:Int"); g_assert_cmpstr (type, ==, "Spa:Int");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "15"); g_assert_cmpstr (value, ==, "15");
g_value_unset (&val); g_value_unset (&val);
@@ -207,20 +217,29 @@ test_metadata_basic (TestFixture *fixture, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
guint subject = -1; guint subject = -1;
const gchar *key = NULL, *type = NULL, *value = NULL; const gchar *key = NULL, *type = NULL, *value = NULL;
WpMetadataItem *mi;
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "test-key"); g_assert_cmpstr (key, ==, "test-key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "test-value"); g_assert_cmpstr (value, ==, "test-value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 15); g_assert_cmpint (subject, ==, 15);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "toast"); g_assert_cmpstr (key, ==, "toast");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "Spa:Int"); g_assert_cmpstr (type, ==, "Spa:Int");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "15"); g_assert_cmpstr (value, ==, "15");
g_value_unset (&val); g_value_unset (&val);
@@ -249,28 +268,41 @@ test_metadata_basic (TestFixture *fixture, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
guint subject = -1; guint subject = -1;
const gchar *key = NULL, *type = NULL, *value = NULL; const gchar *key = NULL, *type = NULL, *value = NULL;
WpMetadataItem *mi;
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "test-key"); g_assert_cmpstr (key, ==, "test-key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "test-value"); g_assert_cmpstr (value, ==, "test-value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 15); g_assert_cmpint (subject, ==, 15);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "toast"); g_assert_cmpstr (key, ==, "toast");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "Spa:Int"); g_assert_cmpstr (type, ==, "Spa:Int");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "20"); g_assert_cmpstr (value, ==, "20");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "3rd.key"); g_assert_cmpstr (key, ==, "3rd.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "3rd.value"); g_assert_cmpstr (value, ==, "3rd.value");
g_value_unset (&val); g_value_unset (&val);
@@ -282,28 +314,41 @@ test_metadata_basic (TestFixture *fixture, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
guint subject = -1; guint subject = -1;
const gchar *key = NULL, *type = NULL, *value = NULL; const gchar *key = NULL, *type = NULL, *value = NULL;
WpMetadataItem *mi;
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "test-key"); g_assert_cmpstr (key, ==, "test-key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "test-value"); g_assert_cmpstr (value, ==, "test-value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 15); g_assert_cmpint (subject, ==, 15);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "toast"); g_assert_cmpstr (key, ==, "toast");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "Spa:Int"); g_assert_cmpstr (type, ==, "Spa:Int");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "20"); g_assert_cmpstr (value, ==, "20");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "3rd.key"); g_assert_cmpstr (key, ==, "3rd.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "3rd.value"); g_assert_cmpstr (value, ==, "3rd.value");
g_value_unset (&val); g_value_unset (&val);
@@ -326,36 +371,53 @@ test_metadata_basic (TestFixture *fixture, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
guint subject = -1; guint subject = -1;
const gchar *key = NULL, *type = NULL, *value = NULL; const gchar *key = NULL, *type = NULL, *value = NULL;
WpMetadataItem *mi;
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "test-key"); g_assert_cmpstr (key, ==, "test-key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "new.value"); g_assert_cmpstr (value, ==, "new.value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 15); g_assert_cmpint (subject, ==, 15);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "toast"); g_assert_cmpstr (key, ==, "toast");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "Spa:Int"); g_assert_cmpstr (type, ==, "Spa:Int");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "20"); g_assert_cmpstr (value, ==, "20");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "3rd.key"); g_assert_cmpstr (key, ==, "3rd.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "3rd.value"); g_assert_cmpstr (value, ==, "3rd.value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "4th.key"); g_assert_cmpstr (key, ==, "4th.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "4th.value"); g_assert_cmpstr (value, ==, "4th.value");
g_value_unset (&val); g_value_unset (&val);
@@ -367,36 +429,53 @@ test_metadata_basic (TestFixture *fixture, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
guint subject = -1; guint subject = -1;
const gchar *key = NULL, *type = NULL, *value = NULL; const gchar *key = NULL, *type = NULL, *value = NULL;
WpMetadataItem *mi;
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "test-key"); g_assert_cmpstr (key, ==, "test-key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "new.value"); g_assert_cmpstr (value, ==, "new.value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 15); g_assert_cmpint (subject, ==, 15);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "toast"); g_assert_cmpstr (key, ==, "toast");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "Spa:Int"); g_assert_cmpstr (type, ==, "Spa:Int");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "20"); g_assert_cmpstr (value, ==, "20");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "3rd.key"); g_assert_cmpstr (key, ==, "3rd.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "3rd.value"); g_assert_cmpstr (value, ==, "3rd.value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "4th.key"); g_assert_cmpstr (key, ==, "4th.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "4th.value"); g_assert_cmpstr (value, ==, "4th.value");
g_value_unset (&val); g_value_unset (&val);
@@ -409,28 +488,41 @@ test_metadata_basic (TestFixture *fixture, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
guint subject = -1; guint subject = -1;
const gchar *key = NULL, *type = NULL, *value = NULL; const gchar *key = NULL, *type = NULL, *value = NULL;
WpMetadataItem *mi;
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "test-key"); g_assert_cmpstr (key, ==, "test-key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "new.value"); g_assert_cmpstr (value, ==, "new.value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "3rd.key"); g_assert_cmpstr (key, ==, "3rd.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "3rd.value"); g_assert_cmpstr (value, ==, "3rd.value");
g_value_unset (&val); g_value_unset (&val);
g_assert_true (wp_iterator_next (iter, &val)); g_assert_true (wp_iterator_next (iter, &val));
wp_metadata_iterator_item_extract (&val, &subject, &key, &type, &value); mi = g_value_get_boxed (&val);
subject = wp_metadata_item_get_subject (mi);
g_assert_cmpint (subject, ==, 0); g_assert_cmpint (subject, ==, 0);
key = wp_metadata_item_get_key (mi);
g_assert_cmpstr (key, ==, "4th.key"); g_assert_cmpstr (key, ==, "4th.key");
type = wp_metadata_item_get_value_type (mi);
g_assert_cmpstr (type, ==, "string"); g_assert_cmpstr (type, ==, "string");
value = wp_metadata_item_get_value (mi);
g_assert_cmpstr (value, ==, "4th.value"); g_assert_cmpstr (value, ==, "4th.value");
g_value_unset (&val); g_value_unset (&val);

View File

@@ -170,10 +170,11 @@ test_metadata (TestSettingsFixture *self, gconstpointer data)
g_auto (GValue) val = G_VALUE_INIT; g_auto (GValue) val = G_VALUE_INIT;
for (; wp_iterator_next (it, &val); g_value_unset (&val)) { for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
const gchar *setting, *value; WpMetadataItem *mi = g_value_get_boxed (&val);
wp_metadata_iterator_item_extract (&val, NULL, &setting, NULL, &value); const gchar *key = wp_metadata_item_get_key (mi);
wp_properties_set (settings, setting, value); const gchar *value = wp_metadata_item_get_value (mi);
g_debug ("%s(%lu) = %s\n", setting, strlen(value), value); wp_properties_set (settings, key, value);
g_debug ("%s(%lu) = %s\n", key, strlen(value), value);
} }
/* match the settings loaded from conf file and metadata */ /* match the settings loaded from conf file and metadata */