IODevice.driver

initial pester tests pass for all kinds
This commit is contained in:
pblivingston 2026-02-28 20:35:12 -05:00
parent abd792acd5
commit 2f2d4af848
5 changed files with 69 additions and 33 deletions

View File

@ -20,11 +20,15 @@ class Remote {
[String]$vmpath [String]$vmpath
[Hashtable]$kind [Hashtable]$kind
[Object]$profiles [Object]$profiles
[String]$userpath
[String]$workingconfig
Remote ([String]$kindId) { Remote ([String]$kindId) {
$this.vmpath = Setup_DLL $this.vmpath = Setup_DLL
$this.kind = GetKind($kindId) $this.kind = GetKind($kindId)
$this.profiles = Get_Profiles($this.kind.name) $this.profiles = Get_Profiles($this.kind.name)
$this.userpath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'Voicemeeter'
$this.workingconfig = Join-Path $this.userpath ('vm' + $this.kind.name + '_working.xml')
} }
[string] ToString() { [string] ToString() {

View File

@ -97,7 +97,7 @@ class VirtualBus : Bus {
} }
class BusDevice : IODevice { class BusDevice : IODevice {
BusDevice ([int]$index, [Object]$remote) : base ($index, $remote) { BusDevice ([int]$index, [Object]$remote) : base ($index, $remote, 'Output') {
if ($this.index -eq 0) { if ($this.index -eq 0) {
AddStringMembers -PARAMS @('asio') -WriteOnly AddStringMembers -PARAMS @('asio') -WriteOnly
} }

View File

@ -100,9 +100,57 @@ class EqCell : IRemote {
} }
class IODevice : IRemote { class IODevice : IRemote {
IODevice ([int]$index, [Object]$remote) : base ($index, $remote) { [string]$kindOfDevice
IODevice ([int]$index, [Object]$remote, [string]$kindOfDevice) : base ($index, $remote) {
$this.kindOfDevice = $kindOfDevice
AddStringMembers -WriteOnly -PARAMS @('wdm', 'ks', 'mme') AddStringMembers -WriteOnly -PARAMS @('wdm', 'ks', 'mme')
AddStringMembers -ReadOnly -PARAMS @('name') AddStringMembers -ReadOnly -PARAMS @('name')
AddIntMembers -ReadOnly -PARAMS @('sr') AddIntMembers -ReadOnly -PARAMS @('sr')
} }
hidden $_driver = $($this | Add-Member ScriptProperty 'driver' `
{
$path = $this.remote.workingconfig
$oldTime = if (Test-Path $path) { (Get-Item $path).LastWriteTime } else { [DateTime]::MinValue }
$this.remote.Setter('Command.Save', $path)
$timeout = New-TimeSpan -Seconds 2
$sw = [Diagnostics.Stopwatch]::StartNew()
$line = $null
do {
if (Test-Path $path) {
$newTime = (Get-Item $path).LastWriteTime
if ($newTime -gt $oldTime) {
try {
$line = Get-Content $path | Select-String -Pattern "<$($this.kindOfDevice)Dev index='$($this.index + 1)'"
if ($line) { break }
}
catch {}
}
}
Start-Sleep -Milliseconds 20
} while ($sw.elapsed -lt $timeout)
if (-not $line) { return 'unknown' }
$type = $null
if ($line.ToString() -match "type='(?<type>\d+)'") {
$type = $matches['type']
}
switch ($type) {
'1' { return 'mme' }
'4' { return 'wdm' }
'8' { return 'ks' }
'256' { return 'asio' }
default { return 'none' }
}
} `
{
Write-Warning ("ERROR: $($this.identifier()).driver is read only")
}
)
} }

View File

@ -155,7 +155,7 @@ class StripEq : IOEq {
} }
class StripDevice : IODevice { class StripDevice : IODevice {
StripDevice ([int]$index, [Object]$remote) : base ($index, $remote) { StripDevice ([int]$index, [Object]$remote) : base ($index, $remote, 'Input') {
} }
[string] identifier () { [string] identifier () {

View File

@ -983,24 +983,16 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' {
@{ Index = $phys_out } @{ Index = $phys_out }
) { ) {
Context 'Device' -ForEach @( Context 'Device' -ForEach @(
@{ Value = 'testOutput' }, @{ Value = '' } @{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' }
@{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' }
@{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' }
@{ Driver = 'mme'; Value = ''; Expected = 'none' }
) { ) {
It "Should set Bus[$index].Device.wdm" { It "Should set Bus[$index].Device.$($driver)" {
$vmr.bus[$index].device.wdm = $value $vmr.bus[$index].device.$($driver) = $value
Start-Sleep -Milliseconds 800
$vmr.bus[$index].device.name | Should -Be $value
}
It "Should set Bus[$index].Device.ks" {
$vmr.bus[$index].device.ks = $value
Start-Sleep -Milliseconds 800
$vmr.bus[$index].device.name | Should -Be $value
}
It "Should set Bus[$index].Device.mme" {
$vmr.bus[$index].device.mme = $value
Start-Sleep -Milliseconds 800 Start-Sleep -Milliseconds 800
$vmr.bus[$index].device.name | Should -Be $value $vmr.bus[$index].device.name | Should -Be $value
$vmr.bus[$index].device.driver | Should -Be $expected
} }
} }
} }
@ -1009,24 +1001,16 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' {
@{ Index = $virt_out } @{ Index = $virt_out }
) { ) {
Context 'Device' -Skip:$ifNotBasic -ForEach @( Context 'Device' -Skip:$ifNotBasic -ForEach @(
@{ Value = 'testOutput' }, @{ Value = '' } @{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' }
@{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' }
@{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' }
@{ Driver = 'mme'; Value = ''; Expected = 'none' }
) { ) {
It "Should set Bus[$index].Device.wdm" { It "Should set Bus[$index].Device.$($driver)" {
$vmr.bus[$index].device.wdm = $value $vmr.bus[$index].device.$($driver) = $value
Start-Sleep -Milliseconds 800
$vmr.bus[$index].device.name | Should -Be $value
}
It "Should set Bus[$index].Device.ks" {
$vmr.bus[$index].device.ks = $value
Start-Sleep -Milliseconds 800
$vmr.bus[$index].device.name | Should -Be $value
}
It "Should set Bus[$index].Device.mme" {
$vmr.bus[$index].device.mme = $value
Start-Sleep -Milliseconds 800 Start-Sleep -Milliseconds 800
$vmr.bus[$index].device.name | Should -Be $value $vmr.bus[$index].device.name | Should -Be $value
$vmr.bus[$index].device.driver | Should -Be $expected
} }
} }
} }