137 lines
4.5 KiB
Plaintext
137 lines
4.5 KiB
Plaintext
Option Explicit
|
|
|
|
Const ForReading = 1
|
|
Const TristateFalse = 0
|
|
|
|
Dim Fso
|
|
Dim RepoRoot
|
|
Dim HelperPath
|
|
Dim HelperSource
|
|
Dim TestRoot
|
|
Dim DataPath
|
|
Dim UnicodeText
|
|
Dim EscapedText
|
|
Dim ResolvedPath
|
|
Dim Shell
|
|
Dim JunctionPath
|
|
Dim JunctionTarget
|
|
Dim JunctionCommand
|
|
Dim JunctionExitCode
|
|
Dim JunctionRejected
|
|
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
RepoRoot = Fso.GetParentFolderName(Fso.GetParentFolderName( _
|
|
Fso.GetParentFolderName(WScript.ScriptFullName)))
|
|
HelperPath = Fso.BuildPath(RepoRoot, _
|
|
"integration\dxdesigner795\BridgeCommon.vbs")
|
|
|
|
If Not Fso.FileExists(HelperPath) Then
|
|
Fail "missing helper: " & HelperPath
|
|
End If
|
|
|
|
HelperSource = Fso.OpenTextFile(HelperPath, ForReading, False, _
|
|
TristateFalse).ReadAll
|
|
ExecuteGlobal HelperSource
|
|
|
|
TestRoot = Fso.BuildPath(Fso.GetSpecialFolder(2), Fso.GetTempName)
|
|
Fso.CreateFolder TestRoot
|
|
DataPath = Fso.BuildPath(TestRoot, "roundtrip.json")
|
|
|
|
UnicodeText = "prefix-" & ChrW(&H6D4B) & ChrW(&H8BD5) & _
|
|
ChrW(&H8DEF) & ChrW(&H5F84) & "-suffix"
|
|
DxWriteUtf8Atomic DataPath, "old"
|
|
DxWriteUtf8Atomic DataPath, UnicodeText
|
|
AssertEqual UnicodeText, DxReadUtf8(DataPath), _
|
|
"UTF-8 text must survive an atomic overwrite"
|
|
AssertEqual 1, Fso.GetFolder(TestRoot).Files.Count, _
|
|
"atomic write must not leave a sibling temporary file"
|
|
UnicodeText = ChrW(&H6D4B) & ChrW(&H8BD5) & _
|
|
ChrW(-10179) & ChrW(-8576)
|
|
AssertEqual UnicodeText, DxJsonEscape(UnicodeText), _
|
|
"JSON escaping must preserve complete UTF-16 units"
|
|
|
|
EscapedText = DxJsonEscape(Chr(34) & "\" & Chr(8) & Chr(9) & _
|
|
Chr(10) & Chr(12) & Chr(13) & Chr(1))
|
|
AssertEqual "\" & Chr(34) & "\\" & "\b\t\n\f\r\u0001", _
|
|
EscapedText, "JSON escaping must cover quotes, slashes, and controls"
|
|
|
|
AssertEqual "1234.5", DxInvariantNumber(1234.5), _
|
|
"positive decimal formatting must use a period"
|
|
AssertEqual "-0.25", DxInvariantNumber(-0.25), _
|
|
"negative decimal formatting must use a period"
|
|
AssertEqual "0", DxInvariantNumber(0), _
|
|
"integer formatting must not add a decimal separator"
|
|
|
|
ResolvedPath = DxResolveRunPath(TestRoot, "nested\run.json")
|
|
AssertEqual Fso.GetAbsolutePathName(Fso.BuildPath(TestRoot, _
|
|
"nested\run.json")), ResolvedPath, _
|
|
"run-relative paths must resolve beneath the supplied root"
|
|
AssertResolveFails TestRoot, "..\escape.json", _
|
|
"parent traversal must be rejected"
|
|
AssertResolveFails TestRoot, Fso.GetAbsolutePathName(DataPath), _
|
|
"absolute paths must be rejected"
|
|
AssertResolveFails TestRoot, "C:\escape.json", _
|
|
"drive-qualified paths must be rejected"
|
|
AssertResolveFails TestRoot, "\\server\share\escape.json", _
|
|
"UNC paths must be rejected"
|
|
AssertResolveFails TestRoot, "", _
|
|
"empty run-relative paths must be rejected"
|
|
|
|
JunctionTarget = TestRoot & "-outside"
|
|
JunctionPath = Fso.BuildPath(TestRoot, "junction")
|
|
Fso.CreateFolder JunctionTarget
|
|
Set Shell = CreateObject("WScript.Shell")
|
|
JunctionCommand = DxCommandQuote( _
|
|
Shell.ExpandEnvironmentStrings("%ComSpec%")) & _
|
|
" /d /s /c " & Chr(34) & "mklink /J " & _
|
|
DxCommandQuote(JunctionPath) & " " & DxCommandQuote(JunctionTarget) & _
|
|
" >nul" & Chr(34)
|
|
JunctionExitCode = Shell.Run(JunctionCommand, 0, True)
|
|
If JunctionExitCode <> 0 Then
|
|
Fso.DeleteFolder JunctionTarget, True
|
|
Fail "junction setup failed"
|
|
End If
|
|
JunctionRejected = ResolveFails(TestRoot, "junction\escape.json")
|
|
JunctionCommand = DxCommandQuote( _
|
|
Shell.ExpandEnvironmentStrings("%ComSpec%")) & _
|
|
" /d /s /c " & Chr(34) & "rmdir " & _
|
|
DxCommandQuote(JunctionPath) & Chr(34)
|
|
JunctionExitCode = Shell.Run(JunctionCommand, 0, True)
|
|
If JunctionExitCode <> 0 Then Fail "junction cleanup failed"
|
|
Fso.DeleteFolder JunctionTarget, True
|
|
If Not JunctionRejected Then
|
|
Fail "junction path components must be rejected"
|
|
End If
|
|
|
|
Fso.DeleteFolder TestRoot, True
|
|
WScript.Echo "PASS: BridgeCommon cscript behavior"
|
|
|
|
Sub AssertEqual(ByVal Expected, ByVal Actual, ByVal Message)
|
|
If CStr(Expected) <> CStr(Actual) Then
|
|
Fail Message & ": expected [" & CStr(Expected) & _
|
|
"], got [" & CStr(Actual) & "]"
|
|
End If
|
|
End Sub
|
|
|
|
Sub AssertResolveFails(ByVal RootPath, ByVal RelativePath, ByVal Message)
|
|
If Not ResolveFails(RootPath, RelativePath) Then
|
|
Fail Message
|
|
End If
|
|
End Sub
|
|
|
|
Function ResolveFails(ByVal RootPath, ByVal RelativePath)
|
|
Dim Ignored
|
|
Dim ErrorNumber
|
|
On Error Resume Next
|
|
Ignored = DxResolveRunPath(RootPath, RelativePath)
|
|
ErrorNumber = Err.Number
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
ResolveFails = (ErrorNumber <> 0)
|
|
End Function
|
|
|
|
Sub Fail(ByVal Message)
|
|
WScript.Echo "FAIL: " & Message
|
|
WScript.Quit 1
|
|
End Sub
|