[CmdletBinding()] param([Parameter(Mandatory)][string]$PackagePath) $ErrorActionPreference='Stop' # Run under Windows PowerShell/.NET Framework. Loads signed build bytes in this # short-lived process; never starts Office, registers VSTO or changes installation. if($env:OS -ne 'Windows_NT' -or $PSVersionTable.PSEdition -ne 'Desktop'){throw 'Use Windows PowerShell for the .NET Framework VSTO ribbon check.'} . (Join-Path $PSScriptRoot 'DeveloperPackage.ps1') $package=Test-DeveloperPackage $PackagePath $script:passed=0 function Check([bool]$condition,[string]$message){if(!$condition){throw $message};$script:passed++;Write-Output "PASS $message"} $assembly=[Reflection.Assembly]::LoadFrom((Join-Path $PackagePath 'PlotDirector.WordAddIn.dll')) Check ($assembly.GetName().Version.ToString() -eq $package.version) 'Loaded ribbon assembly matches the qualified package version' $adapterType=$assembly.GetType('PlotDirector.WordAddIn.WordAdapter',$true) $ribbonType=$assembly.GetType('PlotDirector.WordAddIn.NativeRibbon',$true) $factoryType=[Func``1].MakeGenericType($adapterType) $factoryMethod=[Reflection.Emit.DynamicMethod]::new('NoWordAdapter',$adapterType,[Type[]]@()) $il=$factoryMethod.GetILGenerator();$il.Emit([Reflection.Emit.OpCodes]::Ldnull);$il.Emit([Reflection.Emit.OpCodes]::Ret) $factory=$factoryMethod.CreateDelegate($factoryType) $ribbon=[Activator]::CreateInstance($ribbonType,[object[]]@($factory)) function Callback([string]$name){$ribbonType.GetMethod($name,[Reflection.BindingFlags]'Public,Instance').Invoke($ribbon,[object[]]@($null))} $xml=[xml](Callback 'GetCustomUI') $ns=New-Object Xml.XmlNamespaceManager($xml.NameTable);$ns.AddNamespace('r','http://schemas.microsoft.com/office/2009/07/customui') $hold=$xml.SelectSingleNode('//r:toggleButton[@id="PlotDirectorHold"]',$ns) Check ($hold -and $hold.size -eq 'large' -and $hold.ParentNode.id -eq 'PlotDirectorSharedFocus') 'Large focus toggle remains in the Manuscript focus group' Check ($hold.getLabel -eq 'GetFocusAction' -and $hold.getImage -eq 'GetFocusIcon' -and $hold.getPressed -eq 'GetFocusHeld' -and $hold.getEnabled -eq 'CanHoldFocus' -and $hold.onAction -eq 'ToggleFocusHold') 'Dynamic label, image, enabled, pressed and existing action bindings are present' Check (!$hold.HasAttribute('imageMso')) 'Static Lock icon cannot override the dynamic Pause/Play image' Check (!$xml.SelectSingleNode('//*[@id="PlotDirectorFocusState"]') -and !$xml.SelectSingleNode('//*[@id="PlotDirectorIntent"]')) 'Redundant State and retired Intent controls are absent' foreach($control in @('PlotDirectorBook','PlotDirectorChapter','PlotDirectorScene','PlotDirectorContext','PlotDirectorWeb','PlotDirectorOpen','PlotDirectorAudioReview','PlotDirectorSynchronise','PlotDirectorTools')){ Check ($null -ne $xml.SelectSingleNode("//*[@id='$control']")) "Preserved ribbon control $control" } Check ((Callback 'GetFocusAction') -eq 'Hold' -and !(Callback 'CanHoldFocus') -and !(Callback 'GetFocusHeld')) 'Unavailable callback state is Hold, disabled and unpressed' Check ((Callback 'GetFocusTip') -match 'Connect Companion') 'Unavailable tooltip explains how to recover' $pause=Callback 'GetFocusIcon';$again=Callback 'GetFocusIcon' Check ($null -ne $pause -and [object]::ReferenceEquals($pause,$again)) 'Unavailable Pause icon is rendered and cached without ribbon churn' $imageMethod=$ribbonType.GetMethod('GetPlaybackIcon',[Reflection.BindingFlags]'NonPublic,Instance',$null,[Type[]]@([string]),$null) $play=$imageMethod.Invoke($ribbon,[object[]]@('PlotDirectorAudioPlay')) $cachedPause=$imageMethod.Invoke($ribbon,[object[]]@('PlotDirectorAudioPause')) Check ($null -ne $play -and ![object]::ReferenceEquals($play,$pause) -and [object]::ReferenceEquals($cachedPause,$pause)) 'Play and Pause reuse the established distinct Audio Review image cache' Write-Output "PASS Windows compiled ribbon qualification: $script:passed assertions; Word and the installer were not executed."