feat: add complete yiyezhqiu productivity suite
This commit is contained in:
commit
e422ca8b2a
155 files changed
+18959
No files matched your search
@@ -0,0 +1,75 @@
|
||||
Option Explicit
|
||||
|
||||
Dim Fso
|
||||
Dim ScriptRoot
|
||||
Dim CommonPath
|
||||
Dim CommonText
|
||||
Dim Stream
|
||||
Dim TempRoot
|
||||
Dim Utf8Path
|
||||
Dim Actual
|
||||
Dim Sequence
|
||||
Dim BridgeId
|
||||
Dim Op
|
||||
Dim PropertyName
|
||||
Dim ExpectedRefdes
|
||||
Dim NewRefdes
|
||||
Dim FinalRefdes
|
||||
|
||||
Set Fso = CreateObject("Scripting.FileSystemObject")
|
||||
ScriptRoot = Fso.GetParentFolderName(WScript.ScriptFullName)
|
||||
CommonPath = Fso.GetAbsolutePathName( _
|
||||
Fso.BuildPath(ScriptRoot, "..\..\integration\dxdesigner795\BridgeCommon.vbs"))
|
||||
|
||||
Set Stream = Fso.OpenTextFile(CommonPath, 1, False, 0)
|
||||
CommonText = Stream.ReadAll
|
||||
Stream.Close
|
||||
ExecuteGlobal CommonText
|
||||
|
||||
Call AssertEqual(DxToolsQuote("C:\Tools Path\DxDesignerTools.exe"), _
|
||||
Chr(34) & "C:\Tools Path\DxDesignerTools.exe" & Chr(34), "quote")
|
||||
Call AssertEqual(DxToolsJson(Chr(34) & Chr(92) & vbCrLf & vbTab), _
|
||||
Chr(92) & Chr(34) & Chr(92) & Chr(92) & Chr(92) & "r" & _
|
||||
Chr(92) & "n" & Chr(92) & "t", "json")
|
||||
|
||||
TempRoot = Fso.BuildPath(Fso.GetSpecialFolder(2), _
|
||||
"dx-tools-vbs-" & Replace(CStr(Timer), ".", "-"))
|
||||
Fso.CreateFolder TempRoot
|
||||
Utf8Path = Fso.BuildPath(TempRoot, "round-trip.txt")
|
||||
Call DxToolsWriteUtf8Atomic(Utf8Path, ChrW(&H81EA) & ChrW(&H5B9A) & _
|
||||
ChrW(&H4F4D) & ChrW(&H53F7))
|
||||
Actual = DxToolsReadUtf8(Utf8Path)
|
||||
Call AssertEqual(Actual, ChrW(&H81EA) & ChrW(&H5B9A) & ChrW(&H4F4D) & _
|
||||
ChrW(&H53F7), "utf8")
|
||||
|
||||
If Not DxToolsParseScheduleRow("1" & vbTab & "refdes" & vbTab & _
|
||||
"c000001" & vbTab & "" & vbTab & "R?" & vbTab & "R1" & vbTab & _
|
||||
"R1", Sequence, Op, BridgeId, PropertyName, _
|
||||
ExpectedRefdes, NewRefdes, FinalRefdes) Then
|
||||
Call Fail("valid schedule row")
|
||||
End If
|
||||
Call AssertEqual(Sequence, 1, "sequence")
|
||||
Call AssertEqual(Op, "refdes", "schedule op")
|
||||
Call AssertEqual(BridgeId, "c000001", "bridge id")
|
||||
Call AssertEqual(ExpectedRefdes, "R?", "expected value")
|
||||
|
||||
If DxToolsParseScheduleRow("1" & vbTab & "c000001" & vbTab & "R?", _
|
||||
Sequence, Op, BridgeId, PropertyName, _
|
||||
ExpectedRefdes, NewRefdes, FinalRefdes) Then
|
||||
Call Fail("malformed schedule row")
|
||||
End If
|
||||
|
||||
Fso.DeleteFolder TempRoot, True
|
||||
WScript.Echo "BridgeCommon assertions passed"
|
||||
|
||||
Sub AssertEqual(actualValue, expectedValue, label)
|
||||
If CStr(actualValue) <> CStr(expectedValue) Then
|
||||
Call Fail(label & ": expected [" & CStr(expectedValue) & _
|
||||
"] got [" & CStr(actualValue) & "]")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Fail(message)
|
||||
WScript.Echo "FAIL: " & message
|
||||
WScript.Quit 1
|
||||
End Sub
|
||||
@@ -0,0 +1,163 @@
|
||||
Option Explicit
|
||||
|
||||
Const cmdControlPopup = 10
|
||||
|
||||
Dim Fso
|
||||
Dim SourceRoot
|
||||
Dim TempRoot
|
||||
Dim SourceMenu
|
||||
Dim TargetMenu
|
||||
Dim MenuText
|
||||
Dim Stream
|
||||
Dim Scripting
|
||||
Dim FakeMenuBar
|
||||
Dim DxToolsCommonLoads
|
||||
Dim DxToolsProbeRuns
|
||||
Dim RuntimeRoot
|
||||
Dim RuntimeVbsRoot
|
||||
|
||||
Class FakeScriptingHost
|
||||
Public CurrentScriptFullName
|
||||
Public ScriptFullName
|
||||
End Class
|
||||
|
||||
Class FakeControl
|
||||
Public Caption
|
||||
Public OnAction
|
||||
Public Controls
|
||||
Private ParentControls
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
Set Controls = New FakeControlsCollection
|
||||
End Sub
|
||||
|
||||
Public Property Set Parent(value)
|
||||
Set ParentControls = value
|
||||
End Property
|
||||
|
||||
Public Sub Delete()
|
||||
ParentControls.Remove Me
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Class FakeControlsCollection
|
||||
Private Items
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
Set Items = CreateObject("Scripting.Dictionary")
|
||||
End Sub
|
||||
|
||||
Public Property Get Count()
|
||||
Count = Items.Count
|
||||
End Property
|
||||
|
||||
Public Function Add()
|
||||
Dim control
|
||||
Set control = New FakeControl
|
||||
Set control.Parent = Me
|
||||
Items.Add CStr(Items.Count + 1), control
|
||||
Set Add = control
|
||||
End Function
|
||||
|
||||
Public Property Get Item(index)
|
||||
Set Item = Items(CStr(index))
|
||||
End Property
|
||||
|
||||
Public Sub Remove(target)
|
||||
Dim index
|
||||
Dim found
|
||||
Dim count
|
||||
count = Items.Count
|
||||
found = 0
|
||||
For index = 1 To count
|
||||
If Items(CStr(index)) Is target Then found = index
|
||||
Next
|
||||
If found = 0 Then Exit Sub
|
||||
For index = found To count - 1
|
||||
Set Items(CStr(index)) = Items(CStr(index + 1))
|
||||
Next
|
||||
Items.Remove CStr(count)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Function CommandBars(name)
|
||||
If name <> "Sheet Menu Bar" Then Call Fail("unexpected menu bar")
|
||||
Set CommandBars = FakeMenuBar
|
||||
End Function
|
||||
|
||||
Set Fso = CreateObject("Scripting.FileSystemObject")
|
||||
SourceRoot = Fso.GetAbsolutePathName(Fso.BuildPath( _
|
||||
Fso.GetParentFolderName(WScript.ScriptFullName), _
|
||||
"..\..\integration\dxdesigner795"))
|
||||
TempRoot = Fso.BuildPath(Fso.GetSpecialFolder(2), _
|
||||
"dx-tools-menu-" & Replace(CStr(Timer), ".", "-"))
|
||||
Fso.CreateFolder TempRoot
|
||||
SourceMenu = Fso.BuildPath(SourceRoot, "MenuAdd.vbs")
|
||||
TargetMenu = Fso.BuildPath(TempRoot, "MenuAdd.vbs")
|
||||
Fso.CopyFile SourceMenu, TargetMenu
|
||||
Call Fso.CreateTextFile(Fso.BuildPath(TempRoot, "DesignBridge.vbs"), True).Close
|
||||
Call Fso.CreateTextFile(Fso.BuildPath(TempRoot, "DxDesignerTools.exe"), True).Close
|
||||
RuntimeRoot = Fso.BuildPath(TempRoot, "_runtime")
|
||||
RuntimeVbsRoot = Fso.BuildPath(RuntimeRoot, "vbs")
|
||||
Fso.CreateFolder RuntimeRoot
|
||||
Fso.CreateFolder RuntimeVbsRoot
|
||||
Set Stream = Fso.CreateTextFile( _
|
||||
Fso.BuildPath(RuntimeVbsRoot, "BridgeCommon.vbs"), True)
|
||||
Stream.WriteLine "DxToolsCommonLoads = DxToolsCommonLoads + 1"
|
||||
Stream.Close
|
||||
Set Stream = Fso.CreateTextFile( _
|
||||
Fso.BuildPath(TempRoot, "CompatibilityProbe.vbs"), True)
|
||||
Stream.WriteLine "Sub DxToolsRunCompatibilityProbe()"
|
||||
Stream.WriteLine " DxToolsProbeRuns = DxToolsProbeRuns + 1"
|
||||
Stream.WriteLine "End Sub"
|
||||
Stream.Close
|
||||
|
||||
Set Scripting = New FakeScriptingHost
|
||||
Scripting.CurrentScriptFullName = TargetMenu
|
||||
Scripting.ScriptFullName = ""
|
||||
Set FakeMenuBar = New FakeControl
|
||||
|
||||
Set Stream = Fso.OpenTextFile(TargetMenu, 1, False, 0)
|
||||
MenuText = Stream.ReadAll
|
||||
Stream.Close
|
||||
MenuText = Replace(MenuText, ".Controls.Add(cmdControlPopup)", _
|
||||
".Controls.Add")
|
||||
ExecuteGlobal MenuText
|
||||
|
||||
Call AssertEqual(DxToolsHome, TempRoot, "portable root")
|
||||
Call AssertEqual(DxToolsScriptPathSource, _
|
||||
"Scripting.CurrentScriptFullName", "path source")
|
||||
Call AssertEqual(FakeMenuBar.Controls.Count, 1, "top menu count")
|
||||
Call AssertEqual(FakeMenuBar.Controls.Item(1).Controls.Count, 7, _
|
||||
"command count")
|
||||
Call AssertEqual(FakeMenuBar.Controls.Item(1).Controls.Item(1).OnAction, _
|
||||
"DxToolsOpenRefDes", "refdes action")
|
||||
Call AssertEqual(FakeMenuBar.Controls.Item(1).Controls.Item(2).OnAction, _
|
||||
"DxToolsOpenPropertyChange", "property change action")
|
||||
Call AssertEqual(FakeMenuBar.Controls.Item(1).Controls.Item(5).OnAction, _
|
||||
"DxToolsOpenBom", "bom action")
|
||||
|
||||
Call DxToolsInstallMenu()
|
||||
Call AssertEqual(FakeMenuBar.Controls.Count, 1, "idempotent menu count")
|
||||
|
||||
DxToolsCommonLoads = 0
|
||||
DxToolsProbeRuns = 0
|
||||
Call DxToolsOpenCompatibility()
|
||||
Call DxToolsOpenCompatibility()
|
||||
Call AssertEqual(DxToolsCommonLoads, 1, "common script load count")
|
||||
Call AssertEqual(DxToolsProbeRuns, 2, "probe execution count")
|
||||
|
||||
Fso.DeleteFolder TempRoot, True
|
||||
WScript.Echo "MenuAdd assertions passed"
|
||||
|
||||
Sub AssertEqual(actualValue, expectedValue, label)
|
||||
If CStr(actualValue) <> CStr(expectedValue) Then
|
||||
Call Fail(label & ": expected [" & CStr(expectedValue) & _
|
||||
"] got [" & CStr(actualValue) & "]")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Fail(message)
|
||||
WScript.Echo "FAIL: " & message
|
||||
WScript.Quit 1
|
||||
End Sub
|
||||
@@ -0,0 +1,256 @@
|
||||
Option Explicit
|
||||
|
||||
Dim Fso
|
||||
Dim ScriptRoot
|
||||
Dim IntegrationRoot
|
||||
Dim TempRoot
|
||||
Dim ObjectMap
|
||||
Dim OriginalsMap
|
||||
Dim Component
|
||||
Dim State
|
||||
Dim DxToolsHome
|
||||
|
||||
Class FakeAttribute
|
||||
Private CurrentValue
|
||||
Private CurrentVisible
|
||||
|
||||
Public Property Get Value()
|
||||
Value = CurrentValue
|
||||
End Property
|
||||
|
||||
Public Property Let Value(newValue)
|
||||
If CStr(newValue) = CStr(FailValue) Then
|
||||
Err.Raise vbObjectError + 901, "FakeAttribute", "injected failure"
|
||||
End If
|
||||
CurrentValue = CStr(newValue)
|
||||
End Property
|
||||
|
||||
Public Property Get Visible()
|
||||
Visible = CurrentVisible
|
||||
End Property
|
||||
|
||||
Public Property Let Visible(newValue)
|
||||
CurrentVisible = newValue
|
||||
End Property
|
||||
|
||||
Public Sub Initialize(value, visible)
|
||||
CurrentValue = CStr(value)
|
||||
CurrentVisible = visible
|
||||
FailValue = Chr(0)
|
||||
End Sub
|
||||
|
||||
Public FailValue
|
||||
End Class
|
||||
|
||||
Class FakeAttributes
|
||||
Private Items
|
||||
|
||||
Public Sub Initialize()
|
||||
Set Items = CreateObject("Scripting.Dictionary")
|
||||
End Sub
|
||||
|
||||
Public Sub AddAttribute(name, value, visible)
|
||||
Dim attribute
|
||||
Set attribute = New FakeAttribute
|
||||
Call attribute.Initialize(value, visible)
|
||||
If Items.Exists(LCase(CStr(name))) Then
|
||||
Items.Remove LCase(CStr(name))
|
||||
End If
|
||||
Items.Add LCase(CStr(name)), attribute
|
||||
End Sub
|
||||
|
||||
Public Property Get Item(name)
|
||||
If Not Items.Exists(LCase(CStr(name))) Then
|
||||
Err.Raise vbObjectError + 902, "FakeAttributes", _
|
||||
"attribute not found: " & CStr(name)
|
||||
End If
|
||||
Set Item = Items(LCase(CStr(name)))
|
||||
End Property
|
||||
End Class
|
||||
|
||||
Class FakeComponent
|
||||
Private CurrentRefdes
|
||||
Public FailTarget
|
||||
Public Attributes
|
||||
|
||||
Public Property Get Refdes()
|
||||
Refdes = CurrentRefdes
|
||||
End Property
|
||||
|
||||
Public Property Let Refdes(value)
|
||||
If CStr(value) = CStr(FailTarget) Then
|
||||
Err.Raise vbObjectError + 901, "FakeComponent", "injected failure"
|
||||
End If
|
||||
CurrentRefdes = CStr(value)
|
||||
End Property
|
||||
|
||||
Public Sub Initialize(value)
|
||||
CurrentRefdes = CStr(value)
|
||||
FailTarget = Chr(0)
|
||||
Set Attributes = New FakeAttributes
|
||||
Call Attributes.Initialize()
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Set Fso = CreateObject("Scripting.FileSystemObject")
|
||||
ScriptRoot = Fso.GetParentFolderName(WScript.ScriptFullName)
|
||||
IntegrationRoot = Fso.GetAbsolutePathName(Fso.BuildPath( _
|
||||
ScriptRoot, "..\..\integration\dxdesigner795"))
|
||||
Call LoadGlobal(Fso.BuildPath(IntegrationRoot, "BridgeCommon.vbs"))
|
||||
Call LoadGlobal(Fso.BuildPath(IntegrationRoot, "core\Transaction.vbs"))
|
||||
Call LoadGlobal(Fso.BuildPath(IntegrationRoot, "core\Mailbox.vbs"))
|
||||
|
||||
TempRoot = Fso.BuildPath(Fso.GetSpecialFolder(2), _
|
||||
"dx-tools-bridge-" & Replace(CStr(Timer), ".", "-"))
|
||||
Fso.CreateFolder TempRoot
|
||||
DxToolsHome = TempRoot & "\Tool Root"
|
||||
Call AssertEqual(DxBridgeUiCommand(TempRoot, "bom"), _
|
||||
DxToolsQuote(DxToolsHome & "\DxDesignerTools.exe") & _
|
||||
" ui --request " & DxToolsQuote(TempRoot & "\request.json") & _
|
||||
" --feature " & DxToolsQuote("bom"), "ui command with feature")
|
||||
Call AssertEqual(DxBridgeUiCommand(TempRoot, ""), _
|
||||
DxToolsQuote(DxToolsHome & "\DxDesignerTools.exe") & _
|
||||
" ui --request " & DxToolsQuote(TempRoot & "\request.json"), _
|
||||
"ui command without feature")
|
||||
|
||||
Set ObjectMap = CreateObject("Scripting.Dictionary")
|
||||
Set OriginalsMap = CreateObject("Scripting.Dictionary")
|
||||
Set Component = New FakeComponent
|
||||
Component.Initialize "R?"
|
||||
ObjectMap.Add "c000001", Component
|
||||
|
||||
Call WriteTransaction(TempRoot, "refdes", "", "R?", "R1")
|
||||
State = DxProcessApply(TempRoot, "run-vbs", "snapshot-vbs", _
|
||||
ObjectMap, OriginalsMap)
|
||||
Call AssertEqual(State, "applied", "successful state")
|
||||
Call AssertEqual(Component.Refdes, "R1", "successful refdes")
|
||||
Call AssertContains(DxToolsReadUtf8(Fso.BuildPath( _
|
||||
TempRoot, "apply-status.json")), """state"": ""applied""", _
|
||||
"successful status")
|
||||
|
||||
Component.Initialize "R?"
|
||||
Component.FailTarget = "R9"
|
||||
Call WriteTransaction(TempRoot, "refdes", "", "R?", "R9")
|
||||
State = DxProcessApply(TempRoot, "run-vbs", "snapshot-vbs", _
|
||||
ObjectMap, OriginalsMap)
|
||||
Call AssertEqual(State, "rolled-back", "rollback state")
|
||||
Call AssertEqual(Component.Refdes, "R?", "rollback refdes")
|
||||
|
||||
Component.Initialize "R8"
|
||||
Component.FailTarget = Chr(0)
|
||||
Call WriteTransaction(TempRoot, "refdes", "", "R?", "R2")
|
||||
State = DxProcessApply(TempRoot, "run-vbs", "snapshot-vbs", _
|
||||
ObjectMap, OriginalsMap)
|
||||
Call AssertEqual(State, "rejected", "stale state")
|
||||
Call AssertEqual(Component.Refdes, "R8", "stale refdes unchanged")
|
||||
|
||||
Component.Initialize "R8"
|
||||
Component.Attributes.AddAttribute "Value", "10K", "1"
|
||||
Call WriteTransaction(TempRoot, "property", "Value", "10K", "47K")
|
||||
State = DxProcessApply(TempRoot, "run-vbs", "snapshot-vbs", _
|
||||
ObjectMap, OriginalsMap)
|
||||
Call AssertEqual(State, "applied", "property state")
|
||||
Call AssertEqual(Component.Attributes.Item("Value").Value, "47K", _
|
||||
"property value written")
|
||||
|
||||
Component.Initialize "R8"
|
||||
Component.Attributes.AddAttribute "Part Name", "RES", "1"
|
||||
Call WriteTransaction(TempRoot, "visibility", "Part Name", "1", "0")
|
||||
State = DxProcessApply(TempRoot, "run-vbs", "snapshot-vbs", _
|
||||
ObjectMap, OriginalsMap)
|
||||
Call AssertEqual(State, "applied", "visibility state")
|
||||
Call AssertEqual(DxBridgeNormalizeVisible( _
|
||||
Component.Attributes.Item("Part Name").Visible), "0", _
|
||||
"visibility written")
|
||||
|
||||
Component.Initialize "R8"
|
||||
Component.Attributes.AddAttribute "Missing", "x", "1"
|
||||
Call WriteTransaction(TempRoot, "property", "Absent", "x", "y")
|
||||
State = DxProcessApply(TempRoot, "run-vbs", "snapshot-vbs", _
|
||||
ObjectMap, OriginalsMap)
|
||||
Call AssertEqual(State, "rejected", "missing attribute rejected")
|
||||
|
||||
Call TestClaimAndCleanup
|
||||
|
||||
Fso.DeleteFolder TempRoot, True
|
||||
WScript.Echo "DesignBridge transaction assertions passed"
|
||||
|
||||
Sub TestClaimAndCleanup
|
||||
Dim runsRoot
|
||||
Dim index
|
||||
Dim folderPath
|
||||
Dim sourcePath
|
||||
Dim claimPath
|
||||
runsRoot = Fso.BuildPath(TempRoot, "runs")
|
||||
Fso.CreateFolder runsRoot
|
||||
For index = 1 To 25
|
||||
folderPath = Fso.BuildPath(runsRoot, "run-" & _
|
||||
Right("00" & CStr(index), 3))
|
||||
Fso.CreateFolder folderPath
|
||||
Next
|
||||
Call DxBridgeCleanupRuns(runsRoot, "run-025")
|
||||
Call AssertEqual(Fso.GetFolder(runsRoot).SubFolders.Count, 20, _
|
||||
"run cleanup keeps 20")
|
||||
Call AssertEqual(Fso.FolderExists(Fso.BuildPath(runsRoot, "run-025")), _
|
||||
True, "run cleanup keeps current")
|
||||
|
||||
sourcePath = Fso.BuildPath(TempRoot, "claim-source.tsv")
|
||||
claimPath = Fso.BuildPath(TempRoot, "claim-target.tsv")
|
||||
Call Fso.CreateTextFile(sourcePath, True, False).Close
|
||||
Call AssertEqual(DxBridgeClaimFile(Fso, sourcePath, claimPath), _
|
||||
True, "claim moves source")
|
||||
Call AssertEqual(Fso.FileExists(sourcePath), False, "claim removes source")
|
||||
Call AssertEqual(Fso.FileExists(claimPath), True, "claim creates target")
|
||||
End Sub
|
||||
|
||||
Sub WriteTransaction(root, op, propertyName, expectedValue, newValue)
|
||||
Dim resultPath
|
||||
Dim backupPath
|
||||
Dim requestPath
|
||||
Dim resultStream
|
||||
Dim requestText
|
||||
resultPath = Fso.BuildPath(root, "result.tsv")
|
||||
backupPath = Fso.BuildPath(root, "backup.json")
|
||||
requestPath = Fso.BuildPath(root, "apply-request.json")
|
||||
Set resultStream = Fso.CreateTextFile(resultPath, True, False)
|
||||
resultStream.WriteLine "1" & vbTab & op & vbTab & "c000001" & vbTab & _
|
||||
propertyName & vbTab & expectedValue & vbTab & newValue & vbTab & _
|
||||
newValue
|
||||
resultStream.Close
|
||||
Call Fso.CreateTextFile(backupPath, True, False).Close
|
||||
requestText = "{" & vbCrLf & _
|
||||
" ""format_version"": 2," & vbCrLf & _
|
||||
" ""run_id"": ""run-vbs""," & vbCrLf & _
|
||||
" ""snapshot_id"": ""snapshot-vbs""," & vbCrLf & _
|
||||
" ""backup_path"": """ & DxToolsJson(backupPath) & """," & vbCrLf & _
|
||||
" ""schedule_sha256"": """ & DxToolsSha256File(resultPath) & _
|
||||
"""" & vbCrLf & "}" & vbCrLf
|
||||
Call DxToolsWriteUtf8Atomic(requestPath, requestText)
|
||||
End Sub
|
||||
|
||||
Sub LoadGlobal(path)
|
||||
Dim stream
|
||||
Dim text
|
||||
Set stream = Fso.OpenTextFile(path, 1, False, 0)
|
||||
text = stream.ReadAll
|
||||
stream.Close
|
||||
ExecuteGlobal text
|
||||
End Sub
|
||||
|
||||
Sub AssertEqual(actualValue, expectedValue, label)
|
||||
If CStr(actualValue) <> CStr(expectedValue) Then
|
||||
Call Fail(label & ": expected [" & CStr(expectedValue) & _
|
||||
"] got [" & CStr(actualValue) & "]")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub AssertContains(actualValue, expectedValue, label)
|
||||
If InStr(CStr(actualValue), CStr(expectedValue)) = 0 Then
|
||||
Call Fail(label & ": missing [" & CStr(expectedValue) & "]")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Fail(message)
|
||||
WScript.Echo "FAIL: " & message
|
||||
WScript.Quit 1
|
||||
End Sub
|
||||
@@ -0,0 +1,171 @@
|
||||
Option Explicit
|
||||
|
||||
Const VDM_COMP = 1
|
||||
Const VD_SELECTED = 2
|
||||
Const SHORT_NAME = 3
|
||||
|
||||
Dim Fso
|
||||
Dim Shell
|
||||
Dim ScriptRoot
|
||||
Dim TempRoot
|
||||
Dim ObjectMap
|
||||
Dim OriginalMap
|
||||
Dim RunRoot
|
||||
Dim RunId
|
||||
Dim SnapshotId
|
||||
Dim Component
|
||||
Dim ParentBlock
|
||||
Dim Application
|
||||
Dim ActiveView
|
||||
Dim RequestText
|
||||
|
||||
Class FakeParentBlock
|
||||
Public Name
|
||||
Public SheetNum
|
||||
End Class
|
||||
|
||||
Class FakeComponent
|
||||
Public Refdes
|
||||
Public UID
|
||||
Public Parent
|
||||
Public X
|
||||
Public Y
|
||||
Public PartNumber
|
||||
Public Value
|
||||
Public ComponentName
|
||||
|
||||
Public Function GetName(kind)
|
||||
GetName = ComponentName
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Class FakeDesignNames
|
||||
Public Function GetItem(index)
|
||||
GetItem = "Design-A"
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Class FakeProjectData
|
||||
Public Function GetiCDBDesigns()
|
||||
Set GetiCDBDesigns = New FakeDesignNames
|
||||
End Function
|
||||
|
||||
Public Function GetiCDBDesignRootBlock(name)
|
||||
GetiCDBDesignRootBlock = "TOP"
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Class FakeApplicationHost
|
||||
Public TheComponent
|
||||
Public ProjectPath
|
||||
|
||||
Public Function GetProjectData()
|
||||
Set GetProjectData = New FakeProjectData
|
||||
End Function
|
||||
|
||||
Public Function DesignComponents(a, b, c, d, e)
|
||||
Dim values(0)
|
||||
Set values(0) = TheComponent
|
||||
DesignComponents = values
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Class FakeBlock
|
||||
Public SheetNum
|
||||
End Class
|
||||
|
||||
Class FakeActiveView
|
||||
Public TheComponent
|
||||
Public Block
|
||||
|
||||
Public Function Query(a, b)
|
||||
Dim values(0)
|
||||
Set values(0) = TheComponent
|
||||
Query = values
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Set Fso = CreateObject("Scripting.FileSystemObject")
|
||||
Set Shell = CreateObject("WScript.Shell")
|
||||
ScriptRoot = Fso.GetParentFolderName(WScript.ScriptFullName)
|
||||
Call LoadGlobal(Fso.GetAbsolutePathName(Fso.BuildPath( _
|
||||
ScriptRoot, "..\..\integration\dxdesigner795\BridgeCommon.vbs")))
|
||||
Call LoadGlobal(Fso.GetAbsolutePathName(Fso.BuildPath( _
|
||||
ScriptRoot, "..\..\integration\dxdesigner795\core\Snapshot.vbs")))
|
||||
|
||||
TempRoot = Fso.BuildPath(Fso.GetSpecialFolder(2), _
|
||||
"dx-tools-export-" & Replace(CStr(Timer), ".", "-"))
|
||||
Fso.CreateFolder TempRoot
|
||||
Shell.Environment("PROCESS")("LOCALAPPDATA") = TempRoot
|
||||
|
||||
Set ParentBlock = New FakeParentBlock
|
||||
ParentBlock.Name = "ROOT"
|
||||
ParentBlock.SheetNum = 3
|
||||
Set Component = New FakeComponent
|
||||
Component.Refdes = "R?"
|
||||
Component.UID = "uid-1"
|
||||
Set Component.Parent = ParentBlock
|
||||
Component.X = 12.5
|
||||
Component.Y = 42.25
|
||||
Component.PartNumber = "PN-1"
|
||||
Component.Value = "10K"
|
||||
Component.ComponentName = "R1"
|
||||
|
||||
Set Application = New FakeApplicationHost
|
||||
Set Application.TheComponent = Component
|
||||
Application.ProjectPath = "C:\Projects\board.prj"
|
||||
Set ActiveView = New FakeActiveView
|
||||
Set ActiveView.TheComponent = Component
|
||||
Set ActiveView.Block = New FakeBlock
|
||||
ActiveView.Block.SheetNum = 3
|
||||
|
||||
Set ObjectMap = CreateObject("Scripting.Dictionary")
|
||||
Set OriginalMap = CreateObject("Scripting.Dictionary")
|
||||
If Not DxExportSnapshot(ObjectMap, OriginalMap, RunRoot, RunId, _
|
||||
SnapshotId) Then
|
||||
Call Fail("snapshot export returned false")
|
||||
End If
|
||||
|
||||
Call AssertEqual(ObjectMap.Count, 1, "object count")
|
||||
RequestText = DxToolsReadUtf8(Fso.BuildPath(RunRoot, "request.json"))
|
||||
Call AssertContains(RequestText, """bridge_id"": ""c000001""", "bridge id")
|
||||
Call AssertContains(RequestText, """stable_uid"": ""uid-1""", "stable uid")
|
||||
Call AssertContains(RequestText, """sheet_number"": 3", "sheet number")
|
||||
Call AssertContains(RequestText, """selected"": true", "selected")
|
||||
Call AssertContains(RequestText, """current_sheet"": true", "current sheet")
|
||||
Call AssertContains(RequestText, """x"": ""12.5""", "x coordinate")
|
||||
Call AssertContains(RequestText, """format_version"": 2", "format version")
|
||||
Call AssertContains(RequestText, """attributes"": []", "attributes field")
|
||||
Call AssertContains(RequestText, """nets"": []", "nets field")
|
||||
Call AssertContains(RequestText, """selected_nets"": []", "selected nets field")
|
||||
Call AssertContains(RequestText, """locked"": false", "locked field")
|
||||
|
||||
Fso.DeleteFolder TempRoot, True
|
||||
WScript.Echo "RefDes export assertions passed"
|
||||
|
||||
Sub LoadGlobal(path)
|
||||
Dim stream
|
||||
Dim text
|
||||
Set stream = Fso.OpenTextFile(path, 1, False, 0)
|
||||
text = stream.ReadAll
|
||||
stream.Close
|
||||
ExecuteGlobal text
|
||||
End Sub
|
||||
|
||||
Sub AssertEqual(actualValue, expectedValue, label)
|
||||
If CStr(actualValue) <> CStr(expectedValue) Then
|
||||
Call Fail(label & ": expected [" & CStr(expectedValue) & _
|
||||
"] got [" & CStr(actualValue) & "]")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub AssertContains(actualValue, expectedValue, label)
|
||||
If InStr(CStr(actualValue), CStr(expectedValue)) = 0 Then
|
||||
Call Fail(label & ": missing [" & CStr(expectedValue) & "]")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Fail(message)
|
||||
WScript.Echo "FAIL: " & message
|
||||
WScript.Quit 1
|
||||
End Sub
|
||||
Reference in new issue
Block a user