164 lines
4.7 KiB
Plaintext
164 lines
4.7 KiB
Plaintext
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
|