linking tests: add default device test cases

This commit is contained in:
Ashok Sidipotu 2023-01-05 17:07:37 +05:30 committed by Julian Bouzas
parent db4ace420c
commit 669b91678d
5 changed files with 104 additions and 2 deletions

View file

@ -24,3 +24,17 @@ test(
args: ['script-tests', '01-test-linking-non-default-device-node-capture.lua'],
env: common_env,
)
test(
'test-linking-default-device-node',
script_tester,
args: ['script-tests', '02-test-linking-default-device-node.lua'],
env: common_env,
)
test(
'test-linking-default-device-node-capture',
script_tester,
args: ['script-tests', '03-test-linking-default-device-node-capture.lua'],
env: common_env,
)

View file

@ -26,7 +26,7 @@ SimpleEventHook {
return
end
Log.info (si, string.format ("testPolicy: handling item: %s (%s) si id(%s)",
Log.info (si, string.format ("handling item: %s (%s) si id(%s)",
tostring (si_props ["node.name"]),
tostring (si_props ["node.id"]), si.id))

View file

@ -26,7 +26,7 @@ SimpleEventHook {
return
end
Log.info (si, string.format ("testPolicy: handling item: %s (%s) si id(%s)",
Log.info (si, string.format ("handling item: %s (%s) si id(%s)",
tostring (si_props ["node.name"]),
tostring (si_props ["node.id"]), si.id))

View file

@ -0,0 +1,44 @@
-- Tests linking of streams and default devices. Two device nodes are setup,
-- among which only one is selected as default device node.
local pu = require ("policy-utils")
local tu = require ("test-utils")
Script.async_activation = true
tu.createDeviceNode ("nondefault-device-node", "Audio/Sink")
tu.createDeviceNode ("default-device-node", "Audio/Sink")
tu.createStreamNode ("stream-node")
SimpleEventHook {
name = "linking/test-linking",
after = "linking/link-target",
interests = {
EventInterest {
Constraint { "event.type", "=", "select-target" },
},
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
pu:unwrap_find_target_event (event)
if not target then
return
end
Log.info (si, string.format ("handling item: %s (%s) si id(%s)",
tostring (si_props ["node.name"]),
tostring (si_props ["node.id"]), si.id))
local link = pu.lookupLink (si.id, si_flags.peer_id)
assert (link ~= nil)
assert (si_props ["node.name"] == "stream-node")
assert (target.properties ["node.name"] == "default-device-node")
assert ((link:get_active_features () & Feature.SessionItem.ACTIVE) ~= 0)
assert (target == pu.findDefaultLinkable (si))
Script:finish_activation ()
end
}:register ()

View file

@ -0,0 +1,44 @@
-- Tests linking of streams and default devices. Two device nodes are setup,
-- among which only one is selected as default device node.
local pu = require ("policy-utils")
local tu = require ("test-utils")
Script.async_activation = true
tu.createDeviceNode ("nondefault-device-node", "Audio/Source")
tu.createDeviceNode ("default-device-node", "Audio/Source")
tu.createStreamNode ("stream-node", "Stream/Input/Audio")
SimpleEventHook {
name = "linking/test-linking",
after = "linking/link-target",
interests = {
EventInterest {
Constraint { "event.type", "=", "select-target" },
},
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
pu:unwrap_find_target_event (event)
if not target then
return
end
Log.info (si, string.format ("handling item: %s (%s) si id(%s)",
tostring (si_props ["node.name"]),
tostring (si_props ["node.id"]), si.id))
local link = pu.lookupLink (si.id, si_flags.peer_id)
assert (link ~= nil)
assert (si_props ["node.name"] == "stream-node")
assert (target.properties ["node.name"] == "default-device-node")
assert ((link:get_active_features () & Feature.SessionItem.ACTIVE) ~= 0)
assert (target == pu.findDefaultLinkable (si))
Script:finish_activation ()
end
}:register ()