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.
38 lines
2.4 KiB
38 lines
2.4 KiB
$ErrorActionPreference = 'Stop'
|
|
[void][Reflection.Assembly]::LoadFrom((Join-Path $PSScriptRoot 'DCT_test/bin/Release/DCT_test.exe'))
|
|
function Assert-True($value, $message) { if (!$value) { throw $message } }
|
|
$taskDirectory = Join-Path ([IO.Path]::GetTempPath()) ('dct-log-precision-' + [Guid]::NewGuid().ToString('N'))
|
|
[void][IO.Directory]::CreateDirectory($taskDirectory)
|
|
try {
|
|
$reader = New-Object DCT_test.LogFileReader
|
|
$timestamps = @('23:59:59.999', '23:59:59.999', '23:59:59.999123', '00:00:00.000007')
|
|
$lines = for ($index = 0; $index -lt $timestamps.Count; $index++) {
|
|
$packet = [DCT_test.DctPacket]::Create(0xA3, [byte[]]@($index + 1), 0)
|
|
$hex = ($packet.Encode() | ForEach-Object { $_.ToString('X2') }) -join ' '
|
|
'[Recv][' + $timestamps[$index] + '] ' + $hex
|
|
}
|
|
$file = Join-Path $taskDirectory 'precision.txt'
|
|
[IO.File]::WriteAllLines($file, [string[]]$lines)
|
|
$result = $reader.Load($file)
|
|
Assert-True $result.Success $result.ErrorMessage
|
|
Assert-True ($result.TotalRecords -eq 4) 'Equal millisecond packets were lost'
|
|
$expectedMilliseconds = @(0.0, 0.0, 0.123, 1.007)
|
|
for ($index = 0; $index -lt 4; $index++) {
|
|
Assert-True ($result.Packets[$index].Payload[0] -eq $index + 1) 'Packet order changed'
|
|
Assert-True ([Math]::Abs($result.Packets[$index].LogElapsedMilliseconds - $expectedMilliseconds[$index]) -lt 0.00001) 'Fraction or midnight rollover lost'
|
|
}
|
|
[IO.File]::WriteAllLines($file, [string[]]@($lines[0], $lines[2].Replace('.999123]', '.99912]')))
|
|
$invalid = $reader.Load($file)
|
|
Assert-True (-not $invalid.Success -and $invalid.TotalRecords -eq 0) 'Invalid precision accepted or partial packets retained'
|
|
Write-Output 'PASS: 3/6-digit and mixed timestamps, equal-ms packet order, microsecond gaps, midnight rollover, invalid precision rejection'
|
|
}
|
|
finally {
|
|
# Only the unique temporary fixture owned by this check is removed.
|
|
$resolvedTaskDirectory = [IO.Path]::GetFullPath($taskDirectory)
|
|
$resolvedTemporaryRoot = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('\') + '\'
|
|
if (-not $resolvedTaskDirectory.StartsWith($resolvedTemporaryRoot, [StringComparison]::OrdinalIgnoreCase) -or
|
|
[IO.Path]::GetFileName($resolvedTaskDirectory) -notmatch '^dct-log-precision-[a-f0-9]{32}$') {
|
|
throw 'Refusing to remove a fixture outside the expected temporary directory'
|
|
}
|
|
Remove-Item -LiteralPath $resolvedTaskDirectory -Recurse -Force
|
|
}
|
|
|