| 1 | param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost) |
| 2 | Set-StrictMode -Version Latest |
| 3 | $ErrorActionPreference = 'Stop' |
| 4 | & "$PSScriptRoot\cold-current.ps1" -Root $Root -CloneHost $CloneHost |
| 5 | $inputs = Join-Path $Root 'inputs' |
| 6 | New-Item -ItemType Directory -Path $inputs | Out-Null |
| 7 | $app = New-Object -ComObject OneNote.Application |
| 8 | $notebookId = '' |
| 9 | $namespace = 'http://schemas.microsoft.com/office/onenote/2010/onenote' |
| 10 | try { |
| 11 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebookId, 0) |
| 12 | $sectionId = '' |
| 13 | $app.OpenHierarchy('synthetic.one', $notebookId, [ref]$sectionId, 0) |
| 14 | $cases = @( |
| 15 | @{ name = 'Black highlight control'; html = '<span style="background:black">Black highlight, automatic text</span>' }, |
| 16 | @{ name = 'White on black'; html = '<span style="background:black;color:white">White text on black highlight</span>' }, |
| 17 | @{ name = 'Black on black'; html = '<span style="background:black;color:black">Black text on black highlight</span>' }, |
| 18 | @{ name = 'Partial black highlight'; html = '<b>Before <span style="background:black">middle</span> after</b>' }, |
| 19 | @{ name = 'Yellow control'; html = '<span style="background:yellow">Yellow highlight, automatic text</span>' }, |
| 20 | @{ name = 'Character styles'; html = 'Plain <b>bold</b> <i>italic</i> <u>underline</u> <s>strike</s> <sup>super</sup> <sub>sub</sub> <span style="font-family:Consolas;font-size:18pt;color:#804020;background:#00ffff">font and color</span>' }, |
| 21 | @{ name = 'Unicode runs'; html = 'BMP <b>' + [char]::ConvertFromUtf32(0x1F600) + 'e' + [char]0x0301 + '</b> ' + [char]0x6771 + [char]0x4EAC + ' <i>' + [char]0x0645 + [char]0x0631 + [char]0x062D + [char]0x0628 + [char]0x0627 + '</i>' }, |
| 22 | @{ name = 'Link runs'; html = 'Before <a href="https://example.invalid/fixture?x=1&amp;y=2"><b>Link label</b></a> after' } |
| 23 | ) |
| 24 | $pageId = '' |
| 25 | $app.CreateNewPage($sectionId, [ref]$pageId, 0) |
| 26 | $body = '<one:Title><one:OE><one:T><![CDATA[Native feature probes]]></one:T></one:OE></one:Title><one:Outline><one:Position x="72" y="108"/><one:Size width="480" height="400"/><one:OEChildren>' |
| 27 | foreach ($case in $cases) { $body += '<one:OE><one:T><![CDATA[' + $case.html + ']]></one:T></one:OE>' } |
| 28 | $body += '</one:OEChildren></one:Outline>' |
| 29 | $body = '<one:TagDef index="0" type="0" symbol="3" fontColor="automatic" highlightColor="none" name="Fixture checkbox"/><one:TagDef index="1" type="90" symbol="13" fontColor="#804020" highlightColor="#00ffff" name="Fixture custom tag"/><one:QuickStyleDef index="0" name="h1" font="Calibri" fontSize="20" bold="true" fontColor="#123456" highlightColor="automatic" spaceBefore="8" spaceAfter="4"/>' + $body |
| 30 | $body += '<one:Outline><one:Position x="72" y="540"/><one:Size width="480" height="600"/><one:OEChildren>' |
| 31 | $body += '<one:OE quickStyleIndex="0" alignment="right"><one:T><![CDATA[Named paragraph style]]></one:T></one:OE>' |
| 32 | $body += '<one:OE><one:Tag index="0" completed="false" disabled="false" creationDate="2020-01-02T03:04:05.000Z"/><one:Tag index="1" completed="true" disabled="false" creationDate="2020-01-02T03:04:05.000Z" completionDate="2020-01-02T04:05:06.000Z"/><one:T><![CDATA[Two tags on this paragraph]]></one:T></one:OE>' |
| 33 | $body += '<one:OE><one:List><one:Bullet bullet="3" fontSize="11"/></one:List><one:T><![CDATA[Outer bullet]]></one:T><one:OEChildren><one:OE><one:List><one:Bullet bullet="13" fontSize="11"/></one:List><one:T><![CDATA[Nested bullet]]></one:T></one:OE></one:OEChildren></one:OE>' |
| 34 | $body += '<one:OE><one:List><one:Number numberSequence="1" numberFormat="##." restartNumberingAt="3" font="Calibri" fontSize="11"/></one:List><one:T><![CDATA[Numbered item three]]></one:T></one:OE><one:OE><one:List><one:Number numberSequence="1" numberFormat="##." font="Calibri" fontSize="11"/></one:List><one:T><![CDATA[Numbered item four]]></one:T></one:OE>' |
| 35 | $body += '<one:OE><one:Table bordersVisible="true"><one:Columns><one:Column index="0" width="120" isLocked="true"/><one:Column index="1" width="180"/></one:Columns>' |
| 36 | foreach ($row in 0..2) { |
| 37 | $body += '<one:Row>' |
| 38 | foreach ($column in 0..1) { |
| 39 | $body += '<one:Cell shadingColor="#ffff00"><one:OEChildren><one:OE><one:T><![CDATA[Cell ' + $row + ',' + $column + ']]></one:T></one:OE></one:OEChildren></one:Cell>' |
| 40 | } |
| 41 | $body += '</one:Row>' |
| 42 | } |
| 43 | $body += '</one:Table></one:OE></one:OEChildren></one:Outline>' |
| 44 | |
| 45 | $xml = '<one:Page xmlns:one="' + $namespace + '" ID="' + $pageId + '">' + $body + '</one:Page>' |
| 46 | [IO.File]::WriteAllText((Join-Path $inputs 'format-probes.xml'), $xml, [Text.Encoding]::UTF8) |
| 47 | [xml]$doc = $xml |
| 48 | $results = @() |
| 49 | $n = 0 |
| 50 | $table = $doc.Page.Outline[1].OEChildren.OE[-1].OuterXml |
| 51 | $variants = @($table, $table.Replace(' shadingColor="#ffff00"', ''), $table.Replace(' isLocked="true"', '').Replace(' shadingColor="#ffff00"', ''), $table.Replace(' isLocked="true"', '')) |
| 52 | $parts = @($variants | ForEach-Object { '<one:Outline><one:OEChildren>' + $_ + '</one:OEChildren></one:Outline>' }) |
| 53 | foreach ($part in $parts) { |
| 54 | $testId = '' |
| 55 | $app.CreateNewPage($sectionId, [ref]$testId, 0) |
| 56 | $testXml = '<one:Page xmlns:one="' + $namespace + '" ID="' + $testId + '">' + ($doc.Page.TagDef | ForEach-Object { $_.OuterXml }) + $doc.Page.QuickStyleDef.OuterXml + '<one:Title><one:OE><one:T>Probe ' + $n + '</one:T></one:OE></one:Title>' + $part + '</one:Page>' |
| 57 | [IO.File]::WriteAllText((Join-Path $inputs ('probe-' + $n + '.xml')), $testXml, [Text.Encoding]::UTF8) |
| 58 | try { |
| 59 | $app.UpdatePageContent($testXml, [DateTime]::MinValue, 1, $true) |
| 60 | $results += @{ probe = $n; result = 'accepted' } |
| 61 | } catch { $results += @{ probe = $n; result = $_.Exception.Message } } |
| 62 | $n++ |
| 63 | } |
| 64 | $results | ConvertTo-Json -Depth 8 | Set-Content (Join-Path $Root 'expected.json') -Encoding UTF8 |
| 65 | $app.SyncHierarchy($notebookId) |
| 66 | $app.CloseNotebook($notebookId, $false) |
| 67 | $notebookId = '' |
| 68 | } finally { |
| 69 | if ($notebookId) { $app.CloseNotebook($notebookId, $false) } |
| 70 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 71 | $app = $null |
| 72 | [GC]::Collect() |
| 73 | [GC]::WaitForPendingFinalizers() |
| 74 | } |