Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wireplumber
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pkg
wireplumber
Commits
68223e0e
Commit
68223e0e
authored
4 years ago
by
George Kiagiadakis
Browse files
Options
Downloads
Patches
Plain Diff
tests: add unit test for WpCore disconnection
parent
8e87bd32
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/common/test-server.h
+5
-4
5 additions, 4 deletions
tests/common/test-server.h
tests/wp/core.c
+116
-0
116 additions, 0 deletions
tests/wp/core.c
tests/wp/meson.build
+7
-0
7 additions, 0 deletions
tests/wp/meson.build
with
128 additions
and
4 deletions
tests/common/test-server.h
+
5
−
4
View file @
68223e0e
...
...
@@ -41,10 +41,11 @@ wp_test_server_setup (WpTestServer *self)
static
inline
void
wp_test_server_teardown
(
WpTestServer
*
self
)
{
pw_thread_loop_stop
(
self
->
thread_loop
);
pw_context_destroy
(
self
->
context
);
pw_thread_loop_destroy
(
self
->
thread_loop
);
g_free
(
self
->
name
);
if
(
self
->
thread_loop
)
pw_thread_loop_stop
(
self
->
thread_loop
);
g_clear_pointer
(
&
self
->
context
,
pw_context_destroy
);
g_clear_pointer
(
&
self
->
thread_loop
,
pw_thread_loop_destroy
);
g_clear_pointer
(
&
self
->
name
,
g_free
);
}
typedef
void
WpTestServerLocker
;
...
...
This diff is collapsed.
Click to expand it.
tests/wp/core.c
0 → 100644
+
116
−
0
View file @
68223e0e
/* WirePlumber
*
* Copyright © 2020 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#include
"../common/base-test-fixture.h"
#include
<wp/wp.h>
typedef
struct
{
WpBaseTestFixture
base
;
WpObjectManager
*
om
;
gboolean
disconnected
;
}
TestFixture
;
static
void
test_core_setup
(
TestFixture
*
self
,
gconstpointer
user_data
)
{
wp_base_test_fixture_setup
(
&
self
->
base
,
WP_BASE_TEST_FLAG_DONT_CONNECT
);
/* remove the "disconnected" handler that fails the test */
g_signal_handlers_disconnect_by_data
(
self
->
base
.
core
,
&
self
->
base
);
self
->
om
=
wp_object_manager_new
();
self
->
disconnected
=
FALSE
;
}
static
void
test_core_teardown
(
TestFixture
*
self
,
gconstpointer
user_data
)
{
g_clear_object
(
&
self
->
om
);
wp_base_test_fixture_teardown
(
&
self
->
base
);
}
static
void
expect_disconnected
(
WpCore
*
core
,
TestFixture
*
f
)
{
f
->
disconnected
=
TRUE
;
g_main_loop_quit
(
f
->
base
.
loop
);
}
static
void
expect_object_added
(
WpObjectManager
*
om
,
WpProxy
*
proxy
,
TestFixture
*
f
)
{
g_assert_true
(
WP_IS_CLIENT
(
proxy
));
g_main_loop_quit
(
f
->
base
.
loop
);
}
static
void
test_core_server_disconnected
(
TestFixture
*
f
,
gconstpointer
data
)
{
g_signal_connect
(
f
->
base
.
core
,
"disconnected"
,
G_CALLBACK
(
expect_disconnected
),
f
);
g_signal_connect
(
f
->
om
,
"object-added"
,
G_CALLBACK
(
expect_object_added
),
f
);
wp_object_manager_add_interest_1
(
f
->
om
,
WP_TYPE_CLIENT
,
NULL
);
wp_core_install_object_manager
(
f
->
base
.
core
,
f
->
om
);
/* connect */
g_assert_true
(
wp_core_connect
(
f
->
base
.
core
));
g_assert_true
(
wp_core_is_connected
(
f
->
base
.
core
));
/* wait for the object manager to collect the client proxy */
g_main_loop_run
(
f
->
base
.
loop
);
g_assert_cmpuint
(
wp_object_manager_get_n_objects
(
f
->
om
),
==
,
1
);
/* destroy the server and wait for the disconnected signal */
wp_test_server_teardown
(
&
f
->
base
.
server
);
g_main_loop_run
(
f
->
base
.
loop
);
g_assert_true
(
f
->
disconnected
);
g_assert_false
(
wp_core_is_connected
(
f
->
base
.
core
));
g_assert_cmpuint
(
wp_object_manager_get_n_objects
(
f
->
om
),
==
,
0
);
}
static
void
test_core_client_disconnected
(
TestFixture
*
f
,
gconstpointer
data
)
{
g_signal_connect
(
f
->
base
.
core
,
"disconnected"
,
G_CALLBACK
(
expect_disconnected
),
f
);
g_signal_connect
(
f
->
om
,
"object-added"
,
G_CALLBACK
(
expect_object_added
),
f
);
wp_object_manager_add_interest_1
(
f
->
om
,
WP_TYPE_CLIENT
,
NULL
);
wp_core_install_object_manager
(
f
->
base
.
core
,
f
->
om
);
/* connect */
g_assert_true
(
wp_core_connect
(
f
->
base
.
core
));
g_assert_true
(
wp_core_is_connected
(
f
->
base
.
core
));
/* wait for the object manager to collect the client proxy */
g_main_loop_run
(
f
->
base
.
loop
);
g_assert_cmpuint
(
wp_object_manager_get_n_objects
(
f
->
om
),
==
,
1
);
/* disconnect and expect the disconnected signal */
wp_core_disconnect
(
f
->
base
.
core
);
g_assert_true
(
f
->
disconnected
);
g_assert_false
(
wp_core_is_connected
(
f
->
base
.
core
));
g_assert_cmpuint
(
wp_object_manager_get_n_objects
(
f
->
om
),
==
,
0
);
}
gint
main
(
gint
argc
,
gchar
*
argv
[])
{
g_test_init
(
&
argc
,
&
argv
,
NULL
);
wp_init
(
WP_INIT_ALL
);
g_test_add
(
"/wp/core/server-disconnected"
,
TestFixture
,
NULL
,
test_core_setup
,
test_core_server_disconnected
,
test_core_teardown
);
g_test_add
(
"/wp/core/client-disconnected"
,
TestFixture
,
NULL
,
test_core_setup
,
test_core_client_disconnected
,
test_core_teardown
);
return
g_test_run
();
}
This diff is collapsed.
Click to expand it.
tests/wp/meson.build
+
7
−
0
View file @
68223e0e
...
...
@@ -9,6 +9,13 @@ common_args = [
'-DG_LOG_USE_STRUCTURED'
,
]
test
(
'test-core'
,
executable
(
'test-core'
,
'core.c'
,
dependencies
:
common_deps
,
c_args
:
common_args
),
env
:
common_env
,
)
test
(
'test-endpoint'
,
executable
(
'test-endpoint'
,
'endpoint.c'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment