50 lines
4.6 KiB
PowerShell
50 lines
4.6 KiB
PowerShell
[CmdletBinding()]
|
|
param([Parameter(Mandatory)][string]$PackagePath)
|
|
$ErrorActionPreference='Stop'
|
|
# Existing .NET Framework compiler; no Office, registration, policy or installation changes.
|
|
if($env:OS -ne 'Windows_NT'){throw 'Run the compiled VSTO ribbon check on Windows.'}
|
|
. (Join-Path $PSScriptRoot 'DeveloperPackage.ps1')
|
|
$package=Test-DeveloperPackage $PackagePath
|
|
$work=Join-Path ([IO.Path]::GetTempPath()) ('pd-ribbon-check-'+[guid]::NewGuid().ToString('N'))
|
|
New-Item -ItemType Directory -Path $work | Out-Null
|
|
$source=Join-Path $work 'RibbonChecks.cs';$runner=Join-Path $work 'RibbonChecks.exe'
|
|
try {
|
|
@'
|
|
using System;
|
|
using System.Reflection;
|
|
using System.Reflection.Emit;
|
|
using System.Xml;
|
|
class RibbonChecks {
|
|
static int count;static object ribbon;static Type type;
|
|
static void Check(bool ok,string name){if(!ok)throw new Exception(name);Console.WriteLine("PASS "+name);count++;}
|
|
static object Call(string name){return type.GetMethod(name,BindingFlags.Public|BindingFlags.Instance).Invoke(ribbon,new object[]{null});}
|
|
static int Main(string[] args){try{
|
|
var assembly=Assembly.LoadFrom(System.IO.Path.Combine(args[0],"PlotDirector.WordAddIn.dll"));
|
|
Check(assembly.GetName().Version.ToString()==args[1],"Loaded ribbon assembly matches the qualified package version");
|
|
var adapter=assembly.GetType("PlotDirector.WordAddIn.WordAdapter",true);type=assembly.GetType("PlotDirector.WordAddIn.NativeRibbon",true);
|
|
var factoryType=typeof(Func<>).MakeGenericType(adapter);var method=new DynamicMethod("NoWordAdapter",adapter,Type.EmptyTypes);var il=method.GetILGenerator();il.Emit(OpCodes.Ldnull);il.Emit(OpCodes.Ret);
|
|
ribbon=Activator.CreateInstance(type,new object[]{method.CreateDelegate(factoryType)});
|
|
var xml=new XmlDocument();xml.LoadXml((string)Call("GetCustomUI"));var ns=new XmlNamespaceManager(xml.NameTable);ns.AddNamespace("r","http://schemas.microsoft.com/office/2009/07/customui");
|
|
var hold=(XmlElement)xml.SelectSingleNode("//r:toggleButton[@id='PlotDirectorHold']",ns);
|
|
Check(hold!=null&&hold.GetAttribute("size")=="large"&&((XmlElement)hold.ParentNode).GetAttribute("id")=="PlotDirectorSharedFocus","Large focus toggle remains in the Manuscript focus group");
|
|
Check(hold.GetAttribute("getLabel")=="GetFocusAction"&&hold.GetAttribute("getImage")=="GetFocusIcon"&&hold.GetAttribute("getPressed")=="GetFocusHeld"&&hold.GetAttribute("getEnabled")=="CanHoldFocus"&&hold.GetAttribute("onAction")=="ToggleFocusHold","Dynamic label, image, enabled, pressed and existing action bindings");
|
|
Check(!hold.HasAttribute("imageMso"),"Static Lock icon cannot override dynamic Pause/Play");
|
|
Check(xml.SelectSingleNode("//*[@id='PlotDirectorFocusState']")==null&&xml.SelectSingleNode("//*[@id='PlotDirectorIntent']")==null,"Redundant State and retired Intent controls absent");
|
|
foreach(var id in new[]{"PlotDirectorBook","PlotDirectorChapter","PlotDirectorScene","PlotDirectorContext","PlotDirectorWeb","PlotDirectorOpen","PlotDirectorAudioReview","PlotDirectorAudioReviewOpen","PlotDirectorAudioBack","PlotDirectorAudioPlay","PlotDirectorAudioPause","PlotDirectorAudioForward","PlotDirectorSynchronise","PlotDirectorTools"})Check(xml.SelectSingleNode("//*[@id='"+id+"']")!=null,"Preserved ribbon control "+id);
|
|
Check((string)Call("GetFocusAction")=="Hold"&&!(bool)Call("CanHoldFocus")&&!(bool)Call("GetFocusHeld"),"Unavailable callbacks: Hold, disabled and unpressed");
|
|
Check(((string)Call("GetFocusTip")).Contains("Connect Companion"),"Unavailable tooltip explains recovery");
|
|
var pause=Call("GetFocusIcon");Check(pause!=null&&Object.ReferenceEquals(pause,Call("GetFocusIcon")),"Unavailable Pause icon renders and is cached");
|
|
var image=type.GetMethod("GetPlaybackIcon",BindingFlags.NonPublic|BindingFlags.Instance,null,new[]{typeof(string)},null);
|
|
var play=image.Invoke(ribbon,new object[]{"PlotDirectorAudioPlay"});var cachedPause=image.Invoke(ribbon,new object[]{"PlotDirectorAudioPause"});
|
|
Check(play!=null&&!Object.ReferenceEquals(play,pause)&&Object.ReferenceEquals(cachedPause,pause),"Play and Pause reuse distinct Audio Review image cache");
|
|
Console.WriteLine("PASS Windows compiled ribbon qualification: "+count+" assertions; Word and installer not executed.");return 0;
|
|
}catch(Exception e){Console.Error.WriteLine(e);return 1;}}
|
|
}
|
|
'@ | Set-Content -LiteralPath $source -Encoding UTF8
|
|
Invoke-Checked (Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319\csc.exe') @('/nologo','/target:exe',('/out:'+$runner),$source)
|
|
Invoke-Checked $runner @((Resolve-Path -LiteralPath $PackagePath).Path,$package.version)
|
|
} finally {
|
|
Remove-Item -LiteralPath $source,$runner -Force -ErrorAction SilentlyContinue
|
|
Remove-Item -LiteralPath $work -ErrorAction SilentlyContinue
|
|
}
|