96 lines
4.0 KiB
PowerShell
96 lines
4.0 KiB
PowerShell
|
|
param(
|
||
|
|
[string]$ToolchainRoot = 'C:\Users\Administrator\Desktop\扫描仪\FreeScanViewer\native\toolchain',
|
||
|
|
[string]$SdkInclude = 'C:\Program Files\Shining3d\FreeTrak_TRAK\sdk\include',
|
||
|
|
[switch]$IncludeHttp,
|
||
|
|
[string]$NodePath
|
||
|
|
)
|
||
|
|
|
||
|
|
# The default run is offline. worker_test explicitly selects simulation and
|
||
|
|
# asserts that neither SDKCWrapper.dll nor FreeScanNativeBridge.dll is loaded.
|
||
|
|
# -IncludeHttp also runs the isolated 127.0.0.1:18889 mock HTTP suite. It needs
|
||
|
|
# the already-built production executable but never starts the real SDK.
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
$taskProject = $PSScriptRoot
|
||
|
|
$taskWorkspace = Split-Path -Parent $taskProject
|
||
|
|
$taskTestBin = Join-Path $taskProject 'tests\bin'
|
||
|
|
$taskBuildScript = Join-Path $taskProject 'build.ps1'
|
||
|
|
$taskTests = @(
|
||
|
|
@{
|
||
|
|
Name = 'contracts_test'
|
||
|
|
Sources = @('src/contracts.cpp', 'tests/contracts_test.cpp')
|
||
|
|
},
|
||
|
|
@{
|
||
|
|
Name = 'worker_test'
|
||
|
|
Sources = @('src/common.cpp', 'src/contracts.cpp', 'src/sdk_worker.cpp', 'src/calibration_window_capture.cpp', 'tests/worker_test.cpp')
|
||
|
|
},
|
||
|
|
@{
|
||
|
|
Name = 'preview_capture_test'
|
||
|
|
Sources = @('src/common.cpp', 'tests/preview_capture_test.cpp')
|
||
|
|
},
|
||
|
|
@{
|
||
|
|
Name = 'battery_test'
|
||
|
|
Sources = @('src/common.cpp', 'tests/battery_test.cpp')
|
||
|
|
},
|
||
|
|
@{
|
||
|
|
Name = 'calibration_files_test'
|
||
|
|
Sources = @('src/common.cpp', 'tests/calibration_files_test.cpp')
|
||
|
|
},
|
||
|
|
@{
|
||
|
|
Name = 'calibration_recovery_test'
|
||
|
|
Sources = @('src/common.cpp', 'tests/calibration_recovery_test.cpp')
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
# Give each test its own object directory, so these builds cannot replace the
|
||
|
|
# backend's objects while a separate production build is in progress.
|
||
|
|
foreach ($taskTest in $taskTests) {
|
||
|
|
& $taskBuildScript -ToolchainRoot $ToolchainRoot -SdkInclude $SdkInclude -OutputName ($taskTest.Name + '.exe') `
|
||
|
|
-SourceFiles $taskTest.Sources -OutputDirectory $taskTestBin `
|
||
|
|
-BuildDirectory (Join-Path $taskProject ('build\tests\' + $taskTest.Name))
|
||
|
|
}
|
||
|
|
|
||
|
|
$taskPreviousPath = $env:PATH
|
||
|
|
$taskPreviousTestExecutable = $env:FREESCAN_TEST_EXECUTABLE
|
||
|
|
$taskCrt = Join-Path $ToolchainRoot 'msvc\VC\Redist\MSVC\14.44.35112\x64\Microsoft.VC143.CRT'
|
||
|
|
if (-not (Test-Path -LiteralPath (Join-Path $taskCrt 'msvcp140.dll'))) {
|
||
|
|
# Release packages carry the same native runtime DLLs beside the backend.
|
||
|
|
$taskCrt = Join-Path $taskWorkspace 'FreeScanViewer'
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
$env:PATH = $taskCrt + ';' + $env:PATH
|
||
|
|
foreach ($taskTest in $taskTests) {
|
||
|
|
& (Join-Path $taskTestBin ($taskTest.Name + '.exe'))
|
||
|
|
if ($LASTEXITCODE -ne 0) {
|
||
|
|
throw ('Offline test failed: ' + $taskTest.Name + ' (exit ' + $LASTEXITCODE + ')')
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($IncludeHttp) {
|
||
|
|
$taskBackend = Join-Path $taskProject 'build\bin\FreeScanCpp.exe'
|
||
|
|
if (-not (Test-Path -LiteralPath $taskBackend)) {
|
||
|
|
throw 'Build FreeScanCpp.exe with build.ps1 before running -IncludeHttp.'
|
||
|
|
}
|
||
|
|
if (-not $NodePath) {
|
||
|
|
$taskNodeCommand = Get-Command node.exe -ErrorAction SilentlyContinue
|
||
|
|
if ($taskNodeCommand) {
|
||
|
|
$NodePath = $taskNodeCommand.Source
|
||
|
|
} else {
|
||
|
|
$NodePath = Join-Path $env:LOCALAPPDATA '..\..\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe'
|
||
|
|
$NodePath = [IO.Path]::GetFullPath($NodePath)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (-not (Test-Path -LiteralPath $NodePath)) {
|
||
|
|
throw 'Node.js was not found. Supply -NodePath with the full path to node.exe.'
|
||
|
|
}
|
||
|
|
$env:FREESCAN_TEST_EXECUTABLE = $taskBackend
|
||
|
|
& $NodePath --test (Join-Path $taskProject 'tests\native-api.test.mjs')
|
||
|
|
if ($LASTEXITCODE -ne 0) {
|
||
|
|
throw ('Mock HTTP suite failed (exit ' + $LASTEXITCODE + ')')
|
||
|
|
}
|
||
|
|
}
|
||
|
|
Write-Output ('Native verification passed. HTTP mock included: ' + [bool]$IncludeHttp)
|
||
|
|
} finally {
|
||
|
|
$env:PATH = $taskPreviousPath
|
||
|
|
$env:FREESCAN_TEST_EXECUTABLE = $taskPreviousTestExecutable
|
||
|
|
}
|