Module/ArxmlAutomation-Basic-Validation.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
function Confirm-SameArObjContainer{ param( [AR430._AR430BaseType[]] $Items, [int] $Depth=-1 ) process{ $pass=$True $sortedItems=$Items|Sort-Object {$_.GetAutosarPath().Length}|Foreach-Object {,@($_.GetAutosarPath() -split "/")} $objectMeasures=($sortedItems|ForEach-Object {$_.Count}|Measure-Object -Maximum -Minimum) if($Depth -gt 0 -and $objectMeasures.Maximum-$objectMeasures.Minimum -gt $Depth){ $pass=$False } if($pass){ $DepthMeasured=0 for($i=0;$i-lt $objectMeasures.Minimum;$i++){ # loop if(($sortedItems|ForEach-Object{ $_[$i] }|Select-Object -Unique).Count -ne 1){ if($DepthMeasured -eq $Depth){ $pass=$False break; } else{ $DepthMeasured++ } } } } if(-not $pass){ Write-Warning "$($items|Foreach-Object{$_.GetAutosarPath()}) container different" Write-Error "Same arobj container validation failed for $items." } } } function Assert-ArObjType{ param( [Parameter(ValueFromPipeline)] $InputObject, [Parameter(ParameterSetName="MatchString" , Position=0)] [string[]] $AssertTypeMatch, [Parameter(ParameterSetName="MatchType", Position=0)] [type[]] $AssertType, [switch] $AllowIgnore, [switch] $ReturnBool ) process{ if($PSCmdlet.ParameterSetName -eq ("MatchString")){ if($InputObject.GetType().Name|Select-String -CaseSensitive -Pattern ($AssertTypeMatch|ForEach-Object{ "(?m)^$_$" })){ if($ReturnBool){ return $true } else{ return $InputObject } } elseif(-not $AllowIgnore){ throw "$InputObject is not part of AssertType $AssertType" } elseif($ReturnBool){ return $false } } else{ if($AssertType|Where-Object{$InputObject -is $_}){ if($ReturnBool){ return $true } else{ return $InputObject } } elseif($ReturnBool){ return $false } } } } |