You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
3.1 KiB

$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName PresentationFramework
[void][Reflection.Assembly]::LoadFrom((Join-Path $PSScriptRoot 'DCT_test/bin/Release/DCT_test.exe'))
function Assert-True($value, $message) { if (!$value) { throw $message } }
$packet = [DCT_test.DctPacket]::Create(0xA3, [byte[]](1, 161, 0x12, 0x34), 0)
$bytes = $packet.Encode()
$buffer = New-Object 'System.Collections.Generic.List[byte]'
$buffer.AddRange([byte[]]$bytes[0..3])
Assert-True (([DCT_test.DctPacket]::ParseStream($buffer)).Count -eq 0) 'Partial frame accepted'
$buffer.AddRange([byte[]]$bytes[4..($bytes.Length-1)])
$parsed = [DCT_test.DctPacket]::ParseStream($buffer)
Assert-True ($parsed.Count -eq 1 -and $buffer.Count -eq 0) 'Split frame failed'
Assert-True (($parsed[0].Encode() -join ',') -eq ($bytes -join ',')) 'Roundtrip changed bytes'
$bad = [byte[]]$bytes.Clone()
$bad[$bad.Length-2] = $bad[$bad.Length-2] -bxor 1
$buffer.AddRange($bad)
$buffer.AddRange($bytes)
Assert-True (([DCT_test.DctPacket]::ParseStream($buffer)).Count -eq 1) 'Corrupt frame recovery failed'
$reader = New-Object DCT_test.LogFileReader
$logDirectory = Join-Path $PSScriptRoot '../refer/mdb_dbc_log'
Get-ChildItem $logDirectory -Filter '*log.txt' | ForEach-Object {
$result = $reader.Load($_.FullName)
Assert-True $result.Success ($_.Name + ': ' + $result.ErrorMessage)
Write-Output ($_.Name + ': ' + $result.TotalRecords + ' packets OK')
}
Write-Output 'PASS: split frames, checksum recovery, byte roundtrip, real log loading'
# Exercise the actual WPF START handler without opening a window or a server.
# An empty source must stay stopped and must not generate substitute telemetry.
$previousContext = [Threading.SynchronizationContext]::Current
[Threading.SynchronizationContext]::SetSynchronizationContext(
(New-Object Windows.Threading.DispatcherSynchronizationContext))
$window = $null
try {
$window = New-Object DCT_test.MainWindow
$flags = [Reflection.BindingFlags]'Instance,NonPublic'
$windowType = $window.GetType()
[void]$windowType.GetMethod('BtnClearFile_Click', $flags).Invoke($window, [object[]]@($null, $null))
[void]$windowType.GetMethod('StartTelemetryStreaming', $flags).Invoke($window, $null)
Assert-True (-not $windowType.GetField('_isPlaying', $flags).GetValue($window)) 'Empty source started playback'
Assert-True ($windowType.GetField('_loadedLogRecords', $flags).GetValue($window).Count -eq 0) 'Empty source generated packets'
foreach ($removedName in @('RadioModeSim', 'RadioModeFile', 'ComboProfile', 'ComboRate', 'GridTxSignals', 'BtnPlay', 'BtnPause', 'BtnStop')) {
Assert-True ($null -eq $window.FindName($removedName)) ('Removed control still present: ' + $removedName)
}
foreach ($retainedName in @('ComboSpeed', 'CheckLoop', 'GridClients', 'TextLogConsole')) {
Assert-True ($null -ne $window.FindName($retainedName)) ('Missing playback control: ' + $retainedName)
}
Write-Output 'PASS: log-only WPF controls, empty-source START stays stopped, client list and packet console retained'
}
finally {
if ($null -ne $window) { $window.Close() }
[Threading.SynchronizationContext]::SetSynchronizationContext($previousContext)
}