mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-09 13:30:06 -05:00
tests: add more tests
This commit is contained in:
parent
23c439fd66
commit
69b7c18718
6 changed files with 386 additions and 1 deletions
|
|
@ -22,6 +22,8 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
#include <pipewire/main-loop.h>
|
||||
#include <pipewire/remote.h>
|
||||
|
||||
#define TEST_FUNC(a,b,func) \
|
||||
|
|
@ -65,9 +67,150 @@ static void test_abi(void)
|
|||
spa_assert(pw_remote_state_as_string(PW_REMOTE_STATE_CONNECTED) != NULL);
|
||||
}
|
||||
|
||||
static void remote_destroy_error(void *data)
|
||||
{
|
||||
spa_assert_not_reached();
|
||||
}
|
||||
static void remote_info_changed_error(void *data, const struct pw_core_info *info)
|
||||
{
|
||||
spa_assert_not_reached();
|
||||
}
|
||||
static void remote_sync_reply_error(void *data, uint32_t seq)
|
||||
{
|
||||
spa_assert_not_reached();
|
||||
}
|
||||
static void remote_state_changed_error(void *data, enum pw_remote_state old,
|
||||
enum pw_remote_state state, const char *error)
|
||||
{
|
||||
spa_assert_not_reached();
|
||||
}
|
||||
static void remote_error_error(void *data, uint32_t id, int res, const char *error)
|
||||
{
|
||||
spa_assert_not_reached();
|
||||
}
|
||||
static void remote_exported_error(void *data, uint32_t id)
|
||||
{
|
||||
spa_assert_not_reached();
|
||||
}
|
||||
|
||||
static const struct pw_remote_events remote_events_error =
|
||||
{
|
||||
PW_VERSION_REMOTE_EVENTS,
|
||||
.destroy = remote_destroy_error,
|
||||
.info_changed = remote_info_changed_error,
|
||||
.sync_reply = remote_sync_reply_error,
|
||||
.state_changed = remote_state_changed_error,
|
||||
.error = remote_error_error,
|
||||
.exported = remote_exported_error,
|
||||
};
|
||||
|
||||
static int destroy_count = 0;
|
||||
static void remote_destroy_count(void *data)
|
||||
{
|
||||
destroy_count++;
|
||||
}
|
||||
static void test_create(void)
|
||||
{
|
||||
struct pw_main_loop *loop;
|
||||
struct pw_core *core;
|
||||
struct pw_remote *remote;
|
||||
struct pw_remote_events remote_events = remote_events_error;
|
||||
struct spa_hook listener = { 0, };
|
||||
const char *error = NULL;
|
||||
|
||||
loop = pw_main_loop_new(NULL);
|
||||
core = pw_core_new(pw_main_loop_get_loop(loop), NULL, 12);
|
||||
|
||||
remote = pw_remote_new(core, NULL, 12);
|
||||
spa_assert(remote != NULL);
|
||||
pw_remote_add_listener(remote, &listener, &remote_events, remote);
|
||||
|
||||
/* check core */
|
||||
spa_assert(pw_remote_get_core(remote) == core);
|
||||
/* check user data */
|
||||
spa_assert(pw_remote_get_user_data(remote) != NULL);
|
||||
/* check state */
|
||||
spa_assert(pw_remote_get_state(remote, &error) == PW_REMOTE_STATE_UNCONNECTED);
|
||||
spa_assert(error == NULL);
|
||||
|
||||
/* check core proxy, only available when connected */
|
||||
spa_assert(pw_remote_get_core_proxy(remote) == NULL);
|
||||
/* check core info, only available when connected */
|
||||
spa_assert(pw_remote_get_core_info(remote) == NULL);
|
||||
|
||||
/* check some non-existing proxies */
|
||||
spa_assert(pw_remote_find_proxy(remote, 0) == NULL);
|
||||
spa_assert(pw_remote_find_proxy(remote, 5) == NULL);
|
||||
|
||||
/* check destroy */
|
||||
destroy_count = 0;
|
||||
remote_events.destroy = remote_destroy_count;
|
||||
pw_remote_destroy(remote);
|
||||
spa_assert(destroy_count == 1);
|
||||
|
||||
pw_core_destroy(core);
|
||||
pw_main_loop_destroy(loop);
|
||||
}
|
||||
|
||||
static void test_properties(void)
|
||||
{
|
||||
struct pw_main_loop *loop;
|
||||
struct pw_core *core;
|
||||
const struct pw_properties *props;
|
||||
struct pw_remote *remote;
|
||||
struct pw_remote_events remote_events = remote_events_error;
|
||||
struct spa_hook listener = { NULL, };
|
||||
struct spa_dict_item items[3];
|
||||
|
||||
loop = pw_main_loop_new(NULL);
|
||||
core = pw_core_new(pw_main_loop_get_loop(loop), NULL, 0);
|
||||
remote = pw_remote_new(core,
|
||||
pw_properties_new("foo", "bar",
|
||||
"biz", "fuzz",
|
||||
NULL),
|
||||
0);
|
||||
spa_assert(remote != NULL);
|
||||
spa_assert(pw_remote_get_user_data(remote) == NULL);
|
||||
pw_remote_add_listener(remote, &listener, &remote_events, remote);
|
||||
|
||||
props = pw_remote_get_properties(remote);
|
||||
spa_assert(props != NULL);
|
||||
spa_assert(!strcmp(pw_properties_get(props, "foo"), "bar"));
|
||||
spa_assert(!strcmp(pw_properties_get(props, "biz"), "fuzz"));
|
||||
spa_assert(pw_properties_get(props, "buzz") == NULL);
|
||||
|
||||
/* remove foo */
|
||||
items[0] = SPA_DICT_ITEM_INIT("foo", NULL);
|
||||
/* change biz */
|
||||
items[1] = SPA_DICT_ITEM_INIT("biz", "buzz");
|
||||
/* add buzz */
|
||||
items[2] = SPA_DICT_ITEM_INIT("buzz", "frizz");
|
||||
/* update properties does not emit the info_changed signal
|
||||
* because that is only emited when the remote core properties
|
||||
* changed */
|
||||
pw_remote_update_properties(remote, &SPA_DICT_INIT(items, 3));
|
||||
|
||||
spa_assert(props == pw_remote_get_properties(remote));
|
||||
spa_assert(pw_properties_get(props, "foo") == NULL);
|
||||
spa_assert(!strcmp(pw_properties_get(props, "biz"), "buzz"));
|
||||
spa_assert(!strcmp(pw_properties_get(props, "buzz"), "frizz"));
|
||||
|
||||
/* check destroy */
|
||||
destroy_count = 0;
|
||||
remote_events.destroy = remote_destroy_count;
|
||||
pw_core_destroy(core);
|
||||
spa_assert(destroy_count == 1);
|
||||
|
||||
pw_main_loop_destroy(loop);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pw_init(&argc, &argv);
|
||||
|
||||
test_abi();
|
||||
test_create();
|
||||
test_properties();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue