mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-01-03 06:30:08 +01:00
lib: add spa pod API
This commit is contained in:
parent
b79fcf9418
commit
8c209ecf48
7 changed files with 4371 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ wp_lib_sources = files(
|
|||
'properties.c',
|
||||
'proxy.c',
|
||||
'session.c',
|
||||
'spa-pod.c',
|
||||
'spa-type.c',
|
||||
'spa-props.c',
|
||||
)
|
||||
|
|
@ -41,6 +42,7 @@ wp_lib_headers = files(
|
|||
'properties.h',
|
||||
'proxy.h',
|
||||
'session.h',
|
||||
'spa-pod.h',
|
||||
'spa-type.h',
|
||||
'wp.h',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "object-manager.h"
|
||||
#include "proxy.h"
|
||||
#include "iterator.h"
|
||||
#include "spa-type.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <pipewire/pipewire.h>
|
||||
|
|
@ -132,6 +133,21 @@ WpIterator * wp_iterator_new (const WpIteratorMethods *methods,
|
|||
size_t user_size);
|
||||
gpointer wp_iterator_get_user_data (WpIterator *self);
|
||||
|
||||
/* spa pod */
|
||||
|
||||
typedef struct _WpSpaPod WpSpaPod;
|
||||
WpSpaPod * wp_spa_pod_new_regular_wrap (struct spa_pod *pod);
|
||||
WpSpaPod * wp_spa_pod_new_property_wrap (WpSpaTypeTable table, guint32 key,
|
||||
guint32 flags, struct spa_pod *pod);
|
||||
WpSpaPod * wp_spa_pod_new_control_wrap (guint32 offset, guint32 type,
|
||||
struct spa_pod *pod);
|
||||
WpSpaPod * wp_spa_pod_new_regular_wrap_copy (const struct spa_pod *pod);
|
||||
WpSpaPod * wp_spa_pod_new_property_wrap_copy (WpSpaTypeTable table, guint32 key,
|
||||
guint32 flags, const struct spa_pod *pod);
|
||||
WpSpaPod * wp_spa_pod_new_control_wrap_copy (guint32 offset, guint32 type,
|
||||
const struct spa_pod *pod);
|
||||
struct spa_pod *wp_spa_pod_get_spa_pod (WpSpaPod *self);
|
||||
|
||||
/* spa props */
|
||||
|
||||
struct _WpSpaProps
|
||||
|
|
|
|||
2909
lib/wp/spa-pod.c
Normal file
2909
lib/wp/spa-pod.c
Normal file
File diff suppressed because it is too large
Load diff
459
lib/wp/spa-pod.h
Normal file
459
lib/wp/spa-pod.h
Normal file
|
|
@ -0,0 +1,459 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2020 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_SPA_POD_H__
|
||||
#define __WIREPLUMBER_SPA_POD_H__
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "iterator.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* WP_TYPE_SPA_POD:
|
||||
*
|
||||
* The #WpSpaPod #GType
|
||||
*/
|
||||
#define WP_TYPE_SPA_POD (wp_spa_pod_get_type ())
|
||||
WP_API
|
||||
GType wp_spa_pod_get_type (void);
|
||||
|
||||
typedef struct _WpSpaPod WpSpaPod;
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_ref (WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_unref (WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
const char *wp_spa_pod_get_type_name (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_copy (const WpSpaPod *other);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_unique_owner ( WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_ensure_unique_owner (WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_none (void);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_boolean (gboolean value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_id (guint32 value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_int (gint value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_long (glong value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_float (float value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_double (double value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_string (const char *value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_bytes (gconstpointer value, guint32 len);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_pointer (const char *type_name, gconstpointer value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_fd (gint64 value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_rectangle (guint32 width, guint32 height);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_fraction (guint32 num, guint32 denom);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_choice (const char *type_name, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_choice_valist (const char *type_name, va_list args);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_object (const char *type_name, const char *id_name,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_object_valist (const char *type_name,
|
||||
const char *id_name, va_list args);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_sequence (guint unit, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_new_sequence_valist (guint unit, va_list args);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_none (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_boolean (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_id (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_int (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_long (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_float (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_double (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_string (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_bytes (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_pointer (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_fd (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_rectangle (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_fraction (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_array (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_choice (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_object (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_struct (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_sequence (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_property (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_is_control (const WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_boolean (const WpSpaPod *self, gboolean *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_id (const WpSpaPod *self, guint32 *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_int (const WpSpaPod *self, gint *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_long (const WpSpaPod *self, glong *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_float (const WpSpaPod *self, float *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_double (const WpSpaPod *self, double *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_string (const WpSpaPod *self, const char **value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_bytes (const WpSpaPod *self, gconstpointer *value,
|
||||
guint32 *len);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_pointer (const WpSpaPod *self, const char **type_name,
|
||||
gconstpointer *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_fd (const WpSpaPod *self, gint64 *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_rectangle (const WpSpaPod *self, guint32 *width,
|
||||
guint32 *height);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_fraction (const WpSpaPod *self, guint32 *num,
|
||||
guint32 *denom);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_boolean (WpSpaPod *self, gboolean value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_id (WpSpaPod *self, guint32 value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_int (WpSpaPod *self, gint value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_long (WpSpaPod *self, glong value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_float (WpSpaPod *self, float value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_double (WpSpaPod *self, double value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_pointer (WpSpaPod *self, const char *type_name,
|
||||
gconstpointer value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_fd (WpSpaPod *self, gint64 value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_rectangle (WpSpaPod *self, guint32 width,
|
||||
guint32 height);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_fraction (WpSpaPod *self, guint32 num, guint32 denom);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_set_pod (WpSpaPod *self, const WpSpaPod *pod);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_object (WpSpaPod *self, const char *type_name,
|
||||
const char **id_name, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_object_valist (WpSpaPod *self,
|
||||
const char *type_name, const char **id_name, va_list args);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_struct (WpSpaPod *self, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_struct_valist (WpSpaPod *self, va_list args);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_property (const WpSpaPod *self, const char **key,
|
||||
WpSpaPod **value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_get_control (const WpSpaPod *self, guint32 *offset,
|
||||
const char **type_name, WpSpaPod **value);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_get_choice_child (WpSpaPod *self);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_get_array_child (WpSpaPod *self);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpSpaPod, wp_spa_pod_unref)
|
||||
|
||||
|
||||
/**
|
||||
* WP_TYPE_SPA_POD_BUILDER:
|
||||
*
|
||||
* The #WpSpaPodBuilder #GType
|
||||
*/
|
||||
#define WP_TYPE_SPA_POD_BUILDER (wp_spa_pod_builder_get_type ())
|
||||
WP_API
|
||||
GType wp_spa_pod_builder_get_type (void);
|
||||
|
||||
typedef struct _WpSpaPodBuilder WpSpaPodBuilder;
|
||||
|
||||
WP_API
|
||||
WpSpaPodBuilder *wp_spa_pod_builder_ref (WpSpaPodBuilder *self);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_unref (WpSpaPodBuilder *self);
|
||||
|
||||
WP_API
|
||||
WpSpaPodBuilder *wp_spa_pod_builder_new_array (void);
|
||||
|
||||
WP_API
|
||||
WpSpaPodBuilder *wp_spa_pod_builder_new_choice (const char *type_name);
|
||||
|
||||
WP_API
|
||||
WpSpaPodBuilder *wp_spa_pod_builder_new_object (const char *type_name,
|
||||
const char *id_name);
|
||||
|
||||
WP_API
|
||||
WpSpaPodBuilder *wp_spa_pod_builder_new_struct (void);
|
||||
|
||||
WP_API
|
||||
WpSpaPodBuilder *wp_spa_pod_builder_new_sequence (guint unit);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_none (WpSpaPodBuilder *self);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_boolean (WpSpaPodBuilder *self, gboolean value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_id (WpSpaPodBuilder *self, guint32 value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_int (WpSpaPodBuilder *self, gint value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_long (WpSpaPodBuilder *self, glong value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_float (WpSpaPodBuilder *self, float value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_double (WpSpaPodBuilder *self, double value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_string (WpSpaPodBuilder *self, const char *value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_bytes (WpSpaPodBuilder *self, gconstpointer value,
|
||||
guint32 len);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_pointer (WpSpaPodBuilder *self,
|
||||
const char *type_name, gconstpointer value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_fd (WpSpaPodBuilder *self, gint64 value);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_rectangle (WpSpaPodBuilder *self, guint32 width,
|
||||
guint32 height);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_fraction (WpSpaPodBuilder *self, guint32 num,
|
||||
guint32 denom);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_pod (WpSpaPodBuilder *self, const WpSpaPod *pod);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_property (WpSpaPodBuilder *self, const char *key);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_control (WpSpaPodBuilder *self, guint32 offset,
|
||||
const char *type_name);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add (WpSpaPodBuilder *self, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_builder_add_valist (WpSpaPodBuilder *self, va_list args);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_builder_end (WpSpaPodBuilder *self);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpSpaPodBuilder, wp_spa_pod_builder_unref)
|
||||
|
||||
|
||||
/**
|
||||
* WP_TYPE_SPA_POD_PARSER:
|
||||
*
|
||||
* The #WpSpaPodParser #GType
|
||||
*/
|
||||
#define WP_TYPE_SPA_POD_PARSER (wp_spa_pod_parser_get_type ())
|
||||
WP_API
|
||||
GType wp_spa_pod_parser_get_type (void);
|
||||
|
||||
typedef struct _WpSpaPodParser WpSpaPodParser;
|
||||
|
||||
WP_API
|
||||
WpSpaPodParser *wp_spa_pod_parser_ref (WpSpaPodParser *self);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_parser_unref (WpSpaPodParser *self);
|
||||
|
||||
WP_API
|
||||
WpSpaPodParser *wp_spa_pod_parser_new_object (WpSpaPod *pod,
|
||||
const char *type_name, const char **id_name);
|
||||
|
||||
WP_API
|
||||
WpSpaPodParser *wp_spa_pod_parser_new_struct (WpSpaPod *pod);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_boolean (WpSpaPodParser *self, gboolean *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_id (WpSpaPodParser *self, guint32 *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_int (WpSpaPodParser *self, gint *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_long (WpSpaPodParser *self, glong *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_float (WpSpaPodParser *self, float *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_double (WpSpaPodParser *self, double *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_string (WpSpaPodParser *self,
|
||||
const char **value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_bytes (WpSpaPodParser *self,
|
||||
gconstpointer *value, guint32 *len);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_pointer (WpSpaPodParser *self,
|
||||
const char **type_name, gconstpointer *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_fd (WpSpaPodParser *self, gint64 *value);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_rectangle (WpSpaPodParser *self, guint32 *width,
|
||||
guint32 *height);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_fraction (WpSpaPodParser *self, guint32 *num,
|
||||
guint32 *denom);
|
||||
|
||||
WP_API
|
||||
WpSpaPod *wp_spa_pod_parser_get_pod (WpSpaPodParser *self);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get (WpSpaPodParser *self, ...);
|
||||
|
||||
WP_API
|
||||
gboolean wp_spa_pod_parser_get_valist (WpSpaPodParser *self,
|
||||
va_list args);
|
||||
|
||||
WP_API
|
||||
void wp_spa_pod_parser_end (WpSpaPodParser *self);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpSpaPodParser, wp_spa_pod_parser_unref)
|
||||
|
||||
|
||||
WP_API
|
||||
WpIterator *wp_spa_pod_iterator_new (WpSpaPod *pod);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
@ -25,4 +25,5 @@
|
|||
#include "proxy.h"
|
||||
#include "session.h"
|
||||
#include "spa-type.h"
|
||||
#include "spa-pod.h"
|
||||
#include "wpenums.h"
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ test(
|
|||
env: common_env,
|
||||
)
|
||||
|
||||
test(
|
||||
'test-spa-pod',
|
||||
executable('test-spa-pod', 'spa-pod.c', dependencies: common_deps),
|
||||
env: common_env,
|
||||
)
|
||||
|
||||
test(
|
||||
'test-spa-type',
|
||||
executable('test-spa-type', 'spa-type.c', dependencies: common_deps),
|
||||
|
|
|
|||
978
tests/wp/spa-pod.c
Normal file
978
tests/wp/spa-pod.c
Normal file
|
|
@ -0,0 +1,978 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2020 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
static void
|
||||
test_spa_pod_basic (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* None */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_none ();
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_none (pod));
|
||||
g_assert_false (wp_spa_pod_is_id (pod));
|
||||
g_assert_cmpstr ("None", ==, wp_spa_pod_get_type_name (pod));
|
||||
}
|
||||
|
||||
/* Boolean */
|
||||
{
|
||||
g_autoptr (WpSpaPod) copy = NULL;
|
||||
g_assert_null (copy);
|
||||
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_boolean (TRUE);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_boolean (pod));
|
||||
gboolean value = FALSE;
|
||||
g_assert_true (wp_spa_pod_get_boolean (pod, &value));
|
||||
g_assert_true (value);
|
||||
g_assert_cmpstr ("Bool", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_boolean (pod, FALSE));
|
||||
g_assert_true (wp_spa_pod_get_boolean (pod, &value));
|
||||
g_assert_false (value);
|
||||
|
||||
copy = wp_spa_pod_copy (pod);
|
||||
}
|
||||
|
||||
g_assert_nonnull (copy);
|
||||
g_assert_true (wp_spa_pod_is_boolean (copy));
|
||||
gboolean value = FALSE;
|
||||
g_assert_true (wp_spa_pod_get_boolean (copy, &value));
|
||||
g_assert_false (value);
|
||||
g_assert_cmpstr ("Bool", ==, wp_spa_pod_get_type_name (copy));
|
||||
}
|
||||
|
||||
/* Id */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_id (5);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_id (pod));
|
||||
guint32 value = 0;
|
||||
g_assert_true (wp_spa_pod_get_id (pod, &value));
|
||||
g_assert_cmpuint (value, ==, 5);
|
||||
g_assert_cmpstr ("Id", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_id (pod, 10));
|
||||
g_assert_true (wp_spa_pod_get_id (pod, &value));
|
||||
g_assert_cmpuint (value, ==, 10);
|
||||
}
|
||||
|
||||
/* Int */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_int (-12);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_int (pod));
|
||||
gint value = 0;
|
||||
g_assert_true (wp_spa_pod_get_int (pod, &value));
|
||||
g_assert_cmpint (value, ==, -12);
|
||||
g_assert_cmpstr ("Int", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_int (pod, 9999));
|
||||
g_assert_true (wp_spa_pod_get_int (pod, &value));
|
||||
g_assert_cmpint (value, ==, 9999);
|
||||
}
|
||||
|
||||
/* Long */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_long (LONG_MAX);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_long (pod));
|
||||
long value = 0;
|
||||
g_assert_true (wp_spa_pod_get_long (pod, &value));
|
||||
g_assert_cmpint (value, ==, LONG_MAX);
|
||||
g_assert_cmpstr ("Long", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_long (pod, LONG_MIN));
|
||||
g_assert_true (wp_spa_pod_get_long (pod, &value));
|
||||
g_assert_cmpuint (value, ==, LONG_MIN);
|
||||
}
|
||||
|
||||
/* Float */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_float (3.14);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_float (pod));
|
||||
float value = 0;
|
||||
g_assert_true (wp_spa_pod_get_float (pod, &value));
|
||||
g_assert_cmpfloat_with_epsilon (value, 3.14, 0.001);
|
||||
g_assert_cmpstr ("Float", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_float (pod, 1.0));
|
||||
g_assert_true (wp_spa_pod_get_float (pod, &value));
|
||||
g_assert_cmpfloat_with_epsilon (value, 1.0, 0.001);
|
||||
}
|
||||
|
||||
/* Double */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_double (2.718281828);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_double (pod));
|
||||
double value = 0;
|
||||
g_assert_true (wp_spa_pod_get_double (pod, &value));
|
||||
g_assert_cmpfloat_with_epsilon (value, 2.718281828, 0.0000000001);
|
||||
g_assert_cmpstr ("Double", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_double (pod, 2.0));
|
||||
g_assert_true (wp_spa_pod_get_double (pod, &value));
|
||||
g_assert_cmpfloat_with_epsilon (value, 2.0, 0.0000000001);
|
||||
}
|
||||
|
||||
/* String */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_string ("WirePlumber");
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_string (pod));
|
||||
const char *value = NULL;
|
||||
g_assert_true (wp_spa_pod_get_string (pod, &value));
|
||||
g_assert_nonnull (value);
|
||||
g_assert_cmpstr (value, ==, "WirePlumber");
|
||||
g_assert_cmpstr ("String", ==, wp_spa_pod_get_type_name (pod));
|
||||
|
||||
g_autoptr (WpSpaPod) other = wp_spa_pod_new_string ("Other");
|
||||
g_assert_nonnull (other);
|
||||
g_assert_true (wp_spa_pod_set_pod (pod, other));
|
||||
g_assert_true (wp_spa_pod_get_string (pod, &value));
|
||||
g_assert_nonnull (value);
|
||||
g_assert_cmpstr (value, ==, "Other");
|
||||
}
|
||||
|
||||
/* Bytes */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_bytes ("bytes", 5);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_bytes (pod));
|
||||
gconstpointer value = NULL;
|
||||
guint32 len = 0;
|
||||
g_assert_true (wp_spa_pod_get_bytes (pod, &value, &len));
|
||||
g_assert_nonnull (value);
|
||||
g_assert_cmpmem (value, len, "bytes", 5);
|
||||
g_assert_cmpuint (len, ==, 5);
|
||||
g_assert_cmpstr ("Bytes", ==, wp_spa_pod_get_type_name (pod));
|
||||
}
|
||||
|
||||
/* Pointer */
|
||||
{
|
||||
gint i = 3;
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_pointer ("Int", &i);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_pointer (pod));
|
||||
const char *type_name = NULL;
|
||||
gconstpointer p = NULL;
|
||||
g_assert_true (wp_spa_pod_get_pointer (pod, &type_name, &p));
|
||||
g_assert_nonnull (type_name);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpstr (type_name, ==, "Int");
|
||||
g_assert_true (p == &i);
|
||||
g_assert_cmpint (*(gint *)p, ==, 3);
|
||||
g_assert_cmpstr ("Pointer", ==, wp_spa_pod_get_type_name (pod));
|
||||
gboolean b = TRUE;
|
||||
g_assert_true (wp_spa_pod_set_pointer (pod, "Bool", &b));
|
||||
g_assert_true (wp_spa_pod_get_pointer (pod, &type_name, &p));
|
||||
g_assert_nonnull (type_name);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpstr (type_name, ==, "Bool");
|
||||
g_assert_true (p == &b);
|
||||
g_assert_cmpint (*(gboolean *)p, ==, TRUE);
|
||||
}
|
||||
|
||||
/* Fd */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_fd (4);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_fd (pod));
|
||||
gint64 value = 0;
|
||||
g_assert_true (wp_spa_pod_get_fd (pod, &value));
|
||||
g_assert_cmpint (value, ==, 4);
|
||||
g_assert_cmpstr ("Fd", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_fd (pod, 1));
|
||||
g_assert_true (wp_spa_pod_get_fd (pod, &value));
|
||||
g_assert_cmpuint (value, ==, 1);
|
||||
}
|
||||
|
||||
/* Rectangle */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_rectangle (1920, 1080);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_rectangle (pod));
|
||||
guint32 width = 0;
|
||||
guint32 height = 0;
|
||||
g_assert_true (wp_spa_pod_get_rectangle (pod, &width, &height));
|
||||
g_assert_cmpint (width, ==, 1920);
|
||||
g_assert_cmpint (height, ==, 1080);
|
||||
g_assert_cmpstr ("Rectangle", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_rectangle (pod, 640, 480));
|
||||
g_assert_true (wp_spa_pod_get_rectangle (pod, &width, &height));
|
||||
g_assert_cmpint (width, ==, 640);
|
||||
g_assert_cmpint (height, ==, 480);
|
||||
}
|
||||
|
||||
/* Fraction */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_fraction (16, 9);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_fraction (pod));
|
||||
guint32 num = 0;
|
||||
guint32 denom = 0;
|
||||
g_assert_true (wp_spa_pod_get_fraction (pod, &num, &denom));
|
||||
g_assert_cmpint (num, ==, 16);
|
||||
g_assert_cmpint (denom, ==, 9);
|
||||
g_assert_cmpstr ("Fraction", ==, wp_spa_pod_get_type_name (pod));
|
||||
g_assert_true (wp_spa_pod_set_fraction (pod, 4, 3));
|
||||
g_assert_true (wp_spa_pod_get_fraction (pod, &num, &denom));
|
||||
g_assert_cmpint (num, ==, 4);
|
||||
g_assert_cmpint (denom, ==, 3);
|
||||
}
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_spa_pod_choice (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Static Enum */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_choice (
|
||||
"Enum", "i", 0, "i", 1, "i", 2, NULL);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_choice (pod));
|
||||
g_assert_cmpstr ("Choice", ==, wp_spa_pod_get_type_name (pod));
|
||||
|
||||
g_autoptr (WpSpaPod) child = wp_spa_pod_get_choice_child (pod);
|
||||
g_assert_nonnull (child);
|
||||
g_assert_cmpstr ("Int", ==, wp_spa_pod_get_type_name (child));
|
||||
gint value = 1;
|
||||
g_assert_true (wp_spa_pod_get_int (child, &value));
|
||||
g_assert_cmpint (value, ==, 0);
|
||||
g_assert_true (wp_spa_pod_set_int (child, 3));
|
||||
g_assert_true (wp_spa_pod_get_int (child, &value));
|
||||
g_assert_cmpint (value, ==, 3);
|
||||
}
|
||||
|
||||
/* Static None */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_choice ("None", "s",
|
||||
"default value", NULL);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_choice (pod));
|
||||
g_assert_cmpstr ("Choice", ==, wp_spa_pod_get_type_name (pod));
|
||||
|
||||
{
|
||||
g_autoptr (WpSpaPod) child = wp_spa_pod_get_choice_child (pod);
|
||||
g_assert_nonnull (child);
|
||||
g_assert_cmpstr ("String", ==, wp_spa_pod_get_type_name (child));
|
||||
const char *value = NULL;
|
||||
g_assert_true (wp_spa_pod_get_string (child, &value));
|
||||
g_assert_nonnull (value);
|
||||
g_assert_cmpstr ("default value", ==, value);
|
||||
g_autoptr (WpSpaPod) str_pod = wp_spa_pod_new_string ("new value");
|
||||
g_assert_true (wp_spa_pod_set_pod (child, str_pod));
|
||||
g_assert_true (wp_spa_pod_get_string (child, &value));
|
||||
g_assert_cmpstr ("new value", ==, value);
|
||||
}
|
||||
|
||||
{
|
||||
g_autoptr (WpSpaPod) child = wp_spa_pod_get_choice_child (pod);
|
||||
g_assert_nonnull (child);
|
||||
g_assert_cmpstr ("String", ==, wp_spa_pod_get_type_name (child));
|
||||
const char *value = NULL;
|
||||
g_assert_true (wp_spa_pod_get_string (child, &value));
|
||||
g_assert_nonnull (value);
|
||||
g_assert_cmpstr ("new value", ==, value);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dynamic */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_choice ("Enum");
|
||||
wp_spa_pod_builder_add (b, "i", 0, NULL);
|
||||
wp_spa_pod_builder_add (b, "i", 1, NULL);
|
||||
wp_spa_pod_builder_add (b, "i", 2, NULL);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_choice (pod));
|
||||
g_assert_cmpstr ("Choice", ==, wp_spa_pod_get_type_name (pod));
|
||||
}
|
||||
|
||||
/* It is not possible to use the parser to get the contents of a choice, you
|
||||
* need to use the iterator API to achieve that. This is because there is no
|
||||
* `spa_pod_parser_get_choice` API in the SPA library */
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_spa_pod_array (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Dynamic */
|
||||
{
|
||||
WpSpaPodBuilder *b = wp_spa_pod_builder_new_array ();
|
||||
wp_spa_pod_builder_add (b, "b", FALSE, NULL);
|
||||
wp_spa_pod_builder_add (b, "b", TRUE, NULL);
|
||||
wp_spa_pod_builder_add (b, "b", TRUE, NULL);
|
||||
wp_spa_pod_builder_add (b, "b", FALSE, NULL);
|
||||
wp_spa_pod_builder_add (b, "b", TRUE, NULL);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_array (pod));
|
||||
g_assert_cmpstr ("Array", ==, wp_spa_pod_get_type_name (pod));
|
||||
wp_spa_pod_builder_unref (b);
|
||||
g_assert_true (wp_spa_pod_is_array (pod));
|
||||
|
||||
g_autoptr (WpSpaPod) child = wp_spa_pod_get_array_child (pod);
|
||||
g_assert_nonnull (child);
|
||||
g_assert_cmpstr ("Bool", ==, wp_spa_pod_get_type_name (child));
|
||||
gboolean value = TRUE;
|
||||
g_assert_true (wp_spa_pod_get_boolean (child, &value));
|
||||
g_assert_false (value);
|
||||
}
|
||||
|
||||
/* It is not possible to use the parser to get the contents of an array, you
|
||||
* need to use the iterator API to achieve that. This is because there is no
|
||||
* `spa_pod_parser_get_array` API in the SPA library. */
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_spa_pod_object (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Static */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_object (
|
||||
"Props", "Props",
|
||||
"mute", "b", FALSE,
|
||||
"volume", "f", 0.5,
|
||||
"frequency", "i", 440,
|
||||
"device", "s", "device-name",
|
||||
"deviceFd", "h", 5,
|
||||
NULL);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_object (pod));
|
||||
g_assert_cmpstr ("Object", ==, wp_spa_pod_get_type_name (pod));
|
||||
|
||||
const char *id_name;
|
||||
gboolean mute = TRUE;
|
||||
float vol = 0.0;
|
||||
gint frequency;
|
||||
const char *device;
|
||||
gint64 device_fd;
|
||||
g_assert_true (wp_spa_pod_get_object (pod,
|
||||
"Props", &id_name,
|
||||
"mute", "b", &mute,
|
||||
"volume", "f", &vol,
|
||||
"frequency", "i", &frequency,
|
||||
"device", "s", &device,
|
||||
"deviceFd", "h", &device_fd,
|
||||
NULL));
|
||||
g_assert_cmpstr (id_name, ==, "Props");
|
||||
g_assert_false (mute);
|
||||
g_assert_cmpfloat_with_epsilon (vol, 0.5, 0.01);
|
||||
g_assert_cmpint (frequency, ==, 440);
|
||||
g_assert_cmpstr (device, ==, "device-name");
|
||||
g_assert_cmpint (device_fd, ==, 5);
|
||||
}
|
||||
|
||||
/* Dynamic */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_object (
|
||||
"Props", "Props");
|
||||
wp_spa_pod_builder_add_property (b, "mute");
|
||||
wp_spa_pod_builder_add_boolean (b, FALSE);
|
||||
wp_spa_pod_builder_add_property (b, "volume");
|
||||
wp_spa_pod_builder_add_float (b, 0.5);
|
||||
wp_spa_pod_builder_add_property (b, "frequency");
|
||||
wp_spa_pod_builder_add_int (b, 440);
|
||||
wp_spa_pod_builder_add_property (b, "device");
|
||||
wp_spa_pod_builder_add_string (b, "device-name");
|
||||
wp_spa_pod_builder_add_property (b, "deviceFd");
|
||||
wp_spa_pod_builder_add_fd (b, 5);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_object (pod));
|
||||
g_assert_cmpstr ("Object", ==, wp_spa_pod_get_type_name (pod));
|
||||
|
||||
const char *id_name;
|
||||
gboolean mute = TRUE;
|
||||
float vol = 0.0;
|
||||
gint frequency;
|
||||
const char *device;
|
||||
gint64 device_fd;
|
||||
g_autoptr (WpSpaPodParser) p = wp_spa_pod_parser_new_object (pod,
|
||||
"Props", &id_name);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_parser_get (p, "mute", "b", &mute, NULL));
|
||||
g_assert_true (wp_spa_pod_parser_get (p, "volume", "f", &vol, NULL));
|
||||
g_assert_true (wp_spa_pod_parser_get (p, "frequency", "i", &frequency, NULL));
|
||||
g_assert_true (wp_spa_pod_parser_get (p, "device", "s", &device, NULL));
|
||||
g_assert_true (wp_spa_pod_parser_get (p, "deviceFd", "h", &device_fd, NULL));
|
||||
wp_spa_pod_parser_end (p);
|
||||
g_assert_cmpstr (id_name, ==, "Props");
|
||||
g_assert_false (mute);
|
||||
g_assert_cmpfloat_with_epsilon (vol, 0.5, 0.01);
|
||||
g_assert_cmpint (frequency, ==, 440);
|
||||
g_assert_cmpstr (device, ==, "device-name");
|
||||
g_assert_cmpint (device_fd, ==, 5);
|
||||
}
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_spa_pod_struct (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Dynamic */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_struct ();
|
||||
wp_spa_pod_builder_add_boolean (b, TRUE);
|
||||
wp_spa_pod_builder_add_id (b, 2);
|
||||
wp_spa_pod_builder_add_int (b, 8);
|
||||
wp_spa_pod_builder_add_long (b, 64);
|
||||
wp_spa_pod_builder_add_float (b, 3.14);
|
||||
wp_spa_pod_builder_add_double (b, 2.718281828);
|
||||
wp_spa_pod_builder_add_string (b, "WirePlumber");
|
||||
wp_spa_pod_builder_add_bytes (b, "bytes", 5);
|
||||
wp_spa_pod_builder_add_pointer (b, "Struct", b);
|
||||
wp_spa_pod_builder_add_fd (b, 4);
|
||||
wp_spa_pod_builder_add_rectangle (b, 1920, 1080);
|
||||
wp_spa_pod_builder_add_fraction (b, 16, 9);
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_int (35254);
|
||||
wp_spa_pod_builder_add_pod (b, pod);
|
||||
}
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_object (
|
||||
"Props", "Props",
|
||||
"mute", "b", FALSE,
|
||||
NULL);
|
||||
wp_spa_pod_builder_add (b, "P", pod, NULL);
|
||||
}
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_struct (pod));
|
||||
g_assert_cmpstr ("Struct", ==, wp_spa_pod_get_type_name (pod));
|
||||
|
||||
g_autoptr (WpSpaPodParser) p = wp_spa_pod_parser_new_struct (pod);
|
||||
g_assert_nonnull (pod);
|
||||
|
||||
gboolean value_boolean;
|
||||
g_assert_true (wp_spa_pod_parser_get_boolean (p, &value_boolean));
|
||||
g_assert_true (value_boolean);
|
||||
|
||||
guint32 value_id;
|
||||
g_assert_true (wp_spa_pod_parser_get_id (p, &value_id));
|
||||
g_assert_cmpuint (value_id, ==, 2);
|
||||
|
||||
gint value_int;
|
||||
g_assert_true (wp_spa_pod_parser_get_int (p, &value_int));
|
||||
g_assert_cmpint (value_int, ==, 8);
|
||||
|
||||
glong value_long;
|
||||
g_assert_true (wp_spa_pod_parser_get_long (p, &value_long));
|
||||
g_assert_cmpint (value_long, ==, 64);
|
||||
|
||||
float value_float;
|
||||
g_assert_true (wp_spa_pod_parser_get_float (p, &value_float));
|
||||
g_assert_cmpfloat_with_epsilon (value_float, 3.14, 0.001);
|
||||
|
||||
double value_double;
|
||||
g_assert_true (wp_spa_pod_parser_get_double (p, &value_double));
|
||||
g_assert_cmpfloat_with_epsilon (value_double, 2.718281828, 0.0000000001);
|
||||
|
||||
const char *value_string;
|
||||
g_assert_true (wp_spa_pod_parser_get_string (p, &value_string));
|
||||
g_assert_cmpstr (value_string, ==, "WirePlumber");
|
||||
|
||||
gconstpointer value_bytes;
|
||||
guint32 len_bytes;
|
||||
g_assert_true (wp_spa_pod_parser_get_bytes (p, &value_bytes, &len_bytes));
|
||||
g_assert_cmpmem (value_bytes, len_bytes, "bytes", 5);
|
||||
g_assert_cmpuint (len_bytes, ==, 5);
|
||||
|
||||
gconstpointer value_pointer;
|
||||
const char *type_pointer;
|
||||
g_assert_true (wp_spa_pod_parser_get_pointer (p, &type_pointer, &value_pointer));
|
||||
g_assert_nonnull (type_pointer);
|
||||
g_assert_nonnull (value_pointer);
|
||||
g_assert_cmpstr (type_pointer, ==, "Struct");
|
||||
g_assert_true (value_pointer == b);
|
||||
|
||||
gint64 value_fd;
|
||||
g_assert_true (wp_spa_pod_parser_get_fd (p, &value_fd));
|
||||
g_assert_cmpint (value_fd, ==, 4);
|
||||
|
||||
guint32 value_width;
|
||||
guint32 value_height;
|
||||
g_assert_true (wp_spa_pod_parser_get_rectangle (p, &value_width, &value_height));
|
||||
g_assert_cmpuint (value_width, ==, 1920);
|
||||
g_assert_cmpuint (value_height, ==, 1080);
|
||||
|
||||
guint32 value_num;
|
||||
guint32 value_denom;
|
||||
g_assert_true (wp_spa_pod_parser_get_fraction (p, &value_num, &value_denom));
|
||||
g_assert_cmpuint (value_num, ==, 16);
|
||||
g_assert_cmpuint (value_denom, ==, 9);
|
||||
|
||||
g_autoptr (WpSpaPod) value_pod = wp_spa_pod_parser_get_pod (p);
|
||||
g_assert_nonnull (value_pod);
|
||||
gint value_pod_int;
|
||||
g_assert_true (wp_spa_pod_get_int (value_pod, &value_pod_int));
|
||||
g_assert_cmpint (value_pod_int, ==, 35254);
|
||||
|
||||
g_autoptr (WpSpaPod) value_object = NULL;
|
||||
g_assert_true (wp_spa_pod_parser_get (p, "P", &value_object, NULL));
|
||||
g_assert_nonnull (value_object);
|
||||
const char *id_name;
|
||||
gboolean mute = TRUE;
|
||||
|
||||
g_assert_true (wp_spa_pod_get_object (value_object,
|
||||
"Props", &id_name,
|
||||
"mute", "b", &mute,
|
||||
NULL));
|
||||
g_assert_cmpstr (id_name, ==, "Props");
|
||||
g_assert_false (mute);
|
||||
}
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_spa_pod_sequence (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Static */
|
||||
{
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_sequence (0,
|
||||
10, "Properties", "l", 9999, NULL);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_sequence (pod));
|
||||
g_assert_cmpstr ("Sequence", ==, wp_spa_pod_get_type_name (pod));
|
||||
}
|
||||
|
||||
/* Dynamic */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_sequence (0);
|
||||
wp_spa_pod_builder_add_control (b, 10, "Properties");
|
||||
wp_spa_pod_builder_add_long (b, 9999);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_sequence (pod));
|
||||
g_assert_cmpstr ("Sequence", ==, wp_spa_pod_get_type_name (pod));
|
||||
}
|
||||
|
||||
/* It is not possible to use the parser to get the contents of a sequence, you
|
||||
* need to use the iterator API to achieve that. This is because there is no
|
||||
* `spa_pod_parser_get_sequence` API in the SPA library. */
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
static void
|
||||
choice_foreach (const GValue *item, gpointer data)
|
||||
{
|
||||
gint *total = data;
|
||||
const gint *value = g_value_get_pointer (item);
|
||||
*total += *value;
|
||||
}
|
||||
|
||||
static void
|
||||
array_foreach (const GValue *item, gpointer data)
|
||||
{
|
||||
gint *total = data;
|
||||
const gint *value = g_value_get_pointer (item);
|
||||
*total += *value;
|
||||
}
|
||||
|
||||
static void
|
||||
object_foreach (const GValue *item, gpointer data)
|
||||
{
|
||||
guint32 *total_props = data;
|
||||
const WpSpaPod *prop = g_value_get_boxed (item);
|
||||
g_assert_true (wp_spa_pod_is_property (prop));
|
||||
*total_props += 1;
|
||||
}
|
||||
|
||||
static void
|
||||
struct_foreach (const GValue *item, gpointer data)
|
||||
{
|
||||
guint32 *total_fields = data;
|
||||
*total_fields += 1;
|
||||
}
|
||||
|
||||
static void
|
||||
sequence_foreach (const GValue *item, gpointer data)
|
||||
{
|
||||
guint32 *offset_total = data;
|
||||
const WpSpaPod *control = g_value_get_boxed (item);
|
||||
g_assert_true (wp_spa_pod_is_control (control));
|
||||
guint32 offset = 0;
|
||||
g_assert_true (wp_spa_pod_get_control (control, &offset, NULL, NULL));
|
||||
*offset_total += offset;
|
||||
}
|
||||
|
||||
static void
|
||||
test_spa_pod_iterator (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Choice */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_choice ("Enum");
|
||||
wp_spa_pod_builder_add (b, "i", 0, NULL);
|
||||
wp_spa_pod_builder_add (b, "i", 1, NULL);
|
||||
wp_spa_pod_builder_add (b, "i", 2, NULL);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
|
||||
g_autoptr (WpIterator) it = wp_spa_pod_iterator_new (pod);
|
||||
g_assert_nonnull (it);
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
gpointer p = g_value_get_pointer (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpint (*(gint *)p, ==, 0);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
gpointer p = g_value_get_pointer (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpint (*(gint *)p, ==, 1);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
gpointer p = g_value_get_pointer (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpint (*(gint *)p, ==, 2);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
g_assert_false (wp_iterator_next (it, NULL));
|
||||
}
|
||||
|
||||
gint total = 0;
|
||||
g_assert_true (wp_iterator_foreach (it, choice_foreach, &total));
|
||||
g_assert_cmpint (total, ==, 3);
|
||||
|
||||
}
|
||||
|
||||
/* Array */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_array ();
|
||||
wp_spa_pod_builder_add_int (b, 1);
|
||||
wp_spa_pod_builder_add_int (b, 2);
|
||||
wp_spa_pod_builder_add_int (b, 3);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
|
||||
g_autoptr (WpIterator) it = wp_spa_pod_iterator_new (pod);
|
||||
g_assert_nonnull (it);
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
gpointer p = g_value_get_pointer (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpint (*(gint *)p, ==, 1);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
gpointer p = g_value_get_pointer (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpint (*(gint *)p, ==, 2);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
gpointer p = g_value_get_pointer (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_cmpint (*(gint *)p, ==, 3);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
g_assert_false (wp_iterator_next (it, NULL));
|
||||
}
|
||||
|
||||
gint total = 0;
|
||||
g_assert_true (wp_iterator_foreach (it, array_foreach, &total));
|
||||
g_assert_cmpint (total, ==, 6);
|
||||
}
|
||||
|
||||
/* Object */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_object (
|
||||
"Props", "Props");
|
||||
wp_spa_pod_builder_add_property (b, "mute");
|
||||
wp_spa_pod_builder_add_boolean (b, FALSE);
|
||||
wp_spa_pod_builder_add_property (b, "device");
|
||||
wp_spa_pod_builder_add_string (b, "device-name");
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
|
||||
g_autoptr (WpIterator) it = wp_spa_pod_iterator_new (pod);
|
||||
g_assert_nonnull (it);
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
WpSpaPod *p = g_value_get_boxed (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_true (wp_spa_pod_is_property (p));
|
||||
const char *key = NULL;
|
||||
g_autoptr (WpSpaPod) value = NULL;
|
||||
g_assert_true (wp_spa_pod_get_property (p, &key, &value));
|
||||
g_assert_cmpstr (key, ==, "mute");
|
||||
gboolean b = TRUE;
|
||||
g_assert_true (wp_spa_pod_get_boolean (value, &b));
|
||||
g_assert_false (b);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
WpSpaPod *p = g_value_get_boxed (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_true (wp_spa_pod_is_property (p));
|
||||
const char *key = NULL;
|
||||
g_autoptr (WpSpaPod) value = NULL;
|
||||
g_assert_true (wp_spa_pod_get_property (p, &key, &value));
|
||||
g_assert_cmpstr (key, ==, "device");
|
||||
const char *s = NULL;
|
||||
g_assert_true (wp_spa_pod_get_string (value, &s));
|
||||
g_assert_cmpstr (s, ==, "device-name");
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
g_assert_false (wp_iterator_next (it, NULL));
|
||||
}
|
||||
|
||||
guint32 total_props = 0;
|
||||
g_assert_true (wp_iterator_foreach (it, object_foreach, &total_props));
|
||||
g_assert_cmpuint (total_props, ==, 2);
|
||||
}
|
||||
|
||||
/* Struct */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_struct ();
|
||||
wp_spa_pod_builder_add_boolean (b, TRUE);
|
||||
wp_spa_pod_builder_add_id (b, 2);
|
||||
wp_spa_pod_builder_add_int (b, 8);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
|
||||
g_autoptr (WpIterator) it = wp_spa_pod_iterator_new (pod);
|
||||
g_assert_nonnull (it);
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
WpSpaPod *p = g_value_get_boxed (&next);
|
||||
g_assert_nonnull (p);
|
||||
gboolean v = FALSE;
|
||||
g_assert_true (wp_spa_pod_get_boolean (p, &v));
|
||||
g_assert_true (v);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
WpSpaPod *p = g_value_get_boxed (&next);
|
||||
g_assert_nonnull (p);
|
||||
guint32 v = 0;
|
||||
g_assert_true (wp_spa_pod_get_id (p, &v));
|
||||
g_assert_cmpuint (v, ==, 2);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
WpSpaPod *p = g_value_get_boxed (&next);
|
||||
g_assert_nonnull (p);
|
||||
gint v = 0;
|
||||
g_assert_true (wp_spa_pod_get_int (p, &v));
|
||||
g_assert_cmpint (v, ==, 8);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
g_assert_false (wp_iterator_next (it, NULL));
|
||||
}
|
||||
|
||||
guint32 total_fields = 0;
|
||||
g_assert_true (wp_iterator_foreach (it, struct_foreach, &total_fields));
|
||||
g_assert_cmpuint (total_fields, ==, 3);
|
||||
}
|
||||
|
||||
/* Sequence */
|
||||
{
|
||||
g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_sequence (0);
|
||||
wp_spa_pod_builder_add_control (b, 10, "Properties");
|
||||
wp_spa_pod_builder_add_float (b, 0.33);
|
||||
wp_spa_pod_builder_add_control (b, 40, "Properties");
|
||||
wp_spa_pod_builder_add_float (b, 0.66);
|
||||
g_autoptr (WpSpaPod) pod = wp_spa_pod_builder_end (b);
|
||||
g_assert_nonnull (pod);
|
||||
|
||||
g_autoptr (WpIterator) it = wp_spa_pod_iterator_new (pod);
|
||||
g_assert_nonnull (it);
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
WpSpaPod *p = g_value_get_boxed (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_true (wp_spa_pod_is_control (p));
|
||||
guint32 offset = 0;
|
||||
const char *type_name = NULL;
|
||||
g_autoptr (WpSpaPod) value = NULL;
|
||||
g_assert_true (wp_spa_pod_get_control (p, &offset, &type_name, &value));
|
||||
g_assert_cmpuint (offset, ==, 10);
|
||||
g_assert_cmpstr (type_name, ==, "Properties");
|
||||
float f = 0;
|
||||
g_assert_true (wp_spa_pod_get_float (value, &f));
|
||||
g_assert_cmpfloat_with_epsilon (f, 0.33, 0.001);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
WpSpaPod *p = g_value_get_boxed (&next);
|
||||
g_assert_nonnull (p);
|
||||
g_assert_true (wp_spa_pod_is_control (p));
|
||||
guint32 offset = 0;
|
||||
const char *type_name = NULL;
|
||||
g_autoptr (WpSpaPod) value = NULL;
|
||||
g_assert_true (wp_spa_pod_get_control (p, &offset, &type_name, &value));
|
||||
g_assert_cmpuint (offset, ==, 40);
|
||||
g_assert_cmpstr (type_name, ==, "Properties");
|
||||
float f = 0;
|
||||
g_assert_true (wp_spa_pod_get_float (value, &f));
|
||||
g_assert_cmpfloat_with_epsilon (f, 0.66, 0.001);
|
||||
g_value_unset (&next);
|
||||
}
|
||||
|
||||
{
|
||||
g_assert_false (wp_iterator_next (it, NULL));
|
||||
}
|
||||
|
||||
guint32 offset_total = 0;
|
||||
g_assert_true (wp_iterator_foreach (it, sequence_foreach, &offset_total));
|
||||
g_assert_cmpuint (offset_total, ==, 50);
|
||||
}
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_spa_pod_unique_owner (void)
|
||||
{
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Create an object */
|
||||
WpSpaPod *pod = wp_spa_pod_new_object (
|
||||
"PropInfo", "PropInfo",
|
||||
"id", "I", 1,
|
||||
"name", "s", "prop-info-name",
|
||||
NULL);
|
||||
g_assert_nonnull (pod);
|
||||
g_assert_true (wp_spa_pod_is_unique_owner (pod));
|
||||
|
||||
/* Get the first property using an iterator */
|
||||
GValue next = G_VALUE_INIT;
|
||||
g_autoptr (WpSpaPod) property = NULL;
|
||||
{
|
||||
g_autoptr (WpIterator) it = wp_spa_pod_iterator_new (pod);
|
||||
g_assert_nonnull (it);
|
||||
g_assert_true (wp_iterator_next (it, &next));
|
||||
property = g_value_dup_boxed (&next);
|
||||
}
|
||||
g_assert_nonnull (property);
|
||||
g_assert_true (wp_spa_pod_is_property (property));
|
||||
{
|
||||
g_autoptr (WpSpaPod) value = NULL;
|
||||
const char *key = NULL;
|
||||
g_assert_true (wp_spa_pod_get_property (property, &key, &value));
|
||||
g_assert_nonnull (key);
|
||||
g_assert_cmpstr (key, ==, "id");
|
||||
g_assert_nonnull (value);
|
||||
guint32 id = 0;
|
||||
g_assert_true (wp_spa_pod_get_id (value, &id));
|
||||
g_assert_cmpuint (id, ==, 1);
|
||||
}
|
||||
|
||||
/* Own the data */
|
||||
g_assert_true (wp_spa_pod_is_unique_owner (pod));
|
||||
g_assert_false (wp_spa_pod_is_unique_owner (property));
|
||||
property = wp_spa_pod_ensure_unique_owner (property);
|
||||
g_assert_true (wp_spa_pod_is_unique_owner (pod));
|
||||
g_assert_true (wp_spa_pod_is_unique_owner (property));
|
||||
|
||||
/* Destroy the object */
|
||||
wp_spa_pod_unref (pod);
|
||||
g_assert_true (wp_spa_pod_is_unique_owner (property));
|
||||
|
||||
/* Make sure the property data is still valid */
|
||||
{
|
||||
g_autoptr (WpSpaPod) value = NULL;
|
||||
const char *key = NULL;
|
||||
g_assert_true (wp_spa_pod_get_property (property, &key, &value));
|
||||
g_assert_nonnull (key);
|
||||
g_assert_cmpstr (key, ==, "id");
|
||||
g_assert_nonnull (value);
|
||||
guint32 id = 0;
|
||||
g_assert_true (wp_spa_pod_get_id (value, &id));
|
||||
g_assert_cmpuint (id, ==, 1);
|
||||
}
|
||||
|
||||
/* Destroy the property */
|
||||
g_value_unset (&next);
|
||||
|
||||
wp_spa_type_deinit ();
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/wp/spa-pod/basic", test_spa_pod_basic);
|
||||
g_test_add_func ("/wp/spa-pod/choice", test_spa_pod_choice);
|
||||
g_test_add_func ("/wp/spa-pod/array", test_spa_pod_array);
|
||||
g_test_add_func ("/wp/spa-pod/object", test_spa_pod_object);
|
||||
g_test_add_func ("/wp/spa-pod/struct", test_spa_pod_struct);
|
||||
g_test_add_func ("/wp/spa-pod/sequence", test_spa_pod_sequence);
|
||||
g_test_add_func ("/wp/spa-pod/iterator", test_spa_pod_iterator);
|
||||
g_test_add_func ("/wp/spa-pod/unique-owner", test_spa_pod_unique_owner);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue